Skip to content

Commit

Permalink
systemd-lib: add Install WantedBy section to make units similar to up…
Browse files Browse the repository at this point in the history
…stream ones

and make them better grepable
  • Loading branch information
SuperSandro2000 committed Jan 2, 2024
1 parent 7c19f30 commit 9fbf82d
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions nixos/lib/systemd-lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,13 @@ in rec {
};
};

commonUnitText = def: ''
commonUnitText = def: lines: ''
[Unit]
${attrsToSection def.unitConfig}
'' + lines + lib.optionalString (def.wantedBy != [ ]) ''
[Install]
WantedBy=${concatStringsSep " " def.wantedBy}
'';

targetToUnit = name: def:
Expand All @@ -376,7 +380,7 @@ in rec {

serviceToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def + ''
text = commonUnitText def (''
[Service]
'' + (let env = cfg.globalEnvironment // def.environment;
in concatMapStrings (n:
Expand All @@ -392,45 +396,41 @@ in rec {
'' else "")
+ optionalString (def ? stopIfChanged && !def.stopIfChanged) ''
X-StopIfChanged=false
'' + attrsToSection def.serviceConfig;
'' + attrsToSection def.serviceConfig);
};

socketToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def +
''
[Socket]
${attrsToSection def.socketConfig}
${concatStringsSep "\n" (map (s: "ListenStream=${s}") def.listenStreams)}
${concatStringsSep "\n" (map (s: "ListenDatagram=${s}") def.listenDatagrams)}
'';
text = commonUnitText def ''
[Socket]
${attrsToSection def.socketConfig}
${concatStringsSep "\n" (map (s: "ListenStream=${s}") def.listenStreams)}
${concatStringsSep "\n" (map (s: "ListenDatagram=${s}") def.listenDatagrams)}
'';
};

timerToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def +
''
[Timer]
${attrsToSection def.timerConfig}
'';
text = commonUnitText def ''
[Timer]
${attrsToSection def.timerConfig}
'';
};

pathToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def +
''
[Path]
${attrsToSection def.pathConfig}
'';
text = commonUnitText def ''
[Path]
${attrsToSection def.pathConfig}
'';
};

mountToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def +
''
[Mount]
${attrsToSection def.mountConfig}
'';
text = commonUnitText def ''
[Mount]
${attrsToSection def.mountConfig}
'';
};

automountToUnit = name: def:
Expand All @@ -444,11 +444,10 @@ in rec {

sliceToUnit = name: def:
{ inherit (def) aliases wantedBy requiredBy enable overrideStrategy;
text = commonUnitText def +
''
[Slice]
${attrsToSection def.sliceConfig}
'';
text = commonUnitText def ''
[Slice]
${attrsToSection def.sliceConfig}
'';
};

# Create a directory that contains systemd definition files from an attrset
Expand Down

0 comments on commit 9fbf82d

Please sign in to comment.