ssh-cert-dist/modules/home-manager.nix
2022-12-24 17:17:20 +01:00

35 lines
1.0 KiB
Nix

{ config, pkgs, lib, ... }: with lib; let
cfg = config.services.ssh-cert-dist;
in
{
imports = [
./options.nix
];
config.systemd.user.services = mkIf cfg.enable (mapAttrs'
(path: options: {
inherit (options) name; value = {
Unit.Description = "ssh-cert-dist service for ${path}";
Service = {
Environment = "RUST_LOG=debug";
ExecStart = toString (pkgs.writeShellApplication {
name = "ssh-cert-dist-${options.name}";
runtimeInputs = [ cfg.package ];
text = ''
${optionalString options.fetch ''
ssh-cert-dist fetch --cert-dir '${path}' --api-endpoint '${cfg.endpoint}'
''}
${optionalString options.upload ''
ssh-cert-dist upload --api-endpoint '${cfg.endpoint}' ${path}/*
''}
'';
});
};
};
})
cfg.directories);
config.home.sessionVariables = mkIf (cfg.enable && cfg.endpoint != null) {
SSH_CD_API = cfg.endpoint;
};
config.home.packages = mkIf cfg.enable [ cfg.package ];
}