···
70
-
# The initrd expects these directories to exist.
71
-
mkdir /mnt/dev /mnt/proc /mnt/sys
73
-
mount -o bind /proc /mnt/proc
74
-
mount -o bind /dev /mnt/dev
75
-
mount -o bind /sys /mnt/sys
77
-
# Copy all paths in the closure to the filesystem.
78
-
storePaths=$(perl ${pkgs.pathsFromGraph} /tmp/xchg/closure)
80
-
mkdir -p /mnt/nix/store
81
-
echo "copying everything (will take a while)..."
83
-
cp -prd $storePaths /mnt/nix/store/
# Register the paths in the Nix database.
printRegistration=1 perl ${pkgs.pathsFromGraph} /tmp/xchg/closure | \
87
-
chroot /mnt ${config.nix.package.out}/bin/nix-store --load-db --option build-users-group ""
72
+
${config.nix.package.out}/bin/nix-store --load-db --option build-users-group ""
# Add missing size/hash fields to the database. FIXME:
# exportReferencesGraph should provide these directly.
91
-
chroot /mnt ${config.nix.package.out}/bin/nix-store --verify --check-contents
76
+
${config.nix.package.out}/bin/nix-store --verify --check-contents --option build-users-group ""
93
-
# Create the system profile to allow nixos-rebuild to work.
94
-
chroot /mnt ${config.nix.package.out}/bin/nix-env --option build-users-group "" \
95
-
-p /nix/var/nix/profiles/system --set ${config.system.build.toplevel}
78
+
# In case the bootloader tries to write to /dev/sda…
97
-
# `nixos-rebuild' requires an /etc/NIXOS.
99
-
touch /mnt/etc/NIXOS
101
-
# `switch-to-configuration' requires a /bin/sh
103
-
ln -s ${config.system.build.binsh}/bin/sh /mnt/bin/sh
82
+
# Install the closure onto the image
83
+
USER=root ${config.system.build.nixos-install}/bin/nixos-install \
84
+
--closure ${config.system.build.toplevel} \
87
+
${optionalString (!installBootLoader) "--no-bootloader"}
# Install a configuration.nix.
···
cp ${configFile} /mnt/etc/nixos/configuration.nix
111
-
# Generate the GRUB menu.
112
-
ln -s vda /dev/xvda
114
-
${optionalString installBootLoader "chroot /mnt ${config.system.build.toplevel}/bin/switch-to-configuration boot"}
95
+
# Remove /etc/machine-id so that each machine cloning this image will get its own id
96
+
rm -f /mnt/etc/machine-id
116
-
umount /mnt/proc /mnt/dev /mnt/sys
# Do a fsck to make sure resize2fs works.