summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Aristote <quentin@aristote.fr>2022-09-25 14:11:36 +0200
committerQuentin Aristote <quentin@aristote.fr>2022-09-25 14:11:36 +0200
commit6b7c3879c75f41469edc6897a9dfabf5f0ae17d9 (patch)
tree34c72a75bc051ab0b0a791c64282f9d4907151df
parent97c1db512c252e5dc82ad8092973fa591ff813f6 (diff)
home: systemd: refactor services with a timer
-rw-r--r--home/config/emacs.nix32
-rw-r--r--home/pkgs/lib/default.nix11
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"; };
+ };
+ };
+}