This repository has been archived by the owner on May 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
module.nix
79 lines (62 loc) · 1.89 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
{ config, pkgs, lib, ... }:
let
cfg = config.services.harmonia;
format = pkgs.formats.toml { };
configFile = format.generate "harmonia.toml" cfg.settings;
harmonia = import ./. { inherit pkgs; };
in
{
options = {
services.harmonia = {
enable = lib.mkEnableOption "Harmonia: Nix binary cache written in Rust";
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = format.type;
};
description = "Settings to merge with the default configuration";
};
};
};
config = lib.mkIf cfg.enable {
services.harmonia.settings = builtins.mapAttrs (_: v: lib.mkDefault v) {
bind = "[::]:5000";
workers = 4;
max_connection_rate = 256;
priority = 50;
};
environment.systemPackages = [ harmonia ];
systemd.services.harmonia = {
description = "harmonia binary cache service";
requires = [ "nix-daemon.socket" ];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
path = [ config.nix.package.out ];
environment = {
NIX_REMOTE = "daemon";
LIBEV_FLAGS = "4"; # go ahead and mandate epoll(2)
CONFIG_FILE = lib.mkIf (configFile != null) configFile;
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 = "${harmonia}/bin/harmonia";
User = "harmonia";
Group = "harmonia";
RuntimeDirectory = "harmonia";
SystemCallFilter = "@system-service";
PrivateNetwork = false;
LimitNOFILE = 65536;
};
};
users = {
users.harmonia = {
isSystemUser = true;
group = "harmonia";
};
groups.harmonia = { };
};
};
}