From 27dd65fc95a91155367acbe15754dc22c8869552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 13 Sep 2021 01:00:43 +0200 Subject: Add filesWatcher flake --- modules/default.nix | 3 ++- modules/filesWatcher.nix | 61 ------------------------------------------------ 2 files changed, 2 insertions(+), 62 deletions(-) delete mode 100644 modules/filesWatcher.nix (limited to 'modules') 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 @@ let flakeCompat = import ../lib/flake-compat.nix; + flakeLib = (flakeCompat ../flakes/lib).lib; in { myids = (flakeCompat ../flakes/myuids).nixosModule; secrets = ./secrets.nix; - filesWatcher = ./filesWatcher.nix; + filesWatcher = flakeLib.withNarKeyCompat flakeCompat ../flakes/files-watcher "nixosModule"; webstats = ./webapps/webstats; 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 @@ -{ lib, config, pkgs, ... }: -with lib; -let - cfg = config.services.filesWatcher; -in -{ - options = { - services.filesWatcher = with types; mkOption { - default = {}; - description = '' - Files to watch and trigger service reload or restart of service - when changed. - ''; - type = attrsOf (submodule { - options = { - restart = mkEnableOption "Restart service rather than reloading it"; - paths = mkOption { - type = listOf str; - description = '' - Paths to watch that should trigger a reload of the - service - ''; - }; - waitTime = mkOption { - type = int; - default = 5; - description = '' - Time to wait before reloading/restarting the service. - Set 0 to not wait. - ''; - }; - }; - }); - }; - }; - - config.systemd.services = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair - "${name}Watcher" { - description = "${name} reloader"; - after = [ "network.target" ]; - script = let - action = if icfg.restart then "restart" else "reload"; - in '' - # Service may be stopped during file modification (e.g. activationScripts) - if ${pkgs.systemd}/bin/systemctl --quiet is-active ${name}.service; then - ${pkgs.coreutils}/bin/sleep ${toString icfg.waitTime} - ${pkgs.systemd}/bin/systemctl ${action} ${name}.service - fi - ''; - serviceConfig = { - Type = "oneshot"; - }; - } - ) cfg; - config.systemd.paths = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair - "${name}Watcher" { - wantedBy = [ "multi-user.target" ]; - pathConfig.PathChanged = icfg.paths; - } - ) cfg; -} -- cgit v1.2.3