at 25.11-pre 2.9 kB view raw
1# Provide an initial copy of the NixOS channel so that the user 2# doesn't need to run "nix-channel --update" first. 3 4{ 5 config, 6 lib, 7 pkgs, 8 ... 9}: 10 11let 12 # This is copied into the installer image, so it's important that it is filtered 13 # to avoid including a large .git directory. 14 # We also want the source name to be normalised to "source" to avoid depending on the 15 # location of nixpkgs. 16 # In the future we might want to expose the ISO image from the flake and use 17 # `self.outPath` directly instead. 18 nixpkgs = lib.cleanSource pkgs.path; 19 20 # We need a copy of the Nix expressions for Nixpkgs and NixOS on the 21 # CD. These are installed into the "nixos" channel of the root 22 # user, as expected by nixos-rebuild/nixos-install. FIXME: merge 23 # with make-channel.nix. 24 channelSources = 25 pkgs.runCommand "nixos-${config.system.nixos.version}" { preferLocalBuild = true; } 26 '' 27 mkdir -p $out 28 cp -prd ${nixpkgs.outPath} $out/nixos 29 chmod -R u+w $out/nixos 30 if [ ! -e $out/nixos/nixpkgs ]; then 31 ln -s . $out/nixos/nixpkgs 32 fi 33 ${lib.optionalString (config.system.nixos.revision != null) '' 34 echo -n ${config.system.nixos.revision} > $out/nixos/.git-revision 35 ''} 36 echo -n ${config.system.nixos.versionSuffix} > $out/nixos/.version-suffix 37 echo ${config.system.nixos.versionSuffix} | sed -e s/pre// > $out/nixos/svn-revision 38 ''; 39in 40 41{ 42 options.system.installer.channel.enable = 43 (lib.mkEnableOption "bundling NixOS/Nixpkgs channel in the installer") 44 // { 45 default = true; 46 }; 47 config = lib.mkIf config.system.installer.channel.enable { 48 # Pin the nixpkgs flake in the installer to our cleaned up nixpkgs source. 49 # FIXME: this might be surprising and is really only needed for offline installations, 50 # see discussion in https://github.com/NixOS/nixpkgs/pull/204178#issuecomment-1336289021 51 nix.registry.nixpkgs.to = { 52 type = "path"; 53 path = "${channelSources}/nixos"; 54 }; 55 56 # Provide the NixOS/Nixpkgs sources in /etc/nixos. This is required 57 # for nixos-install. 58 boot.postBootCommands = lib.mkAfter '' 59 if ! [ -e /var/lib/nixos/did-channel-init ]; then 60 echo "unpacking the NixOS/Nixpkgs sources..." 61 mkdir -p /nix/var/nix/profiles/per-user/root 62 ${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/per-user/root/channels \ 63 -i ${channelSources} --quiet --option build-use-substitutes false \ 64 ${lib.optionalString config.boot.initrd.systemd.enable "--option sandbox false"} # There's an issue with pivot_root 65 mkdir -m 0700 -p /root/.nix-defexpr 66 ln -s /nix/var/nix/profiles/per-user/root/channels /root/.nix-defexpr/channels 67 mkdir -m 0755 -p /var/lib/nixos 68 touch /var/lib/nixos/did-channel-init 69 fi 70 ''; 71 }; 72}