refactor!: import modules recursively

This commit is contained in:
Moritz Böhme 2023-05-11 17:33:14 +02:00
parent f9fd542206
commit 9567cce5fa
Signed by: moritz
GPG key ID: 970C6E89EB0547A9
35 changed files with 227 additions and 178 deletions

View file

@ -121,16 +121,8 @@
Modules Modules
*/ */
nixosModules = utils.lib.exportModules [
./modules/profiles/base.nix
./modules/profiles/gaming.nix
./modules/profiles/desktop.nix
./modules/profiles/personal.nix
];
hostDefaults.modules = [ hostDefaults.modules = [
./modules/default.nix ./modules/default.nix
self.nixosModules.base
inputs.home-manager.nixosModule inputs.home-manager.nixosModule
{ {
home-manager = { home-manager = {
@ -145,16 +137,11 @@
hosts.nixos-laptop.modules = [ hosts.nixos-laptop.modules = [
./hosts/nixos-laptop ./hosts/nixos-laptop
self.nixosModules.desktop
self.nixosModules.personal
]; ];
hosts.nixos-desktop.modules = [ hosts.nixos-desktop.modules = [
./hosts/nixos-desktop ./hosts/nixos-desktop
self.nixosModules.desktop
self.nixosModules.gaming
self.nixosModules.personal
]; ];
/* /*

View file

@ -10,7 +10,13 @@
# Include the results of the hardware scan. # Include the results of the hardware scan.
./hardware-configuration.nix ./hardware-configuration.nix
]; ];
my = { my = {
profiles = {
desktop.enable = true;
gaming.enable = true;
personal.enable = true;
};
programs.hyprland.nvidiaSupport = true; programs.hyprland.nvidiaSupport = true;
services.mullvad.enable = true; services.mullvad.enable = true;
programs.ledger.enable = true; programs.ledger.enable = true;

View file

@ -10,6 +10,11 @@
./hardware-configuration.nix ./hardware-configuration.nix
]; ];
my.profiles = {
desktop.enable = true;
personal.enable = true;
};
# BOOT # BOOT
boot = { boot = {
supportedFilesystems = [ "btrfs" ]; supportedFilesystems = [ "btrfs" ];

View file

@ -47,4 +47,34 @@ lib.makeExtensible (_: rec {
mapModules' = f: dir: lib.attrValues (mapModules f dir); mapModules' = f: dir: lib.attrValues (mapModules f dir);
listModules = mapModules' (path: path); listModules = mapModules' (path: path);
mapModulesRec = f: dir:
let
filterDirs = name: type:
let
isPublic = !(lib.hasPrefix "_" name);
isSomething = type != null;
isDir = type == "directory";
isDefault = isDir && builtins.pathExists "${toString dir}/${name}/default.nix";
in
isPublic && isSomething && isDir && !isDefault;
subDirs = lib.filterAttrs filterDirs (builtins.readDir dir);
mkSubModule = name: _:
let
path = "${toString dir}/${name}";
in
lib.nameValuePair name (mapModulesRec f path);
in
mapModules f dir //
(lib.mapAttrs' mkSubModule subDirs);
mapModulesRec' = f: dir:
let
attrValuesRec = attrs: map (values: if lib.isAttrs values then attrValuesRec values else values) (lib.attrValues attrs);
in
lib.flatten (attrValuesRec (mapModulesRec f dir));
listModulesRec = mapModulesRec' (path: path);
}) })

View file

@ -7,10 +7,10 @@
with lib; with lib;
let let
cfg = config.my.bin; cfg = config.my.bin;
cycleSinks = import ./cycleSinks.nix { inherit pkgs; }; cycleSinks = import ./_cycleSinks.nix { inherit pkgs; };
protonge = import ./protonge.nix { inherit pkgs; }; protonge = import ./_protonge.nix { inherit pkgs; };
share = import ./share.nix { inherit pkgs; }; share = import ./_share.nix { inherit pkgs; };
sxhkdHelp = import ./sxhkdHelp.nix { inherit pkgs; }; sxhkdHelp = import ./_sxhkdHelp.nix { inherit pkgs; };
in in
{ {
options.my.bin.enable = mkEnableOption "bin"; options.my.bin.enable = mkEnableOption "bin";

View file

@ -1,5 +0,0 @@
{ lib, ... }:
{
imports = lib.my.listModules ./.;
}

View file

@ -6,7 +6,7 @@ let
in in
{ {
config = mkIf (cfg.enable && cfg.scheme == "catppuccin-frappe") config = mkIf (cfg.enable && cfg.scheme == "catppuccin-frappe")
(import ./catppuccin.nix (import ./_catppuccin.nix
{ {
inherit config lib pkgs; inherit config lib pkgs;
flavor = "mocha"; flavor = "mocha";

View file

@ -6,7 +6,7 @@ let
in in
{ {
config = mkIf (cfg.enable && cfg.scheme == "catppuccin-latte") config = mkIf (cfg.enable && cfg.scheme == "catppuccin-latte")
(import ./catppuccin.nix (import ./_catppuccin.nix
{ {
inherit config lib pkgs; inherit config lib pkgs;
flavor = "mocha"; flavor = "mocha";

View file

@ -6,7 +6,7 @@ let
in in
{ {
config = mkIf (cfg.enable && cfg.scheme == "catppuccin-macchiato") config = mkIf (cfg.enable && cfg.scheme == "catppuccin-macchiato")
(import ./catppuccin.nix (import ./_catppuccin.nix
{ {
inherit config lib pkgs; inherit config lib pkgs;
flavor = "mocha"; flavor = "mocha";

View file

@ -6,7 +6,7 @@ let
in in
{ {
config = mkIf (cfg.enable && cfg.scheme == "catppuccin-mocha") config = mkIf (cfg.enable && cfg.scheme == "catppuccin-mocha")
(import ./catppuccin.nix (import ./_catppuccin.nix
{ {
inherit config lib pkgs; inherit config lib pkgs;
flavor = "mocha"; flavor = "mocha";

View file

Before

Width:  |  Height:  |  Size: 12 MiB

After

Width:  |  Height:  |  Size: 12 MiB

View file

Before

Width:  |  Height:  |  Size: 5.2 MiB

After

Width:  |  Height:  |  Size: 5.2 MiB

View file

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 118 KiB

View file

Before

Width:  |  Height:  |  Size: 4.6 MiB

After

Width:  |  Height:  |  Size: 4.6 MiB

View file

Before

Width:  |  Height:  |  Size: 10 MiB

After

Width:  |  Height:  |  Size: 10 MiB

View file

Before

Width:  |  Height:  |  Size: 501 KiB

After

Width:  |  Height:  |  Size: 501 KiB

View file

Before

Width:  |  Height:  |  Size: 635 KiB

After

Width:  |  Height:  |  Size: 635 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

View file

@ -1,9 +1,4 @@
{ lib, ... }:
{ {
imports = [ imports = lib.my.listModulesRec ./.;
./config
./programs
./security
./services
./virtualisation
];
} }

View file

@ -1,8 +1,17 @@
{ lib { lib
, config
, pkgs , pkgs
, ... , ...
}: }:
with lib; {
with lib;
let
cfg = config.my.profiles.desktop;
in
{
options.my.profiles.desktop.enable = mkEnableOption "desktop profile";
config = mkIf cfg.enable {
my = { my = {
yubikey = { yubikey = {
enable = mkDefault true; enable = mkDefault true;
@ -70,4 +79,5 @@ with lib; {
pulse.enable = true; pulse.enable = true;
}; };
}; };
};
} }

View file

@ -1,6 +1,17 @@
{ pkgs { lib
, config
, pkgs
, ... , ...
}: { }:
with lib;
let
cfg = config.my.profiles.gaming;
in
{
options.my.profiles.gaming.enable = mkEnableOption "Enable gaming profile";
config = mkIf cfg.enable {
programs.steam.enable = true; programs.steam.enable = true;
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
lutris lutris
@ -8,4 +19,5 @@
heroic heroic
mangohud mangohud
]; ];
};
} }

View file

@ -1,7 +1,17 @@
{ lib, ... }: { lib
, config
, ...
}:
with lib; with lib;
let
cfg = config.my.profiles.personal;
in
{ {
options.my.profiles.personal.enable = mkEnableOption "personal profile";
config = mkIf cfg.enable
{
my = { my = {
services = { services = {
openconnect.enable = true; openconnect.enable = true;
@ -60,4 +70,5 @@ with lib;
}; };
}; };
}; };
};
} }

View file

@ -1,10 +1,23 @@
{ pkgs }: { lib
, config
, pkgs
, ...
}:
with lib;
let
cfg = config.my.profiles.ripping;
in
{ {
options.my.profiles.ripping.enable = mkEnableOption "ripping profile";
config = mkIf cfg.enable {
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
# ripping # ripping
abcde abcde
handbrake handbrake
picard picard
]; ];
};
} }

View file

@ -1,5 +0,0 @@
{ lib, ... }:
{
imports = lib.my.listModules ./.;
}

View file

@ -48,7 +48,7 @@ in
enable = true; enable = true;
package = hyprland; package = hyprland;
recommendedEnvironment = true; recommendedEnvironment = true;
extraConfig = import ./config.nix args; extraConfig = import ./_config.nix args;
}; };
}; };

View file

@ -1,5 +0,0 @@
{ lib, ... }:
{
imports = lib.my.listModules ./.;
}

View file

@ -1,5 +0,0 @@
{ lib, ... }:
{
imports = lib.my.listModules ./.;
}