-
Notifications
You must be signed in to change notification settings - Fork 10
/
flake.nix
160 lines (150 loc) · 6.33 KB
/
flake.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
{
description = "Profian Steward";
inputs.nixify.url = github:rvolosatovs/nixify;
outputs = {
self,
nixify,
...
}:
with nixify.lib;
rust.mkFlake {
src = ./.;
excludePaths = [
"/.github"
"/.gitignore"
"/deny.toml"
"/Enarx.toml"
"/flake.lock"
"/flake.nix"
"/LICENSE"
"/README.md"
"/rust-toolchain.toml"
];
clippy.allFeatures = true;
clippy.allTargets = true;
clippy.deny = ["warnings"];
withDevShells = {
devShells,
pkgs,
...
}:
extendDerivations {
buildInputs = [
pkgs.openssl
pkgs.wasmtime
];
}
devShells;
}
// {
nixosModules = let
steward = {
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.services.steward;
conf.toml = ''
crt = "${cfg.certFile}"
key = "${cfg.keyFile}"
'';
configFile = pkgs.writeText "steward.toml" conf.toml;
in {
options.services.steward = {
enable = mkEnableOption "Steward service.";
package = mkOption {
type = types.package;
default = self.packages.${pkgs.hostPlatform.system}.default;
defaultText = literalExpression "pkgs.steward";
description = "Steward package to use.";
};
log.level = mkOption {
type = with types; nullOr (enum ["trace" "debug" "info" "warn" "error"]);
default = null;
example = "debug";
description = "Log level to use, if unset the default value is used.";
};
log.json = mkOption {
type = types.bool;
default = false;
example = true;
description = "Whether to use JSON logging.";
};
certFile = mkOption {
type = types.path;
description = ''
Path to a certificate used by the Steward to issue certificates to
remote parties on successful attestation.
'';
example = literalExpression "./path/to/ca.crt";
};
keyFile = mkOption {
type = types.path;
description = ''
Path to a private key of certificate used by the Steward to issue certificates to
remote parties on successful attestation.
'';
example = literalExpression "./path/to/ca.key";
};
};
config = mkIf cfg.enable (mkMerge [
{
environment.systemPackages = [
cfg.package
];
systemd.services.steward.after = [
"network-online.target"
];
systemd.services.steward.description = "Steward";
systemd.services.steward.environment.RUST_LOG = cfg.log.level;
systemd.services.steward.serviceConfig.DeviceAllow = [""];
systemd.services.steward.serviceConfig.DynamicUser = true;
systemd.services.steward.serviceConfig.ExecPaths = ["/nix/store"];
systemd.services.steward.serviceConfig.ExecStart = "${cfg.package}/bin/steward @${configFile}";
systemd.services.steward.serviceConfig.InaccessiblePaths = ["-/lost+found"];
systemd.services.steward.serviceConfig.KeyringMode = "private";
systemd.services.steward.serviceConfig.LockPersonality = true;
systemd.services.steward.serviceConfig.NoExecPaths = ["/"];
systemd.services.steward.serviceConfig.NoNewPrivileges = true;
systemd.services.steward.serviceConfig.PrivateDevices = true;
systemd.services.steward.serviceConfig.PrivateMounts = "yes";
systemd.services.steward.serviceConfig.PrivateTmp = "yes";
systemd.services.steward.serviceConfig.ProtectClock = true;
systemd.services.steward.serviceConfig.ProtectControlGroups = "yes";
systemd.services.steward.serviceConfig.ProtectHome = true;
systemd.services.steward.serviceConfig.ProtectHostname = true;
systemd.services.steward.serviceConfig.ProtectKernelLogs = true;
systemd.services.steward.serviceConfig.ProtectKernelModules = true;
systemd.services.steward.serviceConfig.ProtectKernelTunables = true;
systemd.services.steward.serviceConfig.ProtectProc = "invisible";
systemd.services.steward.serviceConfig.ProtectSystem = "strict";
systemd.services.steward.serviceConfig.ReadOnlyPaths = ["/"];
systemd.services.steward.serviceConfig.RemoveIPC = true;
systemd.services.steward.serviceConfig.Restart = "always";
systemd.services.steward.serviceConfig.RestrictNamespaces = true;
systemd.services.steward.serviceConfig.RestrictRealtime = true;
systemd.services.steward.serviceConfig.RestrictSUIDSGID = true;
systemd.services.steward.serviceConfig.SystemCallArchitectures = "native";
systemd.services.steward.serviceConfig.Type = "exec";
systemd.services.steward.serviceConfig.UMask = "0077";
systemd.services.steward.unitConfig.AssertPathExists = [
cfg.certFile
cfg.keyFile
configFile
];
systemd.services.steward.wantedBy = ["multi-user.target"];
systemd.services.steward.wants = ["network-online.target"];
}
(mkIf (cfg.log.json) {
systemd.services.steward.environment.RUST_LOG_JSON = "true";
})
]);
};
in {
inherit steward;
default = steward;
};
};
}