2024-05-04 10:40:10 -04:00
|
|
|
# Auto-import modules in this folder, recursively.
|
|
|
|
# Sourced from https://github.com/evanjs/nixos_cfg/blob/4bb5b0b84a221b25cf50853c12b9f66f0cad3ea4/config/new-modules/default.nix
|
|
|
|
{ lib, ... }:
|
|
|
|
let
|
2024-05-07 18:02:59 -04:00
|
|
|
# Recursively constructs an attrset of a given folder, recursing on directories, value of attrs is the filetype
|
|
|
|
getDir =
|
|
|
|
dir:
|
2024-08-02 17:55:48 -04:00
|
|
|
lib.mapAttrs (file: type: if type == "directory" then getDir "${dir}/${file}" else type) (
|
2024-05-07 18:02:59 -04:00
|
|
|
builtins.readDir dir
|
|
|
|
);
|
2024-05-04 10:40:10 -04:00
|
|
|
|
2024-05-07 18:02:59 -04:00
|
|
|
# Collects all files of a directory as a list of strings of paths
|
|
|
|
files =
|
2024-08-02 17:55:48 -04:00
|
|
|
dir:
|
|
|
|
lib.collect lib.isString (
|
|
|
|
lib.mapAttrsRecursive (path: type: lib.concatStringsSep "/" path) (getDir dir)
|
|
|
|
);
|
2024-05-04 10:40:10 -04:00
|
|
|
|
2024-05-21 09:22:03 -04:00
|
|
|
# Search all files and folders within and below the current directory.
|
2024-05-07 18:02:59 -04:00
|
|
|
# Filters out directories that belong to home-manager, and don't end with .nix or are this file.
|
|
|
|
validFiles =
|
|
|
|
dir:
|
|
|
|
map (file: ./. + "/${file}") (
|
2024-08-02 17:55:48 -04:00
|
|
|
lib.filter (
|
|
|
|
file: !lib.hasInfix "home-manager" file && file != "autoimport.nix" && lib.hasSuffix ".nix" file
|
|
|
|
) (files dir)
|
2024-05-07 18:02:59 -04:00
|
|
|
);
|
2024-05-04 10:40:10 -04:00
|
|
|
in
|
|
|
|
{
|
2024-05-16 20:08:57 -04:00
|
|
|
imports = validFiles ./.;
|
2024-05-07 18:02:59 -04:00
|
|
|
}
|