From 14cd8bc24874b33e87ec08ddb6d47502e76f17b0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 26 Nov 2013 18:24:55 +0100 Subject: [PATCH] Allow services to specify a pre-stop script --- nixos/modules/system/boot/systemd-unit-options.nix | 8 ++++++++ nixos/modules/system/boot/systemd.nix | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/nixos/modules/system/boot/systemd-unit-options.nix b/nixos/modules/system/boot/systemd-unit-options.nix index 4eb3f1a43a65..c0518599f17a 100644 --- a/nixos/modules/system/boot/systemd-unit-options.nix +++ b/nixos/modules/system/boot/systemd-unit-options.nix @@ -210,6 +210,14 @@ in rec { ''; }; + preStop = mkOption { + type = types.lines; + default = ""; + description = '' + Shell commands executed to stop the service. + ''; + }; + postStop = mkOption { type = types.lines; default = ""; diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index 31e795ea2d04..51c71c7a5af2 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -190,6 +190,12 @@ let ${config.postStart} ''; }) + (mkIf (config.preStop != "") + { serviceConfig.ExecStop = makeJobScript "${name}-pre-stop" '' + #! ${pkgs.stdenv.shell} -e + ${config.preStop} + ''; + }) (mkIf (config.postStop != "") { serviceConfig.ExecStopPost = makeJobScript "${name}-post-stop" '' #! ${pkgs.stdenv.shell} -e