mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-14 15:36:47 +03:00
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 <shea@shealevy.com>
This commit is contained in:
parent
84f35a7cc1
commit
ca7805be94
@ -11,16 +11,19 @@ let
|
|||||||
systemd = cfg.package;
|
systemd = cfg.package;
|
||||||
|
|
||||||
makeUnit = name: unit:
|
makeUnit = name: unit:
|
||||||
pkgs.runCommand "unit" ({ preferLocalBuild = true; } // optionalAttrs (unit.linkTarget == null) { inherit (unit) text; })
|
pkgs.runCommand "unit" { preferLocalBuild = true; inherit (unit) text; }
|
||||||
(if !unit.enable then ''
|
((if !unit.enable then ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
ln -s /dev/null $out/${name}
|
ln -s /dev/null $out/${name}
|
||||||
'' else if unit.linkTarget != null then ''
|
'' else if unit.linkTarget != null then ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
ln -s ${unit.linkTarget} $out/${name}
|
ln -s ${unit.linkTarget} $out/${name}
|
||||||
'' else ''
|
'' else if unit.text != null then ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
echo -n "$text" > $out/${name}
|
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 =
|
upstreamUnits =
|
||||||
@ -392,7 +395,8 @@ in
|
|||||||
options = { name, config, ... }:
|
options = { name, config, ... }:
|
||||||
{ options = {
|
{ options = {
|
||||||
text = mkOption {
|
text = mkOption {
|
||||||
type = types.str;
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
description = "Text of this systemd unit.";
|
description = "Text of this systemd unit.";
|
||||||
};
|
};
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
@ -424,6 +428,17 @@ in
|
|||||||
description = "The file to symlink this target to.";
|
description = "The file to symlink this target to.";
|
||||||
type = types.nullOr types.path;
|
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 = {
|
config = {
|
||||||
unit = makeUnit name config;
|
unit = makeUnit name config;
|
||||||
|
Loading…
Reference in New Issue
Block a user