2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let cfg = config.nix.sshServe;
|
|
|
|
command =
|
|
|
|
if cfg.protocol == "ssh"
|
2021-09-18 10:52:07 +00:00
|
|
|
then "nix-store --serve ${lib.optionalString cfg.write "--write"}"
|
2020-04-24 23:36:52 +00:00
|
|
|
else "nix-daemon --stdio";
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
|
|
|
|
nix.sshServe = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable serving the Nix store as a remote store via SSH.";
|
|
|
|
};
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
write = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-01-27 00:19:43 +00:00
|
|
|
description = "Whether to enable writing to the Nix store as a remote store via SSH. Note: the sshServe user is named nix-ssh and is not a trusted-user. nix-ssh should be added to the <option>nix.settings.trusted-users</option> option in most use cases, such as allowing remote building of derivations.";
|
2021-09-18 10:52:07 +00:00
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
keys = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "ssh-dss AAAAB3NzaC1k... alice@example.org" ];
|
|
|
|
description = "A list of SSH public keys allowed to access the binary cache via SSH.";
|
|
|
|
};
|
|
|
|
|
|
|
|
protocol = mkOption {
|
|
|
|
type = types.enum [ "ssh" "ssh-ng" ];
|
|
|
|
default = "ssh";
|
|
|
|
description = "The specific Nix-over-SSH protocol to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
users.users.nix-ssh = {
|
|
|
|
description = "Nix SSH store user";
|
2021-09-18 10:52:07 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
group = "nix-ssh";
|
2020-04-24 23:36:52 +00:00
|
|
|
useDefaultShell = true;
|
|
|
|
};
|
2021-09-18 10:52:07 +00:00
|
|
|
users.groups.nix-ssh = {};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
services.openssh.enable = true;
|
|
|
|
|
|
|
|
services.openssh.extraConfig = ''
|
|
|
|
Match User nix-ssh
|
|
|
|
AllowAgentForwarding no
|
|
|
|
AllowTcpForwarding no
|
|
|
|
PermitTTY no
|
|
|
|
PermitTunnel no
|
|
|
|
X11Forwarding no
|
|
|
|
ForceCommand ${config.nix.package.out}/bin/${command}
|
|
|
|
Match All
|
|
|
|
'';
|
|
|
|
|
|
|
|
users.users.nix-ssh.openssh.authorizedKeys.keys = cfg.keys;
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|