3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #17768 from obadz/nixos-install

nixos-install: cleanups & improvements to run on non-NixOS systems
This commit is contained in:
Eelco Dolstra 2016-08-16 13:31:50 +02:00 committed by GitHub
commit 38f306f492
2 changed files with 16 additions and 15 deletions

View file

@ -24,7 +24,6 @@ fi
# Parse the command line for the -I flag # Parse the command line for the -I flag
extraBuildFlags=() extraBuildFlags=()
chrootCommand=(/run/current-system/sw/bin/bash) chrootCommand=(/run/current-system/sw/bin/bash)
bootLoader=1
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
i="$1"; shift 1 i="$1"; shift 1
@ -51,7 +50,7 @@ while [ "$#" -gt 0 ]; do
noRootPasswd=1 noRootPasswd=1
;; ;;
--no-bootloader) --no-bootloader)
bootLoader=0 noBootLoader=1
;; ;;
--show-trace) --show-trace)
extraBuildFlags+=("$i") extraBuildFlags+=("$i")
@ -142,7 +141,7 @@ mkdir -m 0755 -p \
$mountPoint/nix/var/log/nix/drvs $mountPoint/nix/var/log/nix/drvs
mkdir -m 1775 -p $mountPoint/nix/store mkdir -m 1775 -p $mountPoint/nix/store
chown root:nixbld $mountPoint/nix/store chown root:@nixbld_gid@ $mountPoint/nix/store
# There is no daemon in the chroot. # There is no daemon in the chroot.
@ -155,14 +154,14 @@ export LC_ALL=
export LC_TIME= export LC_TIME=
# Create a temporary Nix config file that causes the nixbld users to # Builds will use users that are members of this group
# be used. extraBuildFlags+=(--option "build-users-group" "nixbld")
echo "build-users-group = nixbld" > $mountPoint/tmp/nix.conf # FIXME: remove in Nix 1.8
binary_caches=$(@perl@/bin/perl -I @nix@/lib/perl5/site_perl/*/* -e 'use Nix::Config; Nix::Config::readConfig; print $Nix::Config::config{"binary-caches"};')
if test -n "$binary_caches"; then # Inherit binary caches from the host
echo "binary-caches = $binary_caches" >> $mountPoint/tmp/nix.conf binary_caches="$(@perl@/bin/perl -I @nix@/lib/perl5/site_perl/*/* -e 'use Nix::Config; Nix::Config::readConfig; print $Nix::Config::config{"binary-caches"};')"
fi extraBuildFlags+=(--option "binary-caches" "$binary_caches")
export NIX_CONF_DIR=/tmp
touch $mountPoint/etc/passwd $mountPoint/etc/group touch $mountPoint/etc/passwd $mountPoint/etc/group
mount --bind -o ro /etc/passwd $mountPoint/etc/passwd mount --bind -o ro /etc/passwd $mountPoint/etc/passwd
@ -263,16 +262,17 @@ touch $mountPoint/etc/NIXOS
# a menu default pointing at the kernel/initrd/etc of the new # a menu default pointing at the kernel/initrd/etc of the new
# configuration. # configuration.
echo "finalising the installation..." echo "finalising the installation..."
NIXOS_INSTALL_GRUB="$bootLoader" chroot $mountPoint \ if [ -z "$noBootLoader" ]; then
NIXOS_INSTALL_GRUB=1 chroot $mountPoint \
/nix/var/nix/profiles/system/bin/switch-to-configuration boot /nix/var/nix/profiles/system/bin/switch-to-configuration boot
fi
# Run the activation script. # Run the activation script.
chroot $mountPoint /nix/var/nix/profiles/system/activate chroot $mountPoint /nix/var/nix/profiles/system/activate
# Ask the user to set a root password. # Ask the user to set a root password.
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 if [ -z "$noRootPasswd" ] && [ -x $mountPoint/var/setuid-wrappers/passwd ] && [ -t 0 ]; then
echo "setting root password..." echo "setting root password..."
chroot $mountPoint /var/setuid-wrappers/passwd chroot $mountPoint /var/setuid-wrappers/passwd
fi fi

View file

@ -24,6 +24,7 @@ let
inherit (pkgs) perl pathsFromGraph rsync; inherit (pkgs) perl pathsFromGraph rsync;
nix = config.nix.package.out; nix = config.nix.package.out;
cacert = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; cacert = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
nixbld_gid = config.ids.gids.nixbld;
nixClosure = pkgs.runCommand "closure" nixClosure = pkgs.runCommand "closure"
{ exportReferencesGraph = ["refs" config.nix.package.out]; } { exportReferencesGraph = ["refs" config.nix.package.out]; }