0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-11 21:06:19 +03:00

Refactor nixos-install to separate out filesystem build logic

The key distinction I'm drawing is that there's a component that deals
with the store of the machine being built, and another component for
the store building it. The inner part of it assumes nothing from the
builder (doesn't need chroot or root powers) so it can run comfortably
inside a Nix build, as well as nixos-rebuild. I have some upcoming work
that will use that to significantly speed up and streamline image builds
for NixOS, especially on virtualized hosts like EC2, but it's also a
reasonable speedup on native hosts.
This commit is contained in:
Dan Peebles 2017-02-20 19:57:16 +00:00
parent 91d2dc00bb
commit d990aa7163
5 changed files with 164 additions and 130 deletions

View file

@ -34,6 +34,12 @@ let
boot.loader.systemd-boot.enable = true;
''}
users.extraUsers.alice = {
isNormalUser = true;
home = "/home/alice";
description = "Alice Foobar";
};
hardware.enableAllFirmware = lib.mkForce false;
${replaceChars ["\n"] ["\n "] extraConfig}
@ -96,7 +102,7 @@ let
$machine->shutdown;
# Now see if we can boot the installation.
$machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}" });
$machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}", name => "boot-after-install" });
# For example to enter LUKS passphrase.
${preBootCommands}
@ -118,11 +124,17 @@ let
$machine->waitForUnit("swap.target");
$machine->succeed("cat /proc/swaps | grep -q /dev");
# Check that the store is in good shape
$machine->succeed("nix-store --verify --check-contents >&2");
# Check whether the channel works.
$machine->succeed("nix-env -iA nixos.procps >&2");
$machine->succeed("type -tP ps | tee /dev/stderr") =~ /.nix-profile/
or die "nix-env failed";
# Check that the daemon works, and that non-root users can run builds (this will build a new profile generation through the daemon)
$machine->succeed("su alice -l -c 'nix-env -iA nixos.procps' >&2");
# We need to a writable nix-store on next boot.
$machine->copyFileFromHost(
"${ makeConfig { inherit bootLoader grubVersion grubDevice grubIdentifier extraConfig; forceGrubReinstallCount = 1; } }",
@ -139,7 +151,7 @@ let
$machine->shutdown;
# Check whether a writable store build works
$machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}" });
$machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}", name => "rebuild-switch" });
${preBootCommands}
$machine->waitForUnit("multi-user.target");
$machine->copyFileFromHost(
@ -150,7 +162,7 @@ let
# And just to be sure, check that the machine still boots after
# "nixos-rebuild switch".
$machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}" });
$machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}", "boot-after-rebuild-switch" });
${preBootCommands}
$machine->waitForUnit("network.target");
$machine->shutdown;