2014-02-20 17:34:54 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
2014-07-25 09:54:00 +01:00
|
|
|
with lib;
|
2018-02-28 21:55:00 +00:00
|
|
|
let cfg = config.nix.sshServe;
|
|
|
|
command =
|
|
|
|
if cfg.protocol == "ssh"
|
|
|
|
then "nix-store --serve"
|
|
|
|
else "nix-daemon --stdio";
|
|
|
|
in {
|
2014-02-20 17:34:54 +00:00
|
|
|
options = {
|
2014-07-25 10:00:32 +01:00
|
|
|
|
2014-02-20 17:34:54 +00:00
|
|
|
nix.sshServe = {
|
2014-07-25 10:00:32 +01:00
|
|
|
|
2014-02-20 17:34:54 +00:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
2014-07-25 10:00:32 +01:00
|
|
|
default = false;
|
2018-02-28 21:55:00 +00:00
|
|
|
description = "Whether to enable serving the Nix store as a remote store via SSH.";
|
2014-02-20 17:34:54 +00:00
|
|
|
};
|
2014-07-25 10:00:32 +01: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.";
|
|
|
|
};
|
|
|
|
|
2018-02-28 21:55:00 +00:00
|
|
|
protocol = mkOption {
|
|
|
|
type = types.enum [ "ssh" "ssh-ng" ];
|
|
|
|
default = "ssh";
|
|
|
|
description = "The specific Nix-over-SSH protocol to use.";
|
|
|
|
};
|
|
|
|
|
2014-02-20 17:34:54 +00:00
|
|
|
};
|
2014-07-25 10:00:32 +01:00
|
|
|
|
2014-02-20 17:34:54 +00:00
|
|
|
};
|
|
|
|
|
2018-02-28 21:55:00 +00:00
|
|
|
config = mkIf cfg.enable {
|
2014-07-25 10:00:32 +01:00
|
|
|
|
2014-02-20 17:34:54 +00:00
|
|
|
users.extraUsers.nix-ssh = {
|
2018-02-28 21:55:00 +00:00
|
|
|
description = "Nix SSH store user";
|
2014-02-20 17:34:54 +00:00
|
|
|
uid = config.ids.uids.nix-ssh;
|
2014-07-25 12:42:44 +01:00
|
|
|
useDefaultShell = true;
|
2014-02-20 17:34:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.openssh.enable = true;
|
|
|
|
|
|
|
|
services.openssh.extraConfig = ''
|
|
|
|
Match User nix-ssh
|
|
|
|
AllowAgentForwarding no
|
|
|
|
AllowTcpForwarding no
|
|
|
|
PermitTTY no
|
|
|
|
PermitTunnel no
|
|
|
|
X11Forwarding no
|
2018-02-28 21:55:00 +00:00
|
|
|
ForceCommand ${config.nix.package.out}/bin/${command}
|
2014-02-20 17:34:54 +00:00
|
|
|
Match All
|
|
|
|
'';
|
2014-07-25 10:00:32 +01:00
|
|
|
|
2018-02-28 21:55:00 +00:00
|
|
|
users.extraUsers.nix-ssh.openssh.authorizedKeys.keys = cfg.keys;
|
2014-07-25 10:00:32 +01:00
|
|
|
|
2014-02-20 17:34:54 +00:00
|
|
|
};
|
|
|
|
}
|