diff options
| author | Quentin Aristote <quentin@aristote.fr> | 2022-09-25 14:11:36 +0200 |
|---|---|---|
| committer | Quentin Aristote <quentin@aristote.fr> | 2022-09-25 14:11:36 +0200 |
| commit | 6b7c3879c75f41469edc6897a9dfabf5f0ae17d9 (patch) | |
| tree | 34c72a75bc051ab0b0a791c64282f9d4907151df /home | |
| parent | 97c1db512c252e5dc82ad8092973fa591ff813f6 (diff) | |
home: systemd: refactor services with a timer
Diffstat (limited to 'home')
| -rw-r--r-- | home/config/emacs.nix | 32 | ||||
| -rw-r--r-- | home/pkgs/lib/default.nix | 11 |
2 files changed, 22 insertions, 21 deletions
diff --git a/home/config/emacs.nix b/home/config/emacs.nix index abb45a4..f39086b 100644 --- a/home/config/emacs.nix +++ b/home/config/emacs.nix @@ -1,6 +1,11 @@ { config, lib, pkgs, ... }: -let cfg = config.programs.emacs; +let + cfg = config.programs.emacs; + spacemacs-update-script = pkgs.writeShellScript "spacemacs-update" '' + ${pkgs.git}/bin/git pull + ${cfg.package}/bin/emacsclient --eval '(configuration-layer/update-packages)' + ''; in { programs.emacs = { enable = true; @@ -13,36 +18,21 @@ in { home.file.".spacemacs.d/init.el".source = ./dotfiles/spacemacs; - systemd.user = lib.mkIf cfg.enable { - services.update-spacemacs = { + systemd.user = lib.mkIf cfg.enable + (pkgs.personal.lib.serviceWithTimer "spacemacs-update" { Unit = { Description = "Update Spacemacs by pulling the develop branch"; After = [ "network-online.target" ]; - X-RestartIfChanged = true; }; - Service = { Type = "oneshot"; WorkingDirectory = "${config.home.homeDirectory}/.emacs.d/"; - ExecStart = - "${pkgs.git}/bin/git pull ; ${cfg.package}/bin/emacsclient --eval '(configuration-layer/update-packages)'"; - }; - - Install.WantedBy = [ "default.target" ]; - }; - timers.update-spacemacs = { - Unit = { - Description = "Run Spacemacs update periodically"; - After = [ "network-online.target" ]; + ExecStart = "${spacemacs-update-script}"; }; - Timer = { - Unit = "update-spacemacs.service"; Persistent = true; OnCalendar = "daily"; }; - - Install.WantedBy = [ "default.target" ]; - }; - }; + Install = { WantedBy = [ "default.target" ]; }; + }); } diff --git a/home/pkgs/lib/default.nix b/home/pkgs/lib/default.nix new file mode 100644 index 0000000..55e6c20 --- /dev/null +++ b/home/pkgs/lib/default.nix @@ -0,0 +1,11 @@ +{ pkgs }: + +{ + serviceWithTimer = name: { Unit, Service, Timer, Install, ... }@config: { + services.${name} = { inherit (config) Unit Install Service; }; + timers.${name} = { + inherit (config) Unit Install; + Timer = config.Timer // { Unit = "${name}.service"; }; + }; + }; +} |
