1
0
Fork 0
nix-configuration/modules/autoimport.nix

38 lines
1.3 KiB
Nix
Raw Normal View History

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, ... }:
with lib;
let
2024-05-16 12:19:04 -04:00
# Fetch secrets
# IMPORTANT: Make sure this repo exists on the filesystem first!
nix-secrets = builtins.fetchGit {
2024-05-16 12:19:04 -04:00
url = "/home/aires/Development/nix-configuration/nix-secrets";
ref = "main";
2024-05-16 13:42:05 -04:00
rev = "aed06e8c1f0d018fde197ae4e096012ed80cd08b";
2024-05-16 12:19:04 -04:00
};
# Recursively constructs an attrset of a given folder, recursing on directories, value of attrs is the filetype
getDir =
dir:
mapAttrs (file: type: if type == "directory" then getDir "${dir}/${file}" else type) (
builtins.readDir dir
);
2024-05-04 10:40:10 -04:00
# Collects all files of a directory as a list of strings of paths
files =
dir: collect isString (mapAttrsRecursive (path: type: concatStringsSep "/" path) (getDir dir));
2024-05-04 10:40:10 -04:00
# Filters out directories that belong to home-manager, and don't end with .nix or are this file.
# Also, make the strings absolute
validFiles =
dir:
map (file: ./. + "/${file}") (
filter (file: !hasInfix "home-manager" file && file != "autoimport.nix" && hasSuffix ".nix" file) (
files dir
)
);
2024-05-04 10:40:10 -04:00
in
{
imports = [ "${nix-secrets}" ] ++ validFiles ./.;
}