-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnspawn-tarball.nix
69 lines (59 loc) · 1.61 KB
/
nspawn-tarball.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{ config, pkgs, ... }:
let
makeTarball = pkgs.callPackage (pkgs.path + "/nixos/lib/make-system-tarball.nix");
flakeFile = builtins.toFile "flake.nix" ''
{
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
outputs = inputs@{ self, nixpkgs, ...}: {
nixosConfigurations.${config.system.name} = nixpkgs.lib.nixosSystem {
system = "${pkgs.system}";
modules = [
./configuration.nix
];
};
};
}
'';
in
{
boot.postBootCommands = ''
# After booting, register the contents of the Nix store in the Nix
# database.
if [ -f /nix-path-registration ]; then
${config.nix.package.out}/bin/nix-store --load-db < /nix-path-registration &&
rm /nix-path-registration
fi
'';
system.build.tarball = makeTarball {
extraArgs = "--owner=0";
storeContents = [
{
object = config.system.build.toplevel;
symlink = "/nix/var/nix/profiles/system";
}
];
contents = [
{
# systemd-nspawn requires this file to exist
source = config.system.build.toplevel + "/etc/os-release";
target = "/etc/os-release";
}
{
source = flakeFile;
target = "/etc/nixos/flake.nix";
}
{
source = ./configuration.nix;
target = "/etc/nixos/configuration.nix";
}
{
source = ./nspawn-image.nix;
target = "/etc/nixos/nspawn-image.nix";
}
];
extraCommands = pkgs.writeScript "extra-commands" ''
mkdir -p proc sys dev sbin
ln -sf /nix/var/nix/profiles/system/init sbin/init
'';
};
}