nix/module/RemoteBuilder.nix

33 lines
923 B
Nix
Raw Normal View History

2024-04-14 06:44:00 +03:00
{ pkgs, secret, lib, ... }: let
keyPath = "/root/.nixbuilder";
2024-03-10 07:54:10 +03:00
in {
systemd.services.generate-nix-cache-key = {
wantedBy = [ "multi-user.target" ];
serviceConfig.Type = "oneshot";
path = [ pkgs.nix ];
script = ''
[[ -f "${keyPath}/private-key" ]] && exit
mkdir ${keyPath} || true
2024-04-14 06:44:00 +03:00
nix-store --generate-binary-cache-key "nixbuilder-1" "${keyPath}/private-key" "${keyPath}/public-key"
2024-03-10 08:00:13 +03:00
nix store sign --all -k "${keyPath}/private-key"
2024-03-10 07:54:10 +03:00
'';
};
2024-04-14 06:44:00 +03:00
users.groups.nixbuilder = {};
users.users.nixbuilder = {
openssh.authorizedKeys.keys = secret.ssh.builderKeys;
description = "Nix Remote Builder";
isNormalUser = true;
createHome = lib.mkForce false;
uid = 1234;
home = "/";
group = "nixbuilder";
};
2024-03-10 06:46:02 +03:00
# To apply: nix store sign --all -k /path/to/secret-key-file
2024-03-09 18:38:41 +03:00
nix.extraOptions = ''
2024-04-14 06:44:00 +03:00
trusted-users = nixbuilder
2024-03-10 08:00:13 +03:00
secret-key-files = ${keyPath}/private-key
2024-03-09 18:38:41 +03:00
'';
}