forked from helsinki-systems/harmonia
-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmodule.nix
103 lines (88 loc) · 2.94 KB
/
module.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
{ config, pkgs, lib, ... }:
let
cfg = config.services.harmonia-dev;
format = pkgs.formats.toml { };
configFile = format.generate "harmonia.toml" cfg.settings;
in
{
options = {
services.harmonia-dev = {
enable = lib.mkEnableOption (lib.mdDoc "Harmonia: Nix binary cache written in Rust");
signKeyPath = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = lib.mdDoc "Path to the signing key to use for signing the cache";
};
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = format.type;
};
description = lib.mdDoc "Settings to merge with the default configuration";
};
};
};
config = lib.mkIf cfg.enable {
services.harmonia-dev.settings = builtins.mapAttrs (_: v: lib.mkDefault v) {
bind = "[::]:5000";
workers = 4;
max_connection_rate = 256;
priority = 50;
};
systemd.services.harmonia-dev = {
description = "harmonia binary cache service";
requires = [ "nix-daemon.socket" ];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
environment = {
NIX_REMOTE = "daemon";
LIBEV_FLAGS = "4"; # go ahead and mandate epoll(2)
CONFIG_FILE = lib.mkIf (configFile != null) configFile;
SIGN_KEY_PATH = lib.mkIf (cfg.signKeyPath != null) "%d/sign-key";
RUST_LOG = "info";
};
# Note: it's important to set this for nix-store, because it wants to use
# $HOME in order to use a temporary cache dir. bizarre failures will occur
# otherwise
environment.HOME = "/run/harmonia";
serviceConfig = {
ExecStart = "${pkgs.callPackage ./. { }}/bin/harmonia";
User = "harmonia";
Group = "harmonia";
DynamicUser = true;
PrivateUsers = true;
DeviceAllow = [ "" ];
UMask = "0066";
RuntimeDirectory = "harmonia";
LoadCredential = lib.optional (cfg.signKeyPath != null) "sign-key:${cfg.signKeyPath}";
SystemCallFilter = [
"@system-service"
"~@privileged"
"~@resources"
];
CapabilityBoundingSet = "";
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectControlGroups = true;
ProtectKernelLogs = true;
ProtectHostname = true;
ProtectClock = true;
RestrictRealtime = true;
MemoryDenyWriteExecute = true;
ProcSubset = "pid";
ProtectProc = "invisible";
RestrictNamespaces = true;
SystemCallArchitectures = "native";
PrivateNetwork = false;
PrivateTmp = true;
PrivateDevices = true;
PrivateMounts = true;
NoNewPrivileges = true;
ProtectSystem = "strict";
ProtectHome = true;
LockPersonality = true;
RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6";
LimitNOFILE = 65536;
};
};
};
}