systemd: minor code cleanup
Trying to make more clear what is happening.
This commit is contained in:
parent
5786e42530
commit
175532b627
1 changed files with 20 additions and 7 deletions
|
|
@ -46,16 +46,29 @@ let
|
|||
filename = "${name}.${style}";
|
||||
pathSafeName = mkPathSafeName filename;
|
||||
|
||||
# Needed because systemd derives unit names from the ultimate
|
||||
# link target.
|
||||
# The actual unit content after filtering.
|
||||
finalUnit =
|
||||
let
|
||||
# Filters out fields that are set to `null` or empty list.
|
||||
shouldKeepField =
|
||||
section: key: value:
|
||||
value != null && value != [ ];
|
||||
|
||||
# Filters out empty sections.
|
||||
shouldKeepSection = _: value: value != { };
|
||||
|
||||
inherit (lib) mapAttrs filterAttrs;
|
||||
|
||||
filteredFields = mapAttrs (section: filterAttrs (shouldKeepField section)) serviceCfg;
|
||||
filteredSections = filterAttrs shouldKeepSection filteredFields;
|
||||
in
|
||||
filteredSections;
|
||||
|
||||
# Needed because systemd derives unit names from the ultimate link target.
|
||||
source =
|
||||
pkgs.writeTextFile {
|
||||
name = pathSafeName;
|
||||
text = toSystemdIni (
|
||||
lib.filterAttrs (_: v: v != { }) (
|
||||
lib.mapAttrs (_: lib.filterAttrs (_: v: v != null && v != [ ])) serviceCfg
|
||||
)
|
||||
);
|
||||
text = toSystemdIni finalUnit;
|
||||
destination = "/${filename}";
|
||||
}
|
||||
+ "/${filename}";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue