systemd: minor code cleanup

Trying to make more clear what is happening.
This commit is contained in:
Robert Helgesson 2026-01-29 15:08:59 +01:00
parent 5786e42530
commit 175532b627

View file

@ -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}";