git.iko.soy/typeable/nixpkgs
on master help sign in
nixos-install: cleanups & improvements to run on non-NixOS systems

- Fix --no-bootloader which didn't do what it advertised - Hardcode nixbld GID so that systems which do not have a nixbld user can still run nixos-install (only with --closure since they can't build anything) - Cleanup: get rid of NIX_CONF_DIR(=/tmp)/nix.conf and pass arguments instead - Cleanup: don't assume that the target system has '<nixpkgs/nixos>' or '<nixos-config>' to see if config.users.mutableUsers. Instead check if /var/setuid-wrappers/passwd is there Installing NixOS now works from a Ubuntu host (using --closure). nix-build -A tests.installer.simple '<nixpkgs/nixos/release.nix>' succeeds ✓

commit806e88c13771e5ec336f3ca14969c5f314482a67 authorobadz <obadz-git@obadz.com> dateTue 16 Aug 2016, 01:15 (10 years ago) parent21df40f
2 files changed+16−15
nixos/modules/installer/tools/nixos-install.sh+15−15 nixos/modules/installer/tools/tools.nix+1
nixos/modules/installer/tools/nixos-install.sh+15−15
@@ -24,7 +24,6 @@ fi
2424# Parse the command line for the -I flag
2525extraBuildFlags=()
2626chrootCommand=(/run/current-system/sw/bin/bash)
27−bootLoader=1
2827
2928while [ "$#" -gt 0 ]; do
3029 i="$1"; shift 1
@@ -51,7 +50,7 @@ while [ "$#" -gt 0 ]; do
5150 noRootPasswd=1
5251 ;;
5352 --no-bootloader)
54− bootLoader=0
53+ noBootLoader=1
5554 ;;
5655 --show-trace)
5756 extraBuildFlags+=("$i")
@@ -142,7 +141,7 @@ mkdir -m 0755 -p \
142141 $mountPoint/nix/var/log/nix/drvs
143142
144143mkdir -m 1775 -p $mountPoint/nix/store
145−chown root:nixbld $mountPoint/nix/store
144+chown root:@nixbld_gid@ $mountPoint/nix/store
146145
147146
148147# There is no daemon in the chroot.
@@ -155,14 +154,14 @@ export LC_ALL=
155154export LC_TIME=
156155
157156
158−# Create a temporary Nix config file that causes the nixbld users to
159−# be used.
160−echo "build-users-group = nixbld" > $mountPoint/tmp/nix.conf # FIXME: remove in Nix 1.8
161−binary_caches=$(@perl@/bin/perl -I @nix@/lib/perl5/site_perl/*/* -e 'use Nix::Config; Nix::Config::readConfig; print $Nix::Config::config{"binary-caches"};')
162−if test -n "$binary_caches"; then
163− echo "binary-caches = $binary_caches" >> $mountPoint/tmp/nix.conf
164−fi
165−export NIX_CONF_DIR=/tmp
157+# Builds will use users that are members of this group
158+extraBuildFlags+=(--option "build-users-group" "nixbld")
159+
160+
161+# Inherit binary caches from the host
162+binary_caches="$(@perl@/bin/perl -I @nix@/lib/perl5/site_perl/*/* -e 'use Nix::Config; Nix::Config::readConfig; print $Nix::Config::config{"binary-caches"};')"
163+extraBuildFlags+=(--option "binary-caches" "$binary_caches")
164+
166165
167166touch $mountPoint/etc/passwd $mountPoint/etc/group
168167mount --bind -o ro /etc/passwd $mountPoint/etc/passwd
@@ -263,16 +262,17 @@ touch $mountPoint/etc/NIXOS
263262# a menu default pointing at the kernel/initrd/etc of the new
264263# configuration.
265264echo "finalising the installation..."
266−NIXOS_INSTALL_GRUB="$bootLoader" chroot $mountPoint \
267− /nix/var/nix/profiles/system/bin/switch-to-configuration boot
268−
265+if [ -z "$noBootLoader" ]; then
266+ NIXOS_INSTALL_GRUB=1 chroot $mountPoint \
267+ /nix/var/nix/profiles/system/bin/switch-to-configuration boot
268+fi
269269
270270# Run the activation script.
271271chroot $mountPoint /nix/var/nix/profiles/system/activate
272272
273273
274274# Ask the user to set a root password.
275−if [ -z "$noRootPasswd" ] && [ "$(chroot $mountPoint /run/current-system/sw/bin/sh -l -c "nix-instantiate --eval '<nixpkgs/nixos>' -A config.users.mutableUsers")" = true ] && [ -t 0 ] ; then
275+if [ -z "$noRootPasswd" ] && [ -x $mountPoint/var/setuid-wrappers/passwd ] && [ -t 0 ]; then
276276 echo "setting root password..."
277277 chroot $mountPoint /var/setuid-wrappers/passwd
278278fi
nixos/modules/installer/tools/tools.nix+1
@@ -24,6 +24,7 @@ let
2424 inherit (pkgs) perl pathsFromGraph rsync;
2525 nix = config.nix.package.out;
2626 cacert = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
27+ nixbld_gid = config.ids.gids.nixbld;
2728
2829 nixClosure = pkgs.runCommand "closure"
2930 { exportReferencesGraph = ["refs" config.nix.package.out]; }