nix/modules/stuff/ssh.nix

32 lines
852 B
Nix
Raw Normal View History

2024-08-01 21:22:47 +02:00
{ lib, pkgs, config, ...}: let
inherit (lib) elemAt splitString mapAttrs' hasAttr mkIf mkEnableOption mkOption;
cfg = config.chuj.stuff.ssh;
user = config.chuj.system.user;
in {
options.chuj.stuff.ssh = {
enable = mkEnableOption "ssh";
keys = mkOption {
type = lib.types.attrs;
default = {};
};
};
config = mkIf cfg.enable {
services.openssh.enable = true;
home-manager.users.${user}.programs.ssh = {
enable = true;
matchBlocks = mapAttrs'
(host: hostcfg: {
name = elemAt (splitString "@" host) 1;
value = {
user = elemAt (splitString "@" host) 0;
identityFile = "~/.ssh/keys/${hostcfg.file}";
setEnv = if hasAttr "env" hostcfg
then hostcfg.env
else {};
};
}) cfg.keys;
};
};
}