aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2021-09-13 01:00:43 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2021-10-15 23:15:02 +0200
commit27dd65fc95a91155367acbe15754dc22c8869552 (patch)
tree73e85423c5b359c87e51749f7791cda61a900315 /modules
parentdef6ad9963ed6f3f81fddea854f2a7b110dd5183 (diff)
downloadNix-27dd65fc95a91155367acbe15754dc22c8869552.tar.gz
Nix-27dd65fc95a91155367acbe15754dc22c8869552.tar.zst
Nix-27dd65fc95a91155367acbe15754dc22c8869552.zip
Add filesWatcher flake
Diffstat (limited to 'modules')
-rw-r--r--modules/default.nix3
-rw-r--r--modules/filesWatcher.nix61
2 files changed, 2 insertions, 62 deletions
diff --git a/modules/default.nix b/modules/default.nix
index 7ce1cc2..5359e9c 100644
--- a/modules/default.nix
+++ b/modules/default.nix
@@ -1,10 +1,11 @@
1let 1let
2 flakeCompat = import ../lib/flake-compat.nix; 2 flakeCompat = import ../lib/flake-compat.nix;
3 flakeLib = (flakeCompat ../flakes/lib).lib;
3in 4in
4{ 5{
5 myids = (flakeCompat ../flakes/myuids).nixosModule; 6 myids = (flakeCompat ../flakes/myuids).nixosModule;
6 secrets = ./secrets.nix; 7 secrets = ./secrets.nix;
7 filesWatcher = ./filesWatcher.nix; 8 filesWatcher = flakeLib.withNarKeyCompat flakeCompat ../flakes/files-watcher "nixosModule";
8 9
9 webstats = ./webapps/webstats; 10 webstats = ./webapps/webstats;
10 diaspora = ./webapps/diaspora.nix; 11 diaspora = ./webapps/diaspora.nix;
diff --git a/modules/filesWatcher.nix b/modules/filesWatcher.nix
deleted file mode 100644
index 4444027..0000000
--- a/modules/filesWatcher.nix
+++ /dev/null
@@ -1,61 +0,0 @@
1{ lib, config, pkgs, ... }:
2with lib;
3let
4 cfg = config.services.filesWatcher;
5in
6{
7 options = {
8 services.filesWatcher = with types; mkOption {
9 default = {};
10 description = ''
11 Files to watch and trigger service reload or restart of service
12 when changed.
13 '';
14 type = attrsOf (submodule {
15 options = {
16 restart = mkEnableOption "Restart service rather than reloading it";
17 paths = mkOption {
18 type = listOf str;
19 description = ''
20 Paths to watch that should trigger a reload of the
21 service
22 '';
23 };
24 waitTime = mkOption {
25 type = int;
26 default = 5;
27 description = ''
28 Time to wait before reloading/restarting the service.
29 Set 0 to not wait.
30 '';
31 };
32 };
33 });
34 };
35 };
36
37 config.systemd.services = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
38 "${name}Watcher" {
39 description = "${name} reloader";
40 after = [ "network.target" ];
41 script = let
42 action = if icfg.restart then "restart" else "reload";
43 in ''
44 # Service may be stopped during file modification (e.g. activationScripts)
45 if ${pkgs.systemd}/bin/systemctl --quiet is-active ${name}.service; then
46 ${pkgs.coreutils}/bin/sleep ${toString icfg.waitTime}
47 ${pkgs.systemd}/bin/systemctl ${action} ${name}.service
48 fi
49 '';
50 serviceConfig = {
51 Type = "oneshot";
52 };
53 }
54 ) cfg;
55 config.systemd.paths = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
56 "${name}Watcher" {
57 wantedBy = [ "multi-user.target" ];
58 pathConfig.PathChanged = icfg.paths;
59 }
60 ) cfg;
61}