refactor!: import modules recursively

dev-docs
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,73 +1,83 @@
{ lib { lib
, config
, pkgs , pkgs
, ... , ...
}: }:
with lib; {
my = { with lib;
yubikey = { let
enable = mkDefault true; cfg = config.my.profiles.desktop;
luksSupport = { in
{
options.my.profiles.desktop.enable = mkEnableOption "desktop profile";
config = mkIf cfg.enable {
my = {
yubikey = {
enable = mkDefault true; enable = mkDefault true;
devices = mkDefault [ "enc" ]; luksSupport = {
enable = mkDefault true;
devices = mkDefault [ "enc" ];
};
};
wallpapers.enable = mkDefault true;
theming = {
enable = mkDefault true;
scheme = mkDefault "catppuccin-macchiato";
};
virtualisation.podman.enable = mkDefault true;
programs = {
chromium.enable = mkDefault true;
firefox.enable = mkDefault true;
gpg.enable = mkDefault true;
hyprland.enable = mkDefault true;
logseq.enable = mkDefault true;
nvim.enable = mkDefault true;
python.versions."311".enable = mkDefault true;
spotify.enable = mkDefault true;
ssh.enable = mkDefault true;
thunar.enable = mkDefault true;
wallpaper.enable = mkDefault true;
zathura.enable = mkDefault true;
};
services = {
dunst.enable = mkDefault true;
gammastep.enable = true;
kdeconnect.enable = mkDefault true;
printing.enable = true;
wireguard.enable = true;
}; };
}; };
wallpapers.enable = mkDefault true;
theming = {
enable = mkDefault true;
scheme = mkDefault "catppuccin-macchiato";
};
virtualisation.podman.enable = mkDefault true;
programs = { environment.systemPackages = with pkgs; [
chromium.enable = mkDefault true; anki
firefox.enable = mkDefault true; calibre
gpg.enable = mkDefault true; keepassxc
hyprland.enable = mkDefault true; nixpkgs-review
logseq.enable = mkDefault true; pavucontrol
nvim.enable = mkDefault true; stable.libreoffice # HACK to fix build error
python.versions."311".enable = mkDefault true; stable.signal-desktop
spotify.enable = mkDefault true; texlive.combined.scheme-full
ssh.enable = mkDefault true; thunderbird
thunar.enable = mkDefault true; vlc
wallpaper.enable = mkDefault true; ];
zathura.enable = mkDefault true;
programs.nix-ld.enable = true;
home-manager.users.moritz = {
services.nextcloud-client = {
enable = true;
startInBackground = true;
};
}; };
services = { services = {
dunst.enable = mkDefault true; gnome.gnome-keyring.enable = true;
gammastep.enable = true; pipewire = {
kdeconnect.enable = mkDefault true; enable = true;
printing.enable = true; alsa.enable = true;
wireguard.enable = true; pulse.enable = true;
}; };
};
environment.systemPackages = with pkgs; [
anki
calibre
keepassxc
nixpkgs-review
pavucontrol
stable.libreoffice # HACK to fix build error
stable.signal-desktop
texlive.combined.scheme-full
thunderbird
vlc
];
programs.nix-ld.enable = true;
home-manager.users.moritz = {
services.nextcloud-client = {
enable = true;
startInBackground = true;
};
};
services = {
gnome.gnome-keyring.enable = true;
pipewire = {
enable = true;
alsa.enable = true;
pulse.enable = true;
}; };
}; };
} }

View File

@ -1,11 +1,23 @@
{ pkgs { lib
, config
, pkgs
, ... , ...
}: { }:
programs.steam.enable = true;
environment.systemPackages = with pkgs; [ with lib;
lutris let
legendary-gl cfg = config.my.profiles.gaming;
heroic in
mangohud {
]; options.my.profiles.gaming.enable = mkEnableOption "Enable gaming profile";
config = mkIf cfg.enable {
programs.steam.enable = true;
environment.systemPackages = with pkgs; [
lutris
legendary-gl
heroic
mangohud
];
};
} }

View File

@ -1,63 +1,74 @@
{ lib, ... }: { lib
, config
, ...
}:
with lib; with lib;
let
cfg = config.my.profiles.personal;
in
{ {
my = { options.my.profiles.personal.enable = mkEnableOption "personal profile";
services = {
openconnect.enable = true;
synology-drive.enable = true;
};
programs = {
ssh.includeSecrets = mkDefault [ ../../secrets/ssh-home.age ];
git.signing = mkDefault true;
hub.enable = mkDefault true;
firefox.arkenfox = {
enable = mkDefault true;
overrides = mkDefault {
## arkenfox overrides
# automatic search
"keyword.enabled" = true;
"browser.search.suggest.enabled" = true;
"browser.urlbar.suggest.searches" = true;
# startup page config = mkIf cfg.enable
"browser.startup.homepage" = "https://searxng.moritzboeh.me/"; {
"browser.startup.page" = 1; my = {
services = {
openconnect.enable = true;
synology-drive.enable = true;
};
programs = {
ssh.includeSecrets = mkDefault [ ../../secrets/ssh-home.age ];
git.signing = mkDefault true;
hub.enable = mkDefault true;
firefox.arkenfox = {
enable = mkDefault true;
overrides = mkDefault {
## arkenfox overrides
# automatic search
"keyword.enabled" = true;
"browser.search.suggest.enabled" = true;
"browser.urlbar.suggest.searches" = true;
# drm # startup page
"media.eme.enabled" = true; "browser.startup.homepage" = "https://searxng.moritzboeh.me/";
"browser.startup.page" = 1;
# sanitisation # drm
"privacy.clearOnShutdown.history" = false; "media.eme.enabled" = true;
# disable letterboxing # sanitisation
"privacy.resistFingerprinting.letterboxing" = false; "privacy.clearOnShutdown.history" = false;
## OTHER # disable letterboxing
# Dont show warning when accessing about:config "privacy.resistFingerprinting.letterboxing" = false;
"browser.aboutConfig.showWarning" = false;
# Hide bookmarks ## OTHER
"browser.toolbars.bookmarks.visibility" = "never"; # Dont show warning when accessing about:config
"browser.aboutConfig.showWarning" = false;
# Smooth scrolling # Hide bookmarks
"general.smoothScroll.lines.durationMaxMS" = 125; "browser.toolbars.bookmarks.visibility" = "never";
"general.smoothScroll.lines.durationMinMS" = 125;
"general.smoothScroll.mouseWheel.durationMaxMS" = 200; # Smooth scrolling
"general.smoothScroll.mouseWheel.durationMinMS" = 100; "general.smoothScroll.lines.durationMaxMS" = 125;
"general.smoothScroll.msdPhysics.enabled" = true; "general.smoothScroll.lines.durationMinMS" = 125;
"general.smoothScroll.other.durationMaxMS" = 125; "general.smoothScroll.mouseWheel.durationMaxMS" = 200;
"general.smoothScroll.other.durationMinMS" = 125; "general.smoothScroll.mouseWheel.durationMinMS" = 100;
"general.smoothScroll.pages.durationMaxMS" = 125; "general.smoothScroll.msdPhysics.enabled" = true;
"general.smoothScroll.pages.durationMinMS" = 125; "general.smoothScroll.other.durationMaxMS" = 125;
"mousewheel.min_line_scroll_amount" = 40; "general.smoothScroll.other.durationMinMS" = 125;
"mousewheel.system_scroll_override_on_root_content.enabled" = true; "general.smoothScroll.pages.durationMaxMS" = 125;
"mousewheel.system_scroll_override_on_root_content.horizontal.factor" = 175; "general.smoothScroll.pages.durationMinMS" = 125;
"mousewheel.system_scroll_override_on_root_content.vertical.factor" = 175; "mousewheel.min_line_scroll_amount" = 40;
"toolkit.scrollbox.horizontalScrollDistance" = 6; "mousewheel.system_scroll_override_on_root_content.enabled" = true;
"toolkit.scrollbox.verticalScrollDistance" = 2; "mousewheel.system_scroll_override_on_root_content.horizontal.factor" = 175;
"mousewheel.system_scroll_override_on_root_content.vertical.factor" = 175;
"toolkit.scrollbox.horizontalScrollDistance" = 6;
"toolkit.scrollbox.verticalScrollDistance" = 2;
};
};
}; };
}; };
}; };
};
} }

View File

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

@ -5,7 +5,7 @@ WALLPAPERS=$(find "$WALLPAPERS_PATH" -type f,l)
function help() { function help() {
echo "Usage:" echo "Usage:"
echo -e " wallpaper [OPTIONS] [PATH]" echo -e " wallpaper [OPTIONS] [PATH]"
echo "" echo ""
echo "Options:" echo "Options:"
echo -e " -h, --help \n\t Show this help message and exit" echo -e " -h, --help \n\t Show this help message and exit"
@ -60,12 +60,12 @@ done
set -- "${POSITIONAL[@]}" # restore positional arguments set -- "${POSITIONAL[@]}" # restore positional arguments
if [[ $# -gt 1 ]]; then if [[ $# -gt 1 ]]; then
help help
exit 1 exit 1
fi fi
if [[ $# -eq 1 ]]; then if [[ $# -eq 1 ]]; then
WALLPAPER="$1" WALLPAPER="$1"
fi fi
if [[ -z ${WALLPAPER+x} ]]; then if [[ -z ${WALLPAPER+x} ]]; then

View File

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

View File

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