Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
254 lines (230 loc) · 7.19 KB
/
Copy pathflake.nix
File metadata and controls
254 lines (230 loc) · 7.19 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
srvos.url = "github:numtide/srvos";
srvos.inputs.nixpkgs.follows = "nixpkgs";
disko.url = "github:nix-community/disko";
disko.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { nixpkgs, nixpkgs-unstable, ... }@inputs:
let
host = {
name = "FIXME";
system = "x86_64-linux";
hostId = "FIXME"; # generate with: openssl rand -hex 4
ipv6 = "FIXME";
isCloud = true;
isArm = false;
diskDevices = [ "/dev/sda" ];
diskConfiguration = ./hetzner-cloud-ext4.nix;
diskOptions = {
hetzner.cloud-ext4 = {
mountOptions = [ ];
journalMode = "data=ordered";
};
};
adminUser = {
name = "FIXME";
initialPassword = "change-me";
extraGroups = [ "wheel" "docker" "systemd-journal" ];
authorizedKeys = [
"FIXME"
];
};
};
# host = {
# name = "FIXME";
# system = "x86_64-linux";
# hostId = "FIXME"; # generate with: openssl rand -hex 4
# ipv6 = "FIXME";
# isCloud = false;
# isArm = false;
# diskDevices = [ "/dev/nvme0n1" "/dev/nvme1n1" ];
# diskConfiguration = ./hetzner-robot-mdadm.nix;
# diskOptions = {
# hetzner."robot-mdadm" = {
# level = 0;
# fs = "ext4";
# };
# };
# adminUser = {
# name = "FIXME";
# initialPassword = "change-me";
# extraGroups = [ "wheel" "docker" "systemd-journal" ];
# authorizedKeys = [
# "FIXME"
# ];
# };
# };
baseModule =
{ lib
, pkgs
, pkgs-unstable
, inputs
, isCloud
, isArm
, diskDevices
, modulesPath
, hostName
, hostId
, ipv6
, nixpkgsFlake
, adminUser
, ...
}:
{
imports = [
inputs.srvos.nixosModules.server
(if isCloud then
if isArm then inputs.srvos.nixosModules.hardware-hetzner-cloud-arm
else inputs.srvos.nixosModules.hardware-hetzner-cloud
else inputs.srvos.nixosModules.hardware-hetzner-online-amd)
"${modulesPath}/installer/scan/not-detected.nix"
"${modulesPath}/profiles/all-hardware.nix"
inputs.disko.nixosModules.disko
];
systemd.network.networks."10-uplink".networkConfig.Address = ipv6;
networking.hostName = hostName;
networking.hostId = hostId;
boot.loader.grub = {
enable = if isCloud && isArm then lib.mkForce false else true;
devices = diskDevices;
efiSupport = true;
efiInstallAsRemovable = true;
};
system.stateVersion = "24.11";
# `nix run nixpkgs#hello` will use nixpkgs from this flake
nix.registry.nixpkgs.flake = nixpkgsFlake;
# <nixpkgs> will resolve to this flake
nix.nixPath = [ "nixpkgs=flake:nixpkgs" ];
nixpkgs.config.allowUnfree = true;
nixpkgs.config.nvidia.acceptLicense = true;
environment.systemPackages = with pkgs; [
gettext
lf
ripgrep
fd
bottom
cloud-utils
lsof
nil
nixpkgs-fmt
ncdu
kitty.terminfo
just
openssl
wget
fio
];
environment.shellAliases = {
sctl = "systemctl --user";
jctl = "journalctl --user";
};
environment.extraInit = ''
export PATH="$HOME/.npm-global/bin:$PATH"
'';
services.journald.rateLimitBurst = 0;
services.journald.rateLimitInterval = "0";
services.journald.extraConfig = ''
RuntimeMaxUse=1G
SystemMaxUse=20G
SystemKeepFree=15G
MaxFileSec=1month
SystemMaxFiles=10000
'';
networking.firewall = {
enable = true;
allowedTCPPorts = [ ];
allowedUDPPorts = [ ];
allowPing = true;
trustedInterfaces = [ ];
};
services.openssh.enable = true;
services.openssh.openFirewall = true;
services.openssh.settings.PasswordAuthentication = false;
services.openssh.settings.PermitRootLogin = "no";
services.openssh.settings.MaxStartups = "20:30:100";
programs.ssh.startAgent = true;
programs.mosh.enable = false;
services.fail2ban.enable = true;
services.fail2ban.bantime-increment.enable = true;
programs.direnv.enable = true;
virtualisation.docker.enable = true;
virtualisation.docker.package = pkgs-unstable.docker;
programs.nix-ld.enable = true;
programs.nix-ld.libraries = with pkgs; [
rdkafka
];
programs.git.enable = true;
programs.git.lfs.enable = false;
nix.gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 14d";
};
security.sudo.wheelNeedsPassword = lib.mkForce true;
users.mutableUsers = lib.mkForce true;
users.users.${adminUser.name} = {
inherit (adminUser) initialPassword extraGroups;
isNormalUser = true;
openssh.authorizedKeys = {
keys = adminUser.authorizedKeys;
};
};
systemd.tmpfiles.rules = [
"f /var/lib/systemd/linger/${adminUser.name}"
"d /var/lib/socks 0700 root root"
];
services.tailscale.enable = true;
systemd.services.tailscaled = {
before = [ "remote-fs-pre.target" ];
wantedBy = [ "remote-fs-pre.target" ];
serviceConfig = {
ExecStartPost = ''${pkgs.bash}/bin/bash -c 'echo "Sleeping for 10 seconds to appear initialized for dependent units..." && sleep 10' '';
};
};
};
mkHost =
{ name
, system
, hostId
, ipv6
, diskDevices
, adminUser
, isCloud ? false
, isArm ? false
, diskConfiguration
, diskOptions ? { }
, extraModules ? [ ]
,
}:
let
pkgs-unstable = import nixpkgs-unstable {
inherit system;
config = {
allowUnfree = true;
};
};
in
nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = {
inherit inputs isCloud isArm diskDevices hostId ipv6 adminUser;
hostName = name;
nixpkgsFlake = inputs.nixpkgs;
pkgs-unstable = pkgs-unstable;
};
modules =
[
baseModule
diskConfiguration
diskOptions
]
++ extraModules;
};
in
{
nixosConfigurations.${host.name} = mkHost host;
};
}