fn: Improve readability of fn.lst function arguments.

This commit is contained in:
Kevin Baensch 2024-11-30 21:08:01 +01:00
parent b6b22c2c22
commit c1c5ff299e
Signed by: derped
GPG key ID: C0F1D326C7626543
4 changed files with 32 additions and 31 deletions

View file

@ -35,25 +35,25 @@
fn = import ./fn.nix { inherit lib; }; fn = import ./fn.nix { inherit lib; };
pkgs = nixpkgs.legacyPackages."${system}"; pkgs = nixpkgs.legacyPackages."${system}";
machineList = fn.lst { machineList = fn.lst {
p = toString ./machines; path = toString ./machines;
t = "directory"; fileType = "directory";
b = false; fullPath = false;
}; };
nixosSystemFor = machine: { nixosSystemFor = machine: {
name = machine; name = machine;
value = value =
let let
configFiles = fn.lst { configFiles = fn.lst {
p = toString ./config; path = toString ./config;
b = true; fullPath = true;
}; };
pkgsFiles = fn.lst { pkgsFiles = fn.lst {
p = toString ./pkgs; path = toString ./pkgs;
b = true; fullPath = true;
}; };
serviceFiles = fn.lst { serviceFiles = fn.lst {
p = toString ./services; path = toString ./services;
b = true; fullPath = true;
}; };
machinePath = lib.concatStringsSep "/" [ machinePath = lib.concatStringsSep "/" [
(toString ./.) (toString ./.)
@ -62,8 +62,8 @@
]; ];
machineFiles = lib.filter (lib.strings.hasSuffix ".nix") ( machineFiles = lib.filter (lib.strings.hasSuffix ".nix") (
fn.lst { fn.lst {
p = machinePath; path = machinePath;
b = true; fullPath = true;
} }
); );
in in

32
fn.nix
View file

@ -32,31 +32,33 @@ rec {
*/ */
cwd = builtins.getEnv "PWD"; cwd = builtins.getEnv "PWD";
# lst (string PATH) (string FILETYPE) (bool RETURNFULLPATH) /**
lst (string PATH) (string FILETYPE) (bool RETURNFULLPATH)
*/
lst = lst =
{ {
p ? cwd, path ? cwd,
t ? "regular", fileType ? "regular",
b ? false, fullPath ? false,
}: }:
(lists.forEach (attrNames (filterAttrs (n: v: v == t) (readDir p))) ( assert (builtins.isString path) || throw "Argument path needs to be a string.";
v: ((optionalString b "${p}/") + v) (lists.forEach (attrNames (filterAttrs (n: v: v == fileType) (readDir path))) (
v: ((optionalString fullPath "${path}/") + v)
)); ));
lsf = p: (lst { inherit p; }); lsf = path: (lst { inherit path; });
lsd = lsd =
p: path:
(lst { (lst {
inherit p; inherit path;
t = "directory"; fileType = "directory";
b = true; fullPath = true;
}); });
lsfRec = lsfRec =
p: b: path: fullPath:
flatten ( flatten (
(map (np: lsfRec np b) (lsd p)) (map (nextPath: lsfRec nextPath fullPath) (lsd path))
++ (lst { ++ (lst {
inherit p; inherit path fullPath;
inherit b;
}) })
); );
hasAttrs = aList: d: (map (a: (ifelse (isList a) (hasAttrByPath a d) (hasAttr a d))) aList); hasAttrs = aList: d: (map (a: (ifelse (isList a) (hasAttrByPath a d) (hasAttr a d))) aList);

View file

@ -2,15 +2,14 @@
config, config,
lib, lib,
fn, fn,
pkgs,
... ...
}: }:
with lib; with lib;
let let
cfg = config.machine; cfg = config.machine;
pkgsets = fn.lst { pkgsets = fn.lst {
p = toString ../pkgsets; path = toString ../pkgsets;
b = true; fullPath = true;
}; };
in in
{ {

View file

@ -9,8 +9,8 @@ with lib;
let let
cfg = config.machine; cfg = config.machine;
desktopFiles = fn.lst { desktopFiles = fn.lst {
p = toString ./desktop; path = toString ./desktop;
b = true; fullPath = true;
}; };
in in
{ {