Refactor unit option declarations

This gets rid of some duplication.
This commit is contained in:
Eelco Dolstra 2014-04-17 23:35:05 +02:00
parent 2ad6933a22
commit 073351a5cf
2 changed files with 42 additions and 51 deletions

View File

@ -28,7 +28,7 @@ let
in rec { in rec {
unitOptions = { sharedOptions = {
enable = mkOption { enable = mkOption {
default = true; 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 { description = mkOption {
default = ""; default = "";
type = types.str; 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 { unitConfig = mkOption {
default = {}; default = {};
example = { RequiresMountsFor = "/data"; }; example = { RequiresMountsFor = "/data"; };
@ -146,7 +165,7 @@ in rec {
}; };
serviceOptions = unitOptions // { serviceOptions = commonUnitOptions // {
environment = mkOption { environment = mkOption {
default = {}; default = {};
@ -280,7 +299,7 @@ in rec {
}; };
socketOptions = unitOptions // { socketOptions = commonUnitOptions // {
listenStreams = mkOption { listenStreams = mkOption {
default = []; default = [];
@ -307,7 +326,7 @@ in rec {
}; };
timerOptions = unitOptions // { timerOptions = commonUnitOptions // {
timerConfig = mkOption { timerConfig = mkOption {
default = {}; default = {};
@ -326,7 +345,7 @@ in rec {
}; };
pathOptions = unitOptions // { pathOptions = commonUnitOptions // {
pathConfig = mkOption { pathConfig = mkOption {
default = {}; default = {};
@ -343,7 +362,7 @@ in rec {
}; };
mountOptions = unitOptions // { mountOptions = commonUnitOptions // {
what = mkOption { what = mkOption {
example = "/dev/sda1"; example = "/dev/sda1";
@ -387,7 +406,7 @@ in rec {
}; };
}; };
automountOptions = unitOptions // { automountOptions = commonUnitOptions // {
where = mkOption { where = mkOption {
example = "/mnt"; example = "/mnt";
@ -411,4 +430,6 @@ in rec {
}; };
}; };
targetOptions = commonUnitOptions;
} }

View File

@ -456,37 +456,7 @@ in
default = {}; default = {};
type = types.attrsOf types.optionSet; type = types.attrsOf types.optionSet;
options = { name, config, ... }: options = { name, config, ... }:
{ options = { { options = concreteUnitOptions;
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.";
};
};
config = { config = {
unit = mkDefault (makeUnit name config); unit = mkDefault (makeUnit name config);
}; };
@ -502,7 +472,7 @@ in
systemd.targets = mkOption { systemd.targets = mkOption {
default = {}; default = {};
type = types.attrsOf types.optionSet; type = types.attrsOf types.optionSet;
options = [ unitOptions unitConfig ]; options = [ targetOptions unitConfig ];
description = "Definition of systemd target units."; description = "Definition of systemd target units.";
}; };