systemd-lib: add Install WantedBy section to make units similar to upstream ones

and make them better grepable
This commit is contained in:
Sandro Jäckel 2023-11-09 01:59:59 +01:00
parent 7c19f30a07
commit 9fbf82d9cb
No known key found for this signature in database
GPG key ID: 3AF5A43A3EECC2E5

View file

@ -360,9 +360,13 @@ in rec {
}; };
}; };
commonUnitText = def: '' commonUnitText = def: lines: ''
[Unit] [Unit]
${attrsToSection def.unitConfig} ${attrsToSection def.unitConfig}
'' + lines + lib.optionalString (def.wantedBy != [ ]) ''
[Install]
WantedBy=${concatStringsSep " " def.wantedBy}
''; '';
targetToUnit = name: def: targetToUnit = name: def:
@ -376,7 +380,7 @@ in rec {
serviceToUnit = name: def: serviceToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy; { inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def + '' text = commonUnitText def (''
[Service] [Service]
'' + (let env = cfg.globalEnvironment // def.environment; '' + (let env = cfg.globalEnvironment // def.environment;
in concatMapStrings (n: in concatMapStrings (n:
@ -392,13 +396,12 @@ in rec {
'' else "") '' else "")
+ optionalString (def ? stopIfChanged && !def.stopIfChanged) '' + optionalString (def ? stopIfChanged && !def.stopIfChanged) ''
X-StopIfChanged=false X-StopIfChanged=false
'' + attrsToSection def.serviceConfig; '' + attrsToSection def.serviceConfig);
}; };
socketToUnit = name: def: socketToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy; { inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def + text = commonUnitText def ''
''
[Socket] [Socket]
${attrsToSection def.socketConfig} ${attrsToSection def.socketConfig}
${concatStringsSep "\n" (map (s: "ListenStream=${s}") def.listenStreams)} ${concatStringsSep "\n" (map (s: "ListenStream=${s}") def.listenStreams)}
@ -408,8 +411,7 @@ in rec {
timerToUnit = name: def: timerToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy; { inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def + text = commonUnitText def ''
''
[Timer] [Timer]
${attrsToSection def.timerConfig} ${attrsToSection def.timerConfig}
''; '';
@ -417,8 +419,7 @@ in rec {
pathToUnit = name: def: pathToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy; { inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def + text = commonUnitText def ''
''
[Path] [Path]
${attrsToSection def.pathConfig} ${attrsToSection def.pathConfig}
''; '';
@ -426,8 +427,7 @@ in rec {
mountToUnit = name: def: mountToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy; { inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def + text = commonUnitText def ''
''
[Mount] [Mount]
${attrsToSection def.mountConfig} ${attrsToSection def.mountConfig}
''; '';
@ -444,8 +444,7 @@ in rec {
sliceToUnit = name: def: sliceToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy; { inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def + text = commonUnitText def ''
''
[Slice] [Slice]
${attrsToSection def.sliceConfig} ${attrsToSection def.sliceConfig}
''; '';