blob: f8cb0ab4509ba8917cffa21b576348a493a50e90 (
plain)
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
|
{
config,
lib,
secretsDir,
inputs,
inputs',
...
}:
let
cfg = config.borealis.profiles.server;
# 2^30
# Why doesn't nix have a `pow`???
gb = 1024 * 1024 * 1024;
minimumStorageKb = 15 * gb;
in
{
options.borealis.profiles.server = {
enable = lib.mkEnableOption "the Server profile";
};
config = lib.mkIf cfg.enable (
lib.mkMerge [
{
_module.args = {
# All servers are most likely on stable, so we want to pull in some newer packages from time to time
unstable = inputs'.nixpkgs.legacyPackages;
secretsDir = inputs.self + "/secrets/${config.networking.hostName}";
};
age.secrets = {
tailscaleAuthKey.file = "${secretsDir}/tailscaleAuthKey.age";
};
boot.tmp.cleanOnBoot = lib.mkDefault true;
borealis.users = {
system.enable = true;
};
# We don't need it here
documentation.enable = false;
environment.defaultPackages = lib.mkForce [ ];
nix.gc = {
dates = "*:0/30"; # Every 30 minutes
# GC to stay above minimumStorageBytes
options = toString [
"--delete-older-than 5d"
"--max-freed \"$((${toString minimumStorageKb} - 1024 * $(df -k --output=avail /nix/store | tail -n 1)))\""
];
};
services = {
comin.enable = true;
tailscale = {
enable = true;
authKeyFile = config.age.secrets.tailscaleAuthKey.path;
extraUpFlags = [ "--ssh" ];
};
};
# I use exclusively Tailscale auth on some machines
users.allowNoPasswordLogin = true;
zramSwap.enable = true;
}
(lib.mkIf config.borealis.users.system.enable {
# Hardening access to `nix` as no other users *should* ever really touch it
nix.settings.allowed-users = [ config.networking.hostName ];
})
]
);
}
|