nix/modules/stuff/ssh.nix

32 lines
No EOL
852 B
Nix

{ 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;
};
};
}