├── README.md ├── default.nix ├── publish.sh └── snap.nix /README.md: -------------------------------------------------------------------------------- 1 | Have a Snapcraft-capable machine 2 | 3 | Hint: NixOS doesn't have Snapcraft at the time of publishing. 4 | 5 | Be part of the NixOS Foundation organization on Snapcraft: 6 | 7 | https://snapcraft.io/nix-base 8 | 9 | Then: 10 | 11 | 1. `snapcraft login` 12 | 2. `./publish.sh` 13 | 14 | However, good news, you will probably never need to do this since the 15 | base image has almost nothing in it but the minimum necessary 16 | directories plus `/nix`. 17 | -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | let 2 | nixpkgs = builtins.fetchTarball { 3 | url = "https://github.com/NixOS/nixpkgs/archive/e6d320ec0ceefa56f9e711e389a6f39cdc985634.tar.gz"; 4 | sha256 = "1zzp6h0mnz7qkhvzrgrlmlp6ljwnkn5k942gldkmajhcbs6jddhb"; 5 | }; 6 | 7 | pkgs = import nixpkgs { system = "x86_64-linux"; }; 8 | in pkgs.callPackage ./snap.nix { } 9 | -------------------------------------------------------------------------------- /publish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -eux 4 | 5 | resultpath=$(nix-build .) 6 | snapcraft push --release=stable \ 7 | "$resultpath/"nix-base_*_all.snap 8 | -------------------------------------------------------------------------------- /snap.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, runCommand, squashfsTools, closureInfo, jq 3 | }: 4 | let 5 | meta = { 6 | name = "nix-base"; 7 | type = "base"; 8 | confinement = "strict"; 9 | architectures = [ "all" ] ; 10 | license = "CC0-1.0"; 11 | }; 12 | 13 | # from: https://github.com/snapcore/snapcraft/blob/b88e378148134383ffecf3658e3a940b67c9bcc9/snapcraft/internal/lifecycle/_packer.py#L96-L98 14 | # These options need to match the review tools: 15 | # http://bazaar.launchpad.net/~click-reviewers/click-reviewers-tools/trunk/view/head:/clickreviews/common.py#L38 16 | mksquashfs_args = [ 17 | "-noappend" "-comp" "xz" "-no-xattrs" "-no-fragments" 18 | 19 | # https://github.com/snapcore/snapcraft/blob/b88e378148134383ffecf3658e3a940b67c9bcc9/snapcraft/internal/lifecycle/_packer.py#L100 20 | "-all-root" 21 | ]; 22 | in runCommand "nix-base" { 23 | nativeBuildInputs = [ squashfsTools jq ]; 24 | 25 | snapMeta = builtins.toJSON meta; 26 | passAsFile = [ "snapMeta" ]; 27 | } 28 | '' 29 | root=$PWD/root 30 | mkdir $root 31 | 32 | version=$(echo $out | cut -d/ -f4 | cut -d- -f1) 33 | 34 | ( 35 | mkdir $root/meta 36 | cat $snapMetaPath | jq ". + { version: \"$version\" }" \ 37 | > $root/meta/snap.yaml 38 | ) 39 | 40 | ( 41 | cd $root 42 | mkdir --mode 755 -p meta sys tmp usr/lib/snapd usr/src \ 43 | bin nix snap etc root run dev home proc var/lib/snapd \ 44 | var/tmp var/snap var/log media \ 45 | usr/share/fonts usr/local/share/fonts \ 46 | var/cache/fontconfig 47 | ) 48 | 49 | # Generate the squashfs image. 50 | mksquashfs $root ./nix-base_''${version}_all.snap \ 51 | ${lib.concatStringsSep " " mksquashfs_args} 52 | 53 | mkdir $out 54 | mv ./nix-base_*_all.snap $out/ 55 | '' 56 | --------------------------------------------------------------------------------