diff --git a/modules/home-manager.nix b/modules/home-manager.nix index f78caa3..a12cd80 100644 --- a/modules/home-manager.nix +++ b/modules/home-manager.nix @@ -11,8 +11,8 @@ in Unit.Description = "ssh-cert-dist service for ${path}"; Service = { Environment = "RUST_LOG=debug"; - ExecStart = toString (pkgs.writeShellApplication { - name = "ssh-cert-dist-${options.name}"; + ExecStart = "${pkgs.writeShellApplication { + name = "sshcd"; runtimeInputs = [ cfg.package ]; text = '' ${optionalString options.fetch '' @@ -22,11 +22,23 @@ in sshcd upload --api-endpoint '${cfg.endpoint}' ${path}/* ''} ''; - }); + }}/bin/sshcd"; }; }; }) cfg.directories); + config.systemd.user.timers = mkIf cfg.enable (mapAttrs' + (path: options: { + inherit (options) name; value = { + Unit.Description = "ssh-cert-dist service for ${path}"; + Timer = { + OnCalendar = options.interval; + Unit = "${options.name}.service"; + }; + Install.WantedBy = [ "timers.target" ]; + }; + }) + cfg.directories); config.home.sessionVariables = mkIf (cfg.enable && cfg.endpoint != null) { SSH_CD_API = cfg.endpoint; }; diff --git a/modules/options.nix b/modules/options.nix index 3fb8884..e938d81 100644 --- a/modules/options.nix +++ b/modules/options.nix @@ -13,6 +13,11 @@ type = types.bool; default = false; }; + interval = mkOption { + type = types.str; + default = "daily"; + description = "https://www.freedesktop.org/software/systemd/man/systemd.time.html"; + }; }; }; endpointOption = mkOption {