From 8b1f1d93fa8e3524e0e01378dbe813e6eb06712e Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Wed, 12 Jul 2017 22:03:53 +0100 Subject: [PATCH 1/2] nixos-install: only search for nixpkgs when needed --- nixos/modules/installer/tools/nixos-install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nixos/modules/installer/tools/nixos-install.sh b/nixos/modules/installer/tools/nixos-install.sh index 087fbcd4512f..7fae915871e4 100644 --- a/nixos/modules/installer/tools/nixos-install.sh +++ b/nixos/modules/installer/tools/nixos-install.sh @@ -106,8 +106,11 @@ extraBuildFlags+=(--option "build-users-group" "$buildUsersGroup") binary_caches="$(@perl@/bin/perl -I @nix@/lib/perl5/site_perl/*/* -e 'use Nix::Config; Nix::Config::readConfig; print $Nix::Config::config{"binary-caches"};')" extraBuildFlags+=(--option "binary-caches" "$binary_caches") -nixpkgs="$(readlink -f "$(nix-instantiate --find-file nixpkgs)")" -export NIX_PATH="nixpkgs=$nixpkgs:nixos-config=$mountPoint/$NIXOS_CONFIG" +# We only need nixpkgs in the path if we don't already have a system closure to install +if [[ -z "$closure" ]]; then + nixpkgs="$(readlink -f "$(nix-instantiate --find-file nixpkgs)")" + export NIX_PATH="nixpkgs=$nixpkgs:nixos-config=$mountPoint/$NIXOS_CONFIG" +fi unset NIXOS_CONFIG # TODO: do I need to set NIX_SUBSTITUTERS here or is the --option binary-caches above enough? From 77ce02201e1bc7facabb774d7e9996ab803145d2 Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Wed, 12 Jul 2017 22:04:49 +0100 Subject: [PATCH 2/2] nixos-install: use FIFO for system closure This avoids running out of space in space-constrained environments, e.g. VMs with relatively small amounts of memory and tmp on tmpfs --- nixos/modules/installer/tools/nixos-install.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nixos/modules/installer/tools/nixos-install.sh b/nixos/modules/installer/tools/nixos-install.sh index 7fae915871e4..79ed18c923c0 100644 --- a/nixos/modules/installer/tools/nixos-install.sh +++ b/nixos/modules/installer/tools/nixos-install.sh @@ -126,6 +126,9 @@ function closure() { } system_closure="$tmpdir/system.closure" +# Use a FIFO for piping nix-store --export into nix-store --import, saving disk +# I/O and space. nix-store --import is run by nixos-prepare-root. +mkfifo $system_closure if [ -z "$closure" ]; then expr="(import {}).system" @@ -135,7 +138,9 @@ else system_root=$closure # Create a temporary file ending in .closure (so nixos-prepare-root knows to --import it) to transport the store closure # to the filesytem we're preparing. Also delete it on exit! - nix-store --export $(nix-store -qR $closure) > $system_closure + # Run in background to avoid blocking while trying to write to the FIFO + # $system_closure refers to + nix-store --export $(nix-store -qR $closure) > $system_closure & fi channel_root="$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path 2>/dev/null || echo -n "")"