-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.nix
183 lines (170 loc) · 4.52 KB
/
configuration.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
{ kernelVersion }:
{ pkgs, config, lib, modulesPath, ... }:
let
systemdMini = pkgs.systemdMinimal.override {
withAnalyze = true;
withApparmor = true;
withLogind = true;
withTimesyncd = true;
withCoredump = true;
withCompression = true;
withFido2 = false;
withTpm2Tss = false;
};
in
with lib; with pkgs; {
imports = [
"${modulesPath}/profiles/minimal.nix"
];
systemd = {
package = systemdMini;
services = {
nix-daemon.enable = false;
mount-pstore.enable = false;
sysctl.enable = false;
journald.enable = false;
user-sessions.enable = false;
shutdownRamfs.enable = false;
};
sockets.nix-daemon.enable = false;
};
services = {
openssh = {
enable = true;
startWhenNeeded = true;
permitRootLogin = "yes";
};
# timesyncd.enable = false;
udisks2.enable = false;
# getty.autologinUser = "root";
nscd.config = replaceStrings
[ "server-user nscd" ]
[ "server-user root" ]
(builtins.readFile "${modulesPath}/services/system/nscd.conf");
};
users.users.root = {
password = "root";
};
system = {
stateVersion = "22.05";
activationScripts = {
installInitScript = ''
mkdir -p /sbin
ln -fs $systemConfig/init /sbin/init
'';
};
};
environment = {
defaultPackages = [
nano
curl
nerdctl
iptables
coreutils
time
which
gnused
gnutar
gzip
less
getent
gawk
findutils
netcat
];
};
nixpkgs.overlays = [
(self: super: {
iptables = super.iptables-legacy;
containerd = (callPackage "${path}/pkgs/applications/virtualization/containerd" {
btrfs-progs = null;
});
openssh = (super.openssh.overrideAttrs (final: prev: {
doCheck = false;
})).override {
withFIDO = false;
withKerberos = false;
};
nerdctl = super.nerdctl.overrideAttrs (final: prev: {
postInstall = ''
wrapProgram $out/bin/nerdctl \
--prefix CNI_PATH : "${cni-plugins}/bin"
installShellCompletion --cmd nerdctl \
--bash <($out/bin/nerdctl completion bash) \
--fish <($out/bin/nerdctl completion fish) \
--zsh <($out/bin/nerdctl completion zsh)
'';
});
systemdStage1 = systemdMini;
# systemdMinimal = systemdMini;
# ffs this is causing a dup
})
];
networking = {
hostName = "nixos";
resolvconf.enable = false;
dhcpcd.enable = false;
firewall.enable = false;
wireless.enable = false;
};
virtualisation = {
docker = {
enable = false;
enableOnBoot = false;
};
podman = {
# enable = true;
# dockerCompat = true;
};
containerd = {
enable = true;
};
};
security = {
audit.enable = false;
polkit.enable = false;
sudo.enable = false;
};
boot = {
kernelParams = [ "console=ttyS0" "noapic" "reboot=k" "panic=1" "pci=off" "nomodules" "rw" "init=/nix/var/nix/profiles/system/init" ];
loader.grub.enable = false;
initrd.includeDefaultModules = false;
initrd.availableKernelModules = mkForce [ ];
kernelModules = [ "dm-mod" ];
kernelPackages =
let
version = kernelVersion; # e.g. 5.10.135
pkgsVersion = concatStringsSep "_" (take 2 (splitString "." version)); # e.g. 5_10
majorVersion = head (splitString "." version); # e.g. 5
base = "linuxPackages_${pkgsVersion}";
in
linuxPackagesFor (linuxKernel.manualConfig {
inherit stdenv lib version;
src = fetchTarball {
url = "https://cdn.kernel.org/pub/linux/kernel/v${majorVersion}.x/linux-${version}.tar.xz";
sha256 = "sha256-qNCcrECmuBE9YDwXSs0hbe7clhqczfJeEGP/nNjE1zY=";
};
configfile = ./microvm-kernel-x86_64.config;
allowImportFromDerivation = true;
});
};
fileSystems = {
"/" = {
device = "/dev/vda";
# options = [ "ro" ];
neededForBoot = true;
};
};
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
# nixos-rebuild also requires a "system" profile
${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system \
--set /run/current-system
'';
nix.gc.automatic = true;
}