From ca7805be9470d70ef1a9b2193e5db0237893acf8 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sat, 18 Jan 2014 11:10:39 -0500 Subject: [PATCH] systemd: Enable specifying extra config files for a unit This will allow overriding package-provided units, or overriding only a specific instance of a unit template. Signed-off-by: Shea Levy --- nixos/modules/system/boot/systemd.nix | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index b12031d24adc..b575deb24b7b 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -11,16 +11,19 @@ let systemd = cfg.package; makeUnit = name: unit: - pkgs.runCommand "unit" ({ preferLocalBuild = true; } // optionalAttrs (unit.linkTarget == null) { inherit (unit) text; }) - (if !unit.enable then '' + pkgs.runCommand "unit" { preferLocalBuild = true; inherit (unit) text; } + ((if !unit.enable then '' mkdir -p $out ln -s /dev/null $out/${name} '' else if unit.linkTarget != null then '' mkdir -p $out ln -s ${unit.linkTarget} $out/${name} - '' else '' + '' else if unit.text != null then '' mkdir -p $out echo -n "$text" > $out/${name} + '' else "") + optionalString (unit.extraConfig != {}) '' + mkdir -p $out/${name}.d + ${concatStringsSep "\n" (mapAttrsToList (n: v: "echo -n \"${v}\" > $out/${name}.d/${n}") unit.extraConfig)} ''); upstreamUnits = @@ -392,7 +395,8 @@ in options = { name, config, ... }: { options = { text = mkOption { - type = types.str; + type = types.nullOr types.str; + default = null; description = "Text of this systemd unit."; }; enable = mkOption { @@ -424,6 +428,17 @@ in description = "The file to symlink this target to."; type = types.nullOr types.path; }; + extraConfig = mkOption { + default = {}; + example = { "foo@1.conf" = "X-RestartIfChanged=false"; }; + type = types.attrsOf types.lines; + description = '' + Extra files to be appended to the configuration for the unit. + This can be used to override configuration for a unit provided + by systemd or another package, or to override only a single instance + of a template unit. + ''; + }; }; config = { unit = makeUnit name config;