diff --git a/flake.nix b/flake.nix index 81be96f..e248f83 100644 --- a/flake.nix +++ b/flake.nix @@ -35,25 +35,25 @@ fn = import ./fn.nix { inherit lib; }; pkgs = nixpkgs.legacyPackages."${system}"; machineList = fn.lst { - p = toString ./machines; - t = "directory"; - b = false; + path = toString ./machines; + fileType = "directory"; + fullPath = false; }; nixosSystemFor = machine: { name = machine; value = let configFiles = fn.lst { - p = toString ./config; - b = true; + path = toString ./config; + fullPath = true; }; pkgsFiles = fn.lst { - p = toString ./pkgs; - b = true; + path = toString ./pkgs; + fullPath = true; }; serviceFiles = fn.lst { - p = toString ./services; - b = true; + path = toString ./services; + fullPath = true; }; machinePath = lib.concatStringsSep "/" [ (toString ./.) @@ -62,8 +62,8 @@ ]; machineFiles = lib.filter (lib.strings.hasSuffix ".nix") ( fn.lst { - p = machinePath; - b = true; + path = machinePath; + fullPath = true; } ); in diff --git a/fn.nix b/fn.nix index d16fa84..48ec761 100644 --- a/fn.nix +++ b/fn.nix @@ -32,31 +32,33 @@ rec { */ cwd = builtins.getEnv "PWD"; - # lst (string PATH) (string FILETYPE) (bool RETURNFULLPATH) + /** + lst (string PATH) (string FILETYPE) (bool RETURNFULLPATH) + */ lst = { - p ? cwd, - t ? "regular", - b ? false, + path ? cwd, + fileType ? "regular", + fullPath ? false, }: - (lists.forEach (attrNames (filterAttrs (n: v: v == t) (readDir p))) ( - v: ((optionalString b "${p}/") + v) + assert (builtins.isString path) || throw "Argument path needs to be a string."; + (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 = - p: + path: (lst { - inherit p; - t = "directory"; - b = true; + inherit path; + fileType = "directory"; + fullPath = true; }); lsfRec = - p: b: + path: fullPath: flatten ( - (map (np: lsfRec np b) (lsd p)) + (map (nextPath: lsfRec nextPath fullPath) (lsd path)) ++ (lst { - inherit p; - inherit b; + inherit path fullPath; }) ); hasAttrs = aList: d: (map (a: (ifelse (isList a) (hasAttrByPath a d) (hasAttr a d))) aList); diff --git a/pkgs/systemPackages.nix b/pkgs/systemPackages.nix index 1578d5d..66df5fd 100644 --- a/pkgs/systemPackages.nix +++ b/pkgs/systemPackages.nix @@ -2,15 +2,14 @@ config, lib, fn, - pkgs, ... }: with lib; let cfg = config.machine; pkgsets = fn.lst { - p = toString ../pkgsets; - b = true; + path = toString ../pkgsets; + fullPath = true; }; in { diff --git a/services/desktop.nix b/services/desktop.nix index 3c22ea9..3f6afec 100644 --- a/services/desktop.nix +++ b/services/desktop.nix @@ -9,8 +9,8 @@ with lib; let cfg = config.machine; desktopFiles = fn.lst { - p = toString ./desktop; - b = true; + path = toString ./desktop; + fullPath = true; }; in {