Skip to content

Commit 0210d53

Browse files
committed
auto import nix files
1 parent 5c63553 commit 0210d53

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed

home-manager/desktop/default.nix

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
{ ... }:
1+
{ lib, ... }:
22

3+
with lib;
4+
let
5+
# Recursively constructs an attrset of a given folder, recursing on directories, value of attrs is the filetype
6+
getDir =
7+
dir:
8+
mapAttrs (file: type: if type == "directory" then getDir "${dir}/${file}" else type) (
9+
builtins.readDir dir
10+
);
11+
12+
# Collects all files of a directory as a list of strings of paths
13+
files = dir: collect isString (mapAttrsRecursive (path: _: concatStringsSep "/" path) (getDir dir));
14+
15+
# Filters out directories that don't end with .nix or are this file, also makes the strings absolute
16+
validFiles =
17+
dir:
18+
map (file: ./. + "/${file}") (
19+
filter (file: hasSuffix ".nix" file && file != "default.nix") (files dir)
20+
);
21+
22+
in
323
{
424
imports = [
525
../default.nix
6-
7-
./app.nix
8-
./dconf.nix
9-
./development.nix
10-
./editors.nix
11-
./gtk.nix
12-
./hyprland.nix
13-
./mpv.nix
14-
./rofi.nix
15-
./terminal.nix
16-
./xdg.nix
17-
];
26+
] ++ validFiles ./.;
1827
}

home-manager/home/default.nix

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
{ ... }:
1+
{ lib, ... }:
22

3+
with lib;
4+
let
5+
# Recursively constructs an attrset of a given folder, recursing on directories, value of attrs is the filetype
6+
getDir =
7+
dir:
8+
mapAttrs (file: type: if type == "directory" then getDir "${dir}/${file}" else type) (
9+
builtins.readDir dir
10+
);
11+
12+
# Collects all files of a directory as a list of strings of paths
13+
files = dir: collect isString (mapAttrsRecursive (path: _: concatStringsSep "/" path) (getDir dir));
14+
15+
# Filters out directories that don't end with .nix or are this file, also makes the strings absolute
16+
validFiles =
17+
dir:
18+
map (file: ./. + "/${file}") (
19+
filter (file: hasSuffix ".nix" file && file != "default.nix") (files dir)
20+
);
21+
22+
in
323
{
424
imports = [
525
../desktop/default.nix
6-
7-
./gaming.nix
8-
./mail.nix
9-
./video.nix
10-
];
26+
] ++ validFiles ./.;
1127
}

hosts/desktop/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
inputs,
3+
lib,
34
pkgs,
45
pkgs-unstable,
56
stateVersion,
@@ -31,6 +32,7 @@
3132
${meta.user.username} = import ../../home-manager/home {
3233
inherit
3334
inputs
35+
lib
3436
pkgs
3537
pkgs-unstable
3638
stateVersion

0 commit comments

Comments
 (0)