nix-files/hosts/common/home/ssh.nix

27 lines
841 B
Nix
Raw Permalink Normal View History

{ config, lib, sane-lib, ... }:
2023-01-08 03:07:20 +00:00
with lib;
let
host = config.networking.hostName;
2023-03-11 10:00:53 +00:00
user-pubkey-full = config.sane.ssh.pubkeys."colin@${host}" or {};
user-pubkey = user-pubkey-full.asUserKey or null;
2023-01-08 03:07:20 +00:00
host-keys = filter (k: k.user == "root") (attrValues config.sane.ssh.pubkeys);
known-hosts-text = concatStringsSep
"\n"
2023-01-08 03:07:20 +00:00
(map (k: k.asHostKey) host-keys)
;
in
{
# ssh key is stored in private storage
sane.user.persist.private = [ ".ssh/id_ed25519" ];
2023-03-11 10:00:53 +00:00
sane.user.fs.".ssh/id_ed25519.pub" =
mkIf (user-pubkey != null) (sane-lib.fs.wantedText user-pubkey);
2023-01-30 09:27:19 +00:00
sane.user.fs.".ssh/known_hosts" = sane-lib.fs.wantedText known-hosts-text;
users.users.colin.openssh.authorizedKeys.keys =
let
user-keys = filter (k: k.user == "colin") (attrValues config.sane.ssh.pubkeys);
in
map (k: k.asUserKey) user-keys;
}