2024-05-04 23:15:57 +03:00
|
|
|
# Collection of common functions.
|
2024-05-12 02:40:37 +03:00
|
|
|
{ pkgs, lib, ... }: rec {
|
2024-04-06 03:03:58 +03:00
|
|
|
# Remove tabs indentation,
|
|
|
|
trimTabs = text: let
|
|
|
|
shouldStripTab = lines: builtins.all (line: (line == "") || (pkgs.lib.strings.hasPrefix " " line)) lines;
|
|
|
|
stripTab = lines: builtins.map (line: pkgs.lib.strings.removePrefix " " line) lines;
|
|
|
|
stripTabs = lines: if (shouldStripTab lines) then (stripTabs (stripTab lines)) else lines;
|
|
|
|
in
|
|
|
|
builtins.concatStringsSep "\n" (stripTabs (pkgs.lib.strings.splitString "\n" text));
|
|
|
|
|
|
|
|
# List all files in a dir.
|
|
|
|
ls = path: map (f: "${path}/${f}") (builtins.attrNames (builtins.readDir path));
|
2024-04-28 21:24:49 +03:00
|
|
|
|
|
|
|
# Concat all files by `text` key.
|
2024-05-08 18:26:33 +03:00
|
|
|
catText = files: args: builtins.foldl' (acc: mod:
|
2024-04-30 20:36:50 +03:00
|
|
|
acc + trimTabs ((import mod args).text)
|
2024-05-08 18:26:33 +03:00
|
|
|
) "" files;
|
2024-05-10 20:34:15 +03:00
|
|
|
|
2024-05-12 02:40:37 +03:00
|
|
|
# Concat all files as a set.
|
|
|
|
catSet = files: args: lib.mkMerge (map (file: import file args) files);
|
|
|
|
|
2024-05-10 20:34:15 +03:00
|
|
|
# Systemd service that does not restart with system switch.
|
|
|
|
mkStaticSystemdService = params: params // {
|
|
|
|
restartIfChanged = false;
|
|
|
|
stopIfChanged = false;
|
|
|
|
unitConfig.X-StopOnRemoval = false;
|
|
|
|
};
|
2024-04-06 03:03:58 +03:00
|
|
|
}
|