nix/part/Util.nix

20 lines
731 B
Nix
Raw Normal View History

2024-04-28 21:24:49 +03:00
{ pkgs, ... }: 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.
catAllText = path: args: trimTabs (
(builtins.foldl' (acc: mod:
acc + (import mod args).text
) "" (ls path))
);
2024-04-06 03:03:58 +03:00
}