From 9d405a632461ee6ac367cdde8c8a25d5ee76bc23 Mon Sep 17 00:00:00 2001 From: shimun Date: Mon, 10 Jul 2023 08:44:11 +0200 Subject: [PATCH] feat(home-manager): create timer unit --- modules/home-manager.nix | 18 +++++++++++++++--- modules/options.nix | 5 +++++ 2 files changed, 20 insertions(+), 3 deletions(-) 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 {