# modules/home/ssh.nix — the SSH key and client config, from the flake. # # The private key is a sops secret (secrets/secrets.yaml: ssh_id_ed25519; # `nix-cheat secrets`). At login sops-nix decrypts it with the age key into # the runtime secrets dir and ~/.config/sops-nix/secrets/ssh_id_ed25519 points # there; ~/.ssh/config names that path, so a fresh machine has a working key # as soon as ~/.config/sops/age/keys.txt is restored. The public half is # plain text in ~/.ssh/id_ed25519.pub (comment daemonsec@nixos; registered on # gitlab.com as "nixos", auth and signing, and glab's git_protocol is ssh). # # A plain copy from before this module may still sit at ~/.ssh/id_ed25519; # nothing reads it any more. # # The agent: services.gnome.gnome-keyring.enable (configuration.nix, and # mkDefault in workstation.nix) makes gcr-ssh-agent the $SSH_AUTH_SOCK # (/run/user/1000/gcr/ssh). It is not gpg-agent and not plain ssh-agent, and # it refuses signing requests when it cannot prompt. ssh prefers an agent that # holds the key over reading the file, so that refusal is fatal even though # the key is readable. Hence IdentityAgent = "none" below, and no # AddKeysToAgent. Verified: with the agent, `ssh -T git@gitlab.com` fails; # with SSH_AUTH_SOCK unset it prints "Welcome to GitLab, @DAEMON-404!". { ... }: { flake.homeModules.ssh = { config, ... }: let key = config.sops.secrets.ssh_id_ed25519.path; in { sops.secrets.ssh_id_ed25519 = { }; home.file.".ssh/id_ed25519.pub".text = '' ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB8ExB6Gv5T7DwwVeNqVmzbwCcZ/ULuKL2pAXS7zg4NR daemonsec@nixos ''; programs.ssh = { enable = true; enableDefaultConfig = false; settings = { "gitlab.com" = { User = "git"; IdentityFile = key; IdentitiesOnly = "yes"; IdentityAgent = "none"; }; "github.com" = { User = "git"; IdentityFile = key; IdentitiesOnly = "yes"; IdentityAgent = "none"; }; "gitea.com" = { User = "git"; IdentityFile = key; IdentitiesOnly = "yes"; IdentityAgent = "none"; }; "codeberg.org" = { User = "git"; IdentityFile = key; IdentitiesOnly = "yes"; IdentityAgent = "none"; }; "*" = { IdentityFile = key; ServerAliveInterval = 30; HashKnownHosts = "no"; }; }; }; } ; }