Set up build farm (#3)
Reviewed-on: #3 Co-authored-by: Natsu Kagami <nki@nkagami.me> Co-committed-by: Natsu Kagami <nki@nkagami.me>
This commit is contained in:
parent
70ab3aa5b3
commit
bc4cfe7c69
13 changed files with 162 additions and 25 deletions
66
modules/services/nix-build-farm/default.nix
Normal file
66
modules/services/nix-build-farm/default.nix
Normal file
|
@ -0,0 +1,66 @@
|
|||
{ config, lib, ... }:
|
||||
with { inherit (lib) mkOption types mkIf; };
|
||||
let
|
||||
cfg = config.services.nix-build-farm;
|
||||
hosts = import ./hosts.nix;
|
||||
|
||||
build-user = "nix-builder";
|
||||
|
||||
isBuilder = host: host ? "builder";
|
||||
allBuilders = lib.filterAttrs (_: isBuilder) hosts;
|
||||
in
|
||||
{
|
||||
options.services.nix-build-farm = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Whether to enable nix-build-farm as a client";
|
||||
};
|
||||
hostname = mkOption {
|
||||
type = types.enum (builtins.attrNames hosts);
|
||||
description = "The hostname as listed in ./hosts.nix file";
|
||||
};
|
||||
privateKeyFile = mkOption {
|
||||
type = types.path;
|
||||
description = "The path to the private SSH key file";
|
||||
};
|
||||
|
||||
ipAddrs = mkOption {
|
||||
type = types.str;
|
||||
description = "The ip addresses to limit access to";
|
||||
default = "11.0.0.*";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable (
|
||||
let
|
||||
host = hosts.${cfg.hostname};
|
||||
otherHosts = lib.filterAttrs (name: _: name != cfg.hostname) hosts;
|
||||
otherBuilders = lib.filterAttrs (name: _: name != cfg.hostname) allBuilders;
|
||||
in
|
||||
{
|
||||
nix.distributedBuilds = true;
|
||||
nix.buildMachines = lib.mapAttrsToList
|
||||
(name: host: {
|
||||
hostName = host.host;
|
||||
sshUser = build-user;
|
||||
sshKey = cfg.privateKeyFile;
|
||||
} // host.builder)
|
||||
otherBuilders;
|
||||
|
||||
users = mkIf (isBuilder host) {
|
||||
users.${build-user} = {
|
||||
description = "Nix build farm user";
|
||||
group = build-user;
|
||||
isNormalUser = true;
|
||||
openssh.authorizedKeys.keys = lib.mapAttrsToList (_: host: ''from="${cfg.ipAddrs}" ${host.pubKey}'') otherHosts;
|
||||
};
|
||||
groups.${build-user} = { };
|
||||
};
|
||||
|
||||
nix.settings.trusted-users = mkIf (isBuilder host) [ build-user ];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue