summaryrefslogtreecommitdiff
path: root/system-profiles/build-server/default.nix
blob: 9c821f64aef422c1643ead57596f3003d8eec643 (plain)
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
{ customUtils, flake, config, lib, ... }:

{
  imports = with flake.nixosModules.systemProfiles; [ openssh ];
  
  config = {
    users.groups.nix-ssh-builder = {};
    users.users.nix-ssh-builder = {
      description = "Nix build server user";
      useDefaultShell = true;
      isSystemUser = true;
      group = "nix-ssh-builder";
    };

    services.openssh = {
      enable = true;
      extraConfig = ''
        Match User nix-ssh-builder
          AllowAgentForwarding no
          AllowTcpForwarding no
          PermitTTY no
          PermitTunnel no
          X11Forwarding no
          ForceCommand ${config.nix.package.out}/bin/nix-store --serve --write
        Match All
      '';
    };

    users.users.nix-ssh-builder.openssh.authorizedKeys.keys =
      let
        importKeys = dir: lib.attrValues (customUtils.mapFilterAttrs (_: v: v == "directory") (n: _: lib.nameValuePair n (importKeys' dir n)) (builtins.readDir dir));
        importKeys' = dir: host: builtins.readFile (dir + "/${host}/public");
      in importKeys ./clients;
  };
}