forked from grahamc/packet-nixos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.nix
107 lines (84 loc) · 2.37 KB
/
base.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{ lib, pkgs, config, ... }:
with lib;
let
install-tools = (import ./install-tools {});
cfg = config.installer;
in {
options.installer = {
runTimeNixOS = mkOption {
description = ''
A path of a NixOS system that closely resembles the final
version of NixOS, so minimal building takes place on the
target.
To speed up the build.
'';
default = "";
type = types.path;
};
configFiles = mkOption {
description = "Config files to copy to the installed system";
type = types.listOf types.path;
};
type = mkOption {
description = "System Type";
type = types.string;
};
partition = mkOption {
description = "Partitioning commands";
type = types.string;
};
format = mkOption {
description = "Formatting commands";
type = types.string;
};
mount = mkOption {
description = "Mounting commands";
type = types.string;
};
};
imports = [
<nixpkgs/nixos/modules/installer/netboot/netboot-minimal.nix>
];
config = {
networking.hostName = "ipxe-${cfg.type}";
systemd.services.sshd.wantedBy = mkForce [ "multi-user.target" ];
systemd.services.dumpkeys = {
wantedBy = [ "multi-user.target" ];
after = [ "multi-user.target" ];
script = ''
mkdir /root/.ssh || true
touch /root/.ssh/authorized_keys
chmod 0644 /root/.ssh/authorized_keys
${install-tools}/bin/dump-keys.py > /root/.ssh/authorized_keys
'';
};
systemd.services.doinstall = {
wantedBy = [ "multi-user.target" ];
after = [ "multi-user.target" ];
script = ''
# ${cfg.runTimeNixOS} # Force realization & config validation
. ${install-tools}/bin/tools.sh
pre_partition
${cfg.partition}
pre_format
${cfg.format}
pre_mount
${cfg.mount}
post_mount
generate_standard_config
cp \
${lib.concatMapStrings
(x: " ${x} \\\n")
cfg.configFiles
} /mnt/etc/nixos/packet/
finalize_config
do_install
do_reboot
'';
environment = {
NIX_PATH = "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels";
HOME = "/root";
};
};
};
}