32 lines
852 B
Nix
32 lines
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;
|
||
|
};
|
||
|
};
|
||
|
}
|