refactor
This commit is contained in:
parent
dbd88aea66
commit
8fbd9d06b4
29 changed files with 130 additions and 101 deletions
40
lib.nix
40
lib.nix
|
|
@ -1,23 +1,33 @@
|
|||
{ lib, ... }:
|
||||
rec {
|
||||
# TODO make a version that only includes nix paths.
|
||||
walk-dir =
|
||||
path:
|
||||
let
|
||||
dir = builtins.readDir path;
|
||||
in
|
||||
lib.mapAttrs' (name: value: {
|
||||
name = lib.removeSuffix ".nix" name;
|
||||
value =
|
||||
if value == "regular" then
|
||||
path + "/${name}"
|
||||
else if value == "directory" then
|
||||
walk-dir (path + "/${name}")
|
||||
else
|
||||
builtins.throw "Items of type ${value} are unsupported.";
|
||||
}) dir;
|
||||
|
||||
# Takes a path `p` and returns a flattened lists of all files in that
|
||||
# directory, ignoring `p/default.nix`.
|
||||
import-recursive = path: lib.attrsets.collect builtins.isPath (walk-dir path // { default = { }; });
|
||||
subpaths = lib.mapAttrs' (filename: value: {
|
||||
name = lib.removeSuffix ".nix" filename;
|
||||
value =
|
||||
if value == "regular" then
|
||||
path + "/${filename}"
|
||||
else if value == "directory" then
|
||||
walk-dir (path + "/${filename}")
|
||||
else
|
||||
builtins.throw "Items of type ${value} are unsupported.";
|
||||
}) dir;
|
||||
in
|
||||
subpaths
|
||||
// rec {
|
||||
_files = lib.collect builtins.isPath (subpaths // { default = { }; });
|
||||
_nix_files = builtins.filter (lib.hasSuffix ".nix") _files;
|
||||
_nixos_mod =
|
||||
{ ... }:
|
||||
{
|
||||
imports = _nix_files;
|
||||
};
|
||||
};
|
||||
|
||||
# Takes a path `p` and returns a list of all files in that
|
||||
# directory recursively, ignoring `p/default.nix`.
|
||||
import-recursive = path: (walk-dir path)._files;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue