1 { config, lib, pkgs, ... }:
2 let cfg = config.nix.sshServe;
4 if cfg.protocol == "ssh"
5 then "nix-store --serve ${lib.optionalString cfg.write "--write"}"
6 else "nix-daemon --stdio";
12 enable = lib.mkOption {
13 type = lib.types.bool;
15 description = "Whether to enable serving the Nix store as a remote store via SSH.";
18 write = lib.mkOption {
19 type = lib.types.bool;
21 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 in most use cases, such as allowing remote building of derivations.";
25 type = lib.types.listOf lib.types.str;
27 example = [ "ssh-dss AAAAB3NzaC1k... alice@example.org" ];
28 description = "A list of SSH public keys allowed to access the binary cache via SSH.";
31 protocol = lib.mkOption {
32 type = lib.types.enum [ "ssh" "ssh-ng" ];
34 description = "The specific Nix-over-SSH protocol to use.";
41 config = lib.mkIf cfg.enable {
43 users.users.nix-ssh = {
44 description = "Nix SSH store user";
47 shell = pkgs.bashInteractive;
49 users.groups.nix-ssh = {};
51 services.openssh.enable = true;
53 services.openssh.extraConfig = ''
55 AllowAgentForwarding no
60 ForceCommand ${config.nix.package.out}/bin/${command}
64 users.users.nix-ssh.openssh.authorizedKeys.keys = cfg.keys;