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,45 +396,41 @@ 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)} ${concatStringsSep "\n" (map (s: "ListenDatagram=${s}") def.listenDatagrams)}
${concatStringsSep "\n" (map (s: "ListenDatagram=${s}") def.listenDatagrams)} '';
'';
}; };
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} '';
'';
}; };
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} '';
'';
}; };
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} '';
'';
}; };
automountToUnit = name: def: automountToUnit = name: def:
@ -444,11 +444,10 @@ 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} '';
'';
}; };
# Create a directory that contains systemd definition files from an attrset # Create a directory that contains systemd definition files from an attrset