diff --git a/lib/channel-expr.nix b/lib/channel-expr.nix new file mode 100644 index 000000000000..453bdd506b88 --- /dev/null +++ b/lib/channel-expr.nix @@ -0,0 +1,6 @@ +{ system ? builtins.currentSystem }: + +{ pkgs = + (import nixpkgs/default.nix { inherit system; }) + // { recurseForDerivations = true; }; +} diff --git a/modules/installer/cd-dvd/installation-cd-base.nix b/modules/installer/cd-dvd/installation-cd-base.nix index 9111ac373850..5f351a65ec6d 100644 --- a/modules/installer/cd-dvd/installation-cd-base.nix +++ b/modules/installer/cd-dvd/installation-cd-base.nix @@ -8,22 +8,20 @@ with pkgs.lib; let # We need a copy of the Nix expressions for Nixpkgs and NixOS on the - # CD. We put them in a tarball because accessing that many small - # files from a slow device like a CD-ROM takes too long. !!! Once - # we use squashfs, maybe we won't need this anymore. - makeTarball = tarName: input: pkgs.runCommand "tarball" {inherit tarName;} + # CD. These are installed into the "nixos" channel of the root + # user, as expected by nixos-rebuild/nixos-install. + channelSources = pkgs.runCommand "nixos-${config.system.nixosVersion}" + { expr = builtins.readFile ../../../lib/channel-expr.nix; } '' - ensureDir $out - (cd ${input} && tar cvfj $out/${tarName} . \ - --exclude '*~' --exclude 'result') + mkdir -p $out/nixos + cp -prd ${cleanSource ../../..} $out/nixos/nixos + cp -prd ${cleanSource } $out/nixos/nixpkgs + chmod -R u+w $out/nixos/nixos + echo -n ${config.system.nixosVersion} > $out/nixos/nixos/.version + echo -n "" > $out/nixos/nixos/.version-suffix + echo "$expr" > $out/nixos/default.nix ''; - # Put the current directory in a tarball. - nixosTarball = makeTarball "nixos.tar.bz2" (cleanSource ../../..); - - # Put Nixpkgs in a tarball. - nixpkgsTarball = makeTarball "nixpkgs.tar.bz2" (cleanSource ); - includeSources = true; in @@ -48,19 +46,14 @@ in boot.postBootCommands = '' - export PATH=${pkgs.gnutar}/bin:${pkgs.bzip2}/bin:$PATH - # Provide the NixOS/Nixpkgs sources in /etc/nixos. This is required # for nixos-install. ${optionalString includeSources '' echo "unpacking the NixOS/Nixpkgs sources..." - mkdir -p /etc/nixos/nixos - tar xjf ${nixosTarball}/nixos.tar.bz2 -C /etc/nixos/nixos - mkdir -p /etc/nixos/nixpkgs - tar xjf ${nixpkgsTarball}/nixpkgs.tar.bz2 -C /etc/nixos/nixpkgs - chown -R root.root /etc/nixos - echo -n ${config.system.nixosVersion} > /etc/nixos/nixos/.version - echo -n "" > /etc/nixos/nixos/.version-suffix + mkdir -p /nix/var/nix/profiles/per-user/root + ${config.environment.nix}/bin/nix-env -p /nix/var/nix/profiles/per-user/root/channels -i ${channelSources} --quiet + mkdir -m 0700 -p /root/.nix-defexpr + ln -s /nix/var/nix/profiles/per-user/root/channels /root/.nix-defexpr/channels ''} # Make the installer more likely to succeed in low memory diff --git a/modules/installer/tools/nixos-install.sh b/modules/installer/tools/nixos-install.sh index ebe3413de2f2..8cdef4f78a3d 100644 --- a/modules/installer/tools/nixos-install.sh +++ b/modules/installer/tools/nixos-install.sh @@ -103,7 +103,7 @@ export LC_TIME= # Create a temporary Nix config file that causes the nixbld users to # be used. -echo "build-users-group = nixbld" > /mnt/tmp/nix.conf +echo "build-users-group = nixbld" > $mountPoint/tmp/nix.conf export NIX_CONF_DIR=/tmp @@ -141,45 +141,32 @@ for i in /nix/var/nix/manifests/*.nixmanifest; do done +# Get the absolute path to the NixOS/Nixpkgs sources. +srcs=$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path) + + # Build the specified Nix expression in the target store and install # it into the system configuration profile. echo "building the system configuration..." -NIX_PATH=nixpkgs=/mnt/etc/nixos/nixpkgs:nixos=/mnt/etc/nixos/nixos:nixos-config="/mnt$NIXOS_CONFIG" NIXOS_CONFIG= \ +NIX_PATH="/mnt$srcs/nixos:nixos-config=/mnt$NIXOS_CONFIG" NIXOS_CONFIG= \ chroot $mountPoint @nix@/bin/nix-env \ -p /nix/var/nix/profiles/system -f '' --set -A system --show-trace -# Get rid of the manifests. -rm -f $mountPoint/nix/var/nix/manifests/* - - # We're done building/downloading, so we don't need the /etc bind # mount anymore. In fact, below we want to modify the target's /etc. umount $mountPoint/etc/nixos umount $mountPoint/etc -# Make a backup of the old NixOS/Nixpkgs sources. -echo "copying NixOS/Nixpkgs sources to /etc/nixos...." - -backupTimestamp=$(date "+%Y%m%d%H%M%S") - -targetNixos=$mountPoint/etc/nixos/nixos -if test -e $targetNixos; then - mv $targetNixos $targetNixos.backup-$backupTimestamp -fi - -targetNixpkgs=$mountPoint/etc/nixos/nixpkgs -if test -e $targetNixpkgs; then - mv $targetNixpkgs $targetNixpkgs.backup-$backupTimestamp -fi - - -# Copy the NixOS/Nixpkgs sources to the target. -cp -prd /etc/nixos/nixos $targetNixos -if [ -e /etc/nixos/nixpkgs ]; then - cp -prd /etc/nixos/nixpkgs $targetNixpkgs -fi +# Copy the NixOS/Nixpkgs sources to the target as the initial contents +# of the NixOS channel. +echo "copying NixOS/Nixpkgs sources..." +mkdir -p $mountPoint/nix/var/nix/profiles/per-user/root +chroot $mountPoint @nix@/bin/nix-env \ + -p /nix/var/nix/profiles/per-user/root/channels -i "$srcs" --quiet +mkdir -m 0700 -p $mountPoint/root/.nix-defexpr +ln -s /nix/var/nix/profiles/per-user/root/channels $mountPoint/root/.nix-defexpr/channels # Grub needs an mtab. diff --git a/modules/profiles/installation-device.nix b/modules/profiles/installation-device.nix index 60bd20d39703..83416f49d88f 100644 --- a/modules/profiles/installation-device.nix +++ b/modules/profiles/installation-device.nix @@ -29,7 +29,7 @@ let relocatedModuleFiles = let relocateNixOS = path: - "/etc/nixos/nixos" + removePrefix nixosPath (toString path); + ""; relocateOthers = null; in { nixos = map relocateNixOS partitionedModuleFiles.nixos; @@ -44,16 +44,12 @@ let # evaluated. So we'll just hope for the best. configClone = pkgs.writeText "configuration.nix" '' - {config, pkgs, ...}: + { config, pkgs, ... }: { require = [ ${toString config.installer.cloneConfigIncludes} ]; - - # Add your own options below and run "nixos-rebuild switch". - # E.g., - # services.openssh.enable = true; } ''; in @@ -84,18 +80,6 @@ in ''; }; - # Ignored. Kept for Backward compatibiliy. - # you can retrieve the profiles which have been used by looking at the - # list of modules use to configure the installation device. - installer.configModule = mkOption { - example = "./nixos/modules/installer/cd-dvd/installation-cd.nix"; - description = '' - Filename of the configuration module that builds the CD - configuration. Must be specified to support reconfiguration - in live CDs. - ''; - }; - }; config = { @@ -148,5 +132,13 @@ in # Enable wpa_supplicant, but don't start it by default. networking.wireless.enable = true; jobs.wpa_supplicant.startOn = pkgs.lib.mkOverride 50 ""; + + # Tell the Nix evaluator to garbage collect more aggressively. + # This is desirable in memory-constrained environments that don't + # (yet) have swap set up. + environment.shellInit = + '' + export GC_INITIAL_HEAP_SIZE=100000 + ''; }; } diff --git a/modules/services/misc/nix-daemon.nix b/modules/services/misc/nix-daemon.nix index d2584c2dc3e4..be699d693fd8 100644 --- a/modules/services/misc/nix-daemon.nix +++ b/modules/services/misc/nix-daemon.nix @@ -28,11 +28,10 @@ in environment.nix = mkOption { default = pkgs.nixUnstable; - example = pkgs.nixCustomFun /root/nix.tar.gz; merge = mergeOneOption; - description = " + description = '' This option specifies the Nix package instance to use throughout the system. - "; + ''; }; nix = { diff --git a/release.nix b/release.nix index 2ee090f86ae6..11276fa695a2 100644 --- a/release.nix +++ b/release.nix @@ -114,11 +114,7 @@ let buildInputs = [ nixUnstable ]; - expr = - '' - { system ? builtins.currentSystem }: - { pkgs = (import nixpkgs/default.nix { inherit system; }) // { recurseForDerivations = true; }; } - ''; + expr = builtins.readFile lib/channel-expr.nix; distPhase = '' echo -n $VERSION_SUFFIX > .version-suffix @@ -128,7 +124,6 @@ let cp -prd . ../$releaseName/nixos cp -prd ${nixpkgs} ../$releaseName/nixpkgs echo "$expr" > ../$releaseName/default.nix - echo nixos > ../$releaseName/channel-name NIX_STATE_DIR=$TMPDIR nix-env -f ../$releaseName/default.nix -qaP --meta --xml \* > /dev/null cd .. chmod -R u+w $releaseName diff --git a/tests/installer.nix b/tests/installer.nix index 73cf6312f590..b64a24c1e3f6 100644 --- a/tests/installer.nix +++ b/tests/installer.nix @@ -131,7 +131,7 @@ let # Test nix-env. $machine->mustFail("hello"); - $machine->mustSucceed("nix-env -f /etc/nixos/nixpkgs -i hello"); + $machine->mustSucceed("nix-env -i hello"); $machine->mustSucceed("hello") =~ /Hello, world/ or die "bad `hello' output"; ''} @@ -175,7 +175,7 @@ let # !!! Idem. $machine->waitUntilSucceeds("cat /proc/swaps | grep -q /dev"); - $machine->mustSucceed("nix-env -f /etc/nixos/nixpkgs -i coreutils >&2"); + $machine->mustSucceed("nix-env -i coreutils >&2"); $machine->mustSucceed("type -tP ls | tee /dev/stderr") =~ /.nix-profile/ or die "nix-env failed";