diff --git a/modules/system/boot/systemd-unit-options.nix b/modules/system/boot/systemd-unit-options.nix index 46f2a705df8c..2efea2fb9e12 100644 --- a/modules/system/boot/systemd-unit-options.nix +++ b/modules/system/boot/systemd-unit-options.nix @@ -145,6 +145,15 @@ rec { ''; }; + postStop = mkOption { + type = types.string; + default = ""; + description = '' + Shell commands executed after the service's main process + has exited. + ''; + }; + restartIfChanged = mkOption { type = types.bool; default = true; diff --git a/modules/system/boot/systemd.nix b/modules/system/boot/systemd.nix index 268e81b10910..c166c1cbf031 100644 --- a/modules/system/boot/systemd.nix +++ b/modules/system/boot/systemd.nix @@ -250,6 +250,13 @@ let ''} ''} + ${optionalString (def.postStop != "") '' + ExecStopPost=${makeJobScript "${name}-poststop.sh" '' + #! ${pkgs.stdenv.shell} -e + ${def.postStop} + ''} + ''} + ${attrsToSection def.serviceConfig} ''; };