2023-05-07 16:34:09 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.harmonia;
|
|
|
|
format = pkgs.formats.toml { };
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.harmonia = {
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = lib.mkEnableOption "Harmonia: Nix binary cache written in Rust";
|
2023-05-07 16:34:09 +00:00
|
|
|
|
|
|
|
signKeyPath = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
|
|
|
default = null;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Path to the signing key that will be used for signing the cache";
|
2023-05-07 16:34:09 +00:00
|
|
|
};
|
|
|
|
|
2023-11-30 18:03:14 +00:00
|
|
|
package = lib.mkPackageOption pkgs "harmonia" { };
|
2023-05-07 16:34:09 +00:00
|
|
|
|
|
|
|
settings = lib.mkOption {
|
|
|
|
inherit (format) type;
|
2023-05-10 16:41:25 +00:00
|
|
|
default = { };
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2023-05-10 16:41:25 +00:00
|
|
|
Settings to merge with the default configuration.
|
|
|
|
For the list of the default configuration, see <https://github.com/nix-community/harmonia/tree/master#configuration>.
|
|
|
|
'';
|
2023-05-07 16:34:09 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2023-11-04 08:04:35 +00:00
|
|
|
nix.settings.extra-allowed-users = [ "harmonia" ];
|
2023-12-03 16:07:48 +00:00
|
|
|
users.users.harmonia = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "harmonia";
|
|
|
|
};
|
|
|
|
users.groups.harmonia = { };
|
2023-11-04 08:04:35 +00:00
|
|
|
|
2023-05-07 16:34:09 +00:00
|
|
|
systemd.services.harmonia = {
|
|
|
|
description = "harmonia binary cache service";
|
|
|
|
|
|
|
|
requires = [ "nix-daemon.socket" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
CONFIG_FILE = format.generate "harmonia.toml" cfg.settings;
|
|
|
|
SIGN_KEY_PATH = lib.mkIf (cfg.signKeyPath != null) "%d/sign-key";
|
|
|
|
# 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
|
|
|
|
HOME = "/run/harmonia";
|
|
|
|
};
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = lib.getExe cfg.package;
|
|
|
|
User = "harmonia";
|
|
|
|
Group = "harmonia";
|
2023-12-10 21:42:56 +00:00
|
|
|
Restart = "on-failure";
|
2023-05-07 16:34:09 +00:00
|
|
|
PrivateUsers = true;
|
|
|
|
DeviceAllow = [ "" ];
|
|
|
|
UMask = "0066";
|
|
|
|
RuntimeDirectory = "harmonia";
|
2023-05-10 16:41:25 +00:00
|
|
|
LoadCredential = lib.mkIf (cfg.signKeyPath != null) [ "sign-key:${cfg.signKeyPath}" ];
|
2023-05-07 16:34:09 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|