-
Notifications
You must be signed in to change notification settings - Fork 10
/
base.nix
115 lines (92 loc) · 2.66 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
108
109
110
111
112
113
114
115
{ lib, pkgs, config, ... }:
with lib;
let
install-tools = (import ./install-tools { inherit pkgs; });
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;
};
kexec = mkOption {
description = ''
Don't do a full reboot, just load the new kernel and kexec it.
'';
default = false;
type = types.bool;
};
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;
};
};
config = {
networking.hostName = "install-environment";
# systemd.services.sshd.wantedBy = mkForce [ "multi-user.target" ];
systemd.services.dumpkeys = {
wantedBy = [ "multi-user.target" ];
after = [ "multi-user.target" ];
script = ''
if ${pkgs.gnugrep}/bin/grep -q dumpkeys /proc/cmdline; then
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
systemctl start sshd
fi
'';
};
systemd.services.doinstall = {
wantedBy = [ "multi-user.target" ];
after = [ "multi-user.target" ];
script = ''
# ${cfg.runTimeNixOS} # Force realization & config validation
. ${install-tools}/bin/tools.sh
initialize
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
${if cfg.kexec then "do_kexec" else "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";
};
};
};
}