Refactor unit option declarations
This gets rid of some duplication.
This commit is contained in:
parent
2ad6933a22
commit
073351a5cf
|
@ -28,7 +28,7 @@ let
|
|||
|
||||
in rec {
|
||||
|
||||
unitOptions = {
|
||||
sharedOptions = {
|
||||
|
||||
enable = mkOption {
|
||||
default = true;
|
||||
|
@ -41,6 +41,37 @@ in rec {
|
|||
'';
|
||||
};
|
||||
|
||||
requiredBy = mkOption {
|
||||
default = [];
|
||||
type = types.listOf types.string;
|
||||
description = "Units that require (i.e. depend on and need to go down with) this unit.";
|
||||
};
|
||||
|
||||
wantedBy = mkOption {
|
||||
default = [];
|
||||
type = types.listOf types.string;
|
||||
description = "Units that want (i.e. depend on) this unit.";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
concreteUnitOptions = sharedOptions // {
|
||||
|
||||
text = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = "Text of this systemd unit.";
|
||||
};
|
||||
|
||||
unit = mkOption {
|
||||
internal = true;
|
||||
description = "The generated unit.";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
commonUnitOptions = sharedOptions // {
|
||||
|
||||
description = mkOption {
|
||||
default = "";
|
||||
type = types.str;
|
||||
|
@ -109,18 +140,6 @@ in rec {
|
|||
'';
|
||||
};
|
||||
|
||||
requiredBy = mkOption {
|
||||
default = [];
|
||||
type = types.listOf types.str;
|
||||
description = "Units that require (i.e. depend on and need to go down with) this unit.";
|
||||
};
|
||||
|
||||
wantedBy = mkOption {
|
||||
default = [];
|
||||
type = types.listOf types.str;
|
||||
description = "Units that want (i.e. depend on) this unit.";
|
||||
};
|
||||
|
||||
unitConfig = mkOption {
|
||||
default = {};
|
||||
example = { RequiresMountsFor = "/data"; };
|
||||
|
@ -146,7 +165,7 @@ in rec {
|
|||
};
|
||||
|
||||
|
||||
serviceOptions = unitOptions // {
|
||||
serviceOptions = commonUnitOptions // {
|
||||
|
||||
environment = mkOption {
|
||||
default = {};
|
||||
|
@ -280,7 +299,7 @@ in rec {
|
|||
};
|
||||
|
||||
|
||||
socketOptions = unitOptions // {
|
||||
socketOptions = commonUnitOptions // {
|
||||
|
||||
listenStreams = mkOption {
|
||||
default = [];
|
||||
|
@ -307,7 +326,7 @@ in rec {
|
|||
};
|
||||
|
||||
|
||||
timerOptions = unitOptions // {
|
||||
timerOptions = commonUnitOptions // {
|
||||
|
||||
timerConfig = mkOption {
|
||||
default = {};
|
||||
|
@ -326,7 +345,7 @@ in rec {
|
|||
};
|
||||
|
||||
|
||||
pathOptions = unitOptions // {
|
||||
pathOptions = commonUnitOptions // {
|
||||
|
||||
pathConfig = mkOption {
|
||||
default = {};
|
||||
|
@ -343,7 +362,7 @@ in rec {
|
|||
};
|
||||
|
||||
|
||||
mountOptions = unitOptions // {
|
||||
mountOptions = commonUnitOptions // {
|
||||
|
||||
what = mkOption {
|
||||
example = "/dev/sda1";
|
||||
|
@ -387,7 +406,7 @@ in rec {
|
|||
};
|
||||
};
|
||||
|
||||
automountOptions = unitOptions // {
|
||||
automountOptions = commonUnitOptions // {
|
||||
|
||||
where = mkOption {
|
||||
example = "/mnt";
|
||||
|
@ -411,4 +430,6 @@ in rec {
|
|||
};
|
||||
};
|
||||
|
||||
targetOptions = commonUnitOptions;
|
||||
|
||||
}
|
||||
|
|
|
@ -456,37 +456,7 @@ in
|
|||
default = {};
|
||||
type = types.attrsOf types.optionSet;
|
||||
options = { name, config, ... }:
|
||||
{ options = {
|
||||
text = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = "Text of this systemd unit.";
|
||||
};
|
||||
enable = mkOption {
|
||||
default = true;
|
||||
type = types.bool;
|
||||
description = ''
|
||||
If set to false, this unit will be a symlink to
|
||||
/dev/null. This is primarily useful to prevent specific
|
||||
template instances (e.g. <literal>serial-getty@ttyS0</literal>)
|
||||
from being started.
|
||||
'';
|
||||
};
|
||||
requiredBy = mkOption {
|
||||
default = [];
|
||||
type = types.listOf types.string;
|
||||
description = "Units that require (i.e. depend on and need to go down with) this unit.";
|
||||
};
|
||||
wantedBy = mkOption {
|
||||
default = [];
|
||||
type = types.listOf types.string;
|
||||
description = "Units that want (i.e. depend on) this unit.";
|
||||
};
|
||||
unit = mkOption {
|
||||
internal = true;
|
||||
description = "The generated unit.";
|
||||
};
|
||||
};
|
||||
{ options = concreteUnitOptions;
|
||||
config = {
|
||||
unit = mkDefault (makeUnit name config);
|
||||
};
|
||||
|
@ -502,7 +472,7 @@ in
|
|||
systemd.targets = mkOption {
|
||||
default = {};
|
||||
type = types.attrsOf types.optionSet;
|
||||
options = [ unitOptions unitConfig ];
|
||||
options = [ targetOptions unitConfig ];
|
||||
description = "Definition of systemd target units.";
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue