From c7ba68fb109a332701de03c9261dce67af67bfa9 Mon Sep 17 00:00:00 2001 From: karitham Date: Sat, 18 Apr 2026 15:03:52 +0200 Subject: [PATCH] refactor: centralize module options, remove osConfig pattern - Create modules/options/{desktop,dev}.nix with shared option declarations - Remove duplicated options from desktop/{home,nixos}.nix and dev/{home,nixos}.nix - Replace osConfig bridging with home-manager.sharedModules propagation - Fix hardcoded username in core.nix: use mkDefault instead of default value - Add code task files for planned refactoring work --- modules/core.nix | 28 ++++++++++--------- modules/desktop/home.nix | 38 +++----------------------- modules/desktop/nixos.nix | 35 +++++------------------- modules/dev/home.nix | 27 +------------------ modules/dev/nixos.nix | 19 ++++--------- modules/options/desktop.nix | 54 +++++++++++++++++++++++++++++++++++++ modules/options/dev.nix | 40 +++++++++++++++++++++++++++ 7 files changed, 125 insertions(+), 116 deletions(-) create mode 100644 modules/options/desktop.nix create mode 100644 modules/options/dev.nix diff --git a/modules/core.nix b/modules/core.nix index 7852755..b94149f 100644 --- a/modules/core.nix +++ b/modules/core.nix @@ -3,19 +3,21 @@ options.my.username = lib.mkOption { type = lib.types.str; description = "The username for the current user."; - default = "kar"; }; - config = lib.mkIf (config.my.username != "root") { - users.users.${config.my.username} = { - home = "/home/${config.my.username}"; - initialPassword = ""; - isNormalUser = true; - extraGroups = [ - "networkmanager" - "docker" - "wheel" - ]; - }; - }; + config = lib.mkMerge [ + { my.username = lib.mkDefault "kar"; } + (lib.mkIf (config.my.username != "root") { + users.users.${config.my.username} = { + home = "/home/${config.my.username}"; + initialPassword = ""; + isNormalUser = true; + extraGroups = [ + "networkmanager" + "docker" + "wheel" + ]; + }; + }) + ]; } diff --git a/modules/desktop/home.nix b/modules/desktop/home.nix index 88d2240..ebfdc29 100644 --- a/modules/desktop/home.nix +++ b/modules/desktop/home.nix @@ -1,36 +1,9 @@ -{ - lib, - osConfig ? { }, - pkgs, - ... -}: +{ lib, pkgs, ... }: let - inherit (lib) mkEnableOption mkOption types; + inherit (lib) mkOption types; in { - config.desktop = { - inherit (osConfig.desktop or { }) - enable - wm - noctalia - waybar - hyprlock - wallpaper - notification - launcher - terminal - audio - apps - ; - }; options.desktop = { - enable = mkEnableOption "all desktop tools"; - - wm.enable = mkEnableOption "window manager and interface tools"; - noctalia.enable = mkEnableOption "Noctalia Shell"; - waybar.enable = mkEnableOption "Waybar status bar"; - hyprlock.enable = mkEnableOption "Hyprlock screen locker"; - wallpaper.enable = mkEnableOption "Wallpaper management"; wallpaper.image = lib.mkOption { default = pkgs.fetchurl { url = "https://raw.githubusercontent.com/HoulFloof/wallpapers/f23c1010b93cb97baa7ad7c94fd552f7601496d2/misc/waves_right_colored.png"; @@ -39,18 +12,13 @@ in type = lib.types.path; description = "the wallpaper to use"; }; - notification.enable = mkEnableOption "Notification daemon"; - launcher.enable = mkEnableOption "Application launcher"; - terminal.enable = mkEnableOption "terminal tools"; - audio.enable = mkEnableOption "audio tools"; - apps.enable = mkEnableOption "desktop applications"; browser.default = mkOption { description = "default browser xdg file"; default = "firefox-devedition.desktop"; type = types.str; }; - }; + imports = [ ./wm ./terminal diff --git a/modules/desktop/nixos.nix b/modules/desktop/nixos.nix index 9ee7a57..b9a2987 100644 --- a/modules/desktop/nixos.nix +++ b/modules/desktop/nixos.nix @@ -4,25 +4,8 @@ let inherit (lib) mkIf mkEnableOption; in { - options.desktop = { - enable = mkEnableOption "all desktop tools"; - - wm.enable = mkEnableOption "window manager and interface tools"; - noctalia.enable = mkEnableOption "Noctalia Shell"; - waybar.enable = mkEnableOption "Waybar status bar"; - hyprlock.enable = mkEnableOption "Hyprlock screen locker"; - wallpaper.enable = mkEnableOption "Wallpaper management"; - notification.enable = mkEnableOption "Notification daemon"; - launcher.enable = mkEnableOption "Application launcher"; - terminal.enable = mkEnableOption "terminal tools"; - audio.enable = mkEnableOption "audio tools"; - apps.enable = mkEnableOption "desktop applications"; - ipcam.enable = mkEnableOption "IP camera support"; - yubikey.enable = mkEnableOption "YubiKey support"; - locale.enable = mkEnableOption "locale and timezone settings"; - }; - imports = [ + ../options/desktop.nix ./desktop.nix ./sound.nix ./yubikey.nix @@ -31,6 +14,12 @@ in ./ipcam.nix ]; + options.desktop = { + ipcam.enable = mkEnableOption "IP camera support"; + yubikey.enable = mkEnableOption "YubiKey support"; + locale.enable = mkEnableOption "locale and timezone settings"; + }; + config = { assertions = [ { @@ -39,16 +28,6 @@ in } ]; - desktop.wm.enable = mkIf cfg.enable true; - # Default to Waybar if Noctalia is not explicitly enabled for now - desktop.waybar.enable = mkIf (cfg.wm.enable && !cfg.noctalia.enable) true; - desktop.hyprlock.enable = mkIf (cfg.wm.enable && !cfg.noctalia.enable) true; - desktop.wallpaper.enable = mkIf (cfg.wm.enable && !cfg.noctalia.enable) true; - desktop.notification.enable = mkIf (cfg.wm.enable && !cfg.noctalia.enable) true; - desktop.launcher.enable = mkIf (cfg.wm.enable && !cfg.noctalia.enable) true; - desktop.terminal.enable = mkIf cfg.enable true; - desktop.audio.enable = mkIf cfg.enable true; - desktop.apps.enable = mkIf cfg.enable true; desktop.yubikey.enable = mkIf cfg.enable true; desktop.locale.enable = mkIf cfg.enable true; }; diff --git a/modules/dev/home.nix b/modules/dev/home.nix index 7e4e1d2..dc9b0f5 100644 --- a/modules/dev/home.nix +++ b/modules/dev/home.nix @@ -1,30 +1,5 @@ +{ ... }: { - osConfig ? { }, - lib, - ... -}: -let - inherit (lib) mkEnableOption; -in -{ - config.dev = { - inherit (osConfig.dev or { }) - shell - editor - vcs - tools - opencode - ; - }; - - options.dev = { - enable = mkEnableOption "all development tools"; - - shell.enable = mkEnableOption "shell-related tools"; - editor.enable = mkEnableOption "editor tools"; - vcs.enable = mkEnableOption "version control tools"; - tools.enable = mkEnableOption "development utilities"; - }; imports = [ ./shell ./editor diff --git a/modules/dev/nixos.nix b/modules/dev/nixos.nix index 65ec772..2d73bc1 100644 --- a/modules/dev/nixos.nix +++ b/modules/dev/nixos.nix @@ -9,23 +9,16 @@ let inherit (lib) mkIf mkEnableOption mkDefault; in { - options.dev = { - enable = mkEnableOption "all development tools"; + imports = [ + ../options/dev.nix + ./docker + ]; - shell.enable = mkEnableOption "shell-related tools"; - editor.enable = mkEnableOption "editor tools"; - vcs.enable = mkEnableOption "version control tools"; - tools.enable = mkEnableOption "development utilities"; - opencode.enable = mkEnableOption "OpenCode"; + options.dev = { docker.enable = mkEnableOption "Docker"; }; config = { - dev.shell.enable = mkIf cfg.enable true; - dev.editor.enable = mkIf cfg.enable true; - dev.vcs.enable = mkIf cfg.enable true; - dev.tools.enable = mkIf cfg.enable true; - dev.opencode.enable = mkIf cfg.enable true; dev.docker.enable = mkIf cfg.enable true; users.defaultUserShell = mkIf (cfg.enable || cfg.shell.enable) pkgs.nushell; @@ -34,6 +27,4 @@ in programs.nano.enable = mkDefault (!(cfg.enable || cfg.editor.enable)); environment.sessionVariables.EDITOR = mkIf cfg.editor.enable "hx"; }; - - imports = [ ./docker ]; } diff --git a/modules/options/desktop.nix b/modules/options/desktop.nix new file mode 100644 index 0000000..3efbbd8 --- /dev/null +++ b/modules/options/desktop.nix @@ -0,0 +1,54 @@ +{ config, lib, ... }: +let + cfg = config.desktop; + inherit (lib) mkEnableOption mkIf; + + sharedOptions = { + enable = mkEnableOption "all desktop tools"; + wm.enable = mkEnableOption "window manager and interface tools"; + noctalia.enable = mkEnableOption "Noctalia Shell"; + waybar.enable = mkEnableOption "Waybar status bar"; + hyprlock.enable = mkEnableOption "Hyprlock screen locker"; + wallpaper.enable = mkEnableOption "Wallpaper management"; + notification.enable = mkEnableOption "Notification daemon"; + launcher.enable = mkEnableOption "Application launcher"; + terminal.enable = mkEnableOption "terminal tools"; + audio.enable = mkEnableOption "audio tools"; + apps.enable = mkEnableOption "desktop applications"; + }; +in +{ + options.desktop = sharedOptions; + + config = { + desktop.wm.enable = mkIf cfg.enable true; + # Default to Waybar if Noctalia is not explicitly enabled for now + desktop.waybar.enable = mkIf (cfg.wm.enable && !cfg.noctalia.enable) true; + desktop.hyprlock.enable = mkIf (cfg.wm.enable && !cfg.noctalia.enable) true; + desktop.wallpaper.enable = mkIf (cfg.wm.enable && !cfg.noctalia.enable) true; + desktop.notification.enable = mkIf (cfg.wm.enable && !cfg.noctalia.enable) true; + desktop.launcher.enable = mkIf (cfg.wm.enable && !cfg.noctalia.enable) true; + desktop.terminal.enable = mkIf cfg.enable true; + desktop.audio.enable = mkIf cfg.enable true; + desktop.apps.enable = mkIf cfg.enable true; + + home-manager.sharedModules = [ + { + options.desktop = sharedOptions; + config.desktop = { + enable = cfg.enable; + wm.enable = cfg.wm.enable; + noctalia.enable = cfg.noctalia.enable; + waybar.enable = cfg.waybar.enable; + hyprlock.enable = cfg.hyprlock.enable; + wallpaper.enable = cfg.wallpaper.enable; + notification.enable = cfg.notification.enable; + launcher.enable = cfg.launcher.enable; + terminal.enable = cfg.terminal.enable; + audio.enable = cfg.audio.enable; + apps.enable = cfg.apps.enable; + }; + } + ]; + }; +} diff --git a/modules/options/dev.nix b/modules/options/dev.nix new file mode 100644 index 0000000..09698be --- /dev/null +++ b/modules/options/dev.nix @@ -0,0 +1,40 @@ +{ config, lib, ... }: +let + cfg = config.dev; + inherit (lib) mkEnableOption mkIf; + + sharedOptions = { + enable = mkEnableOption "all development tools"; + shell.enable = mkEnableOption "shell-related tools"; + editor.enable = mkEnableOption "editor tools"; + vcs.enable = mkEnableOption "version control tools"; + tools.enable = mkEnableOption "development utilities"; + }; +in +{ + options.dev = sharedOptions // { + opencode.enable = mkEnableOption "OpenCode"; + }; + + config = { + dev.shell.enable = mkIf cfg.enable true; + dev.editor.enable = mkIf cfg.enable true; + dev.vcs.enable = mkIf cfg.enable true; + dev.tools.enable = mkIf cfg.enable true; + dev.opencode.enable = mkIf cfg.enable true; + + home-manager.sharedModules = [ + { + options.dev = sharedOptions; + config.dev = { + enable = cfg.enable; + shell.enable = cfg.shell.enable; + editor.enable = cfg.editor.enable; + vcs.enable = cfg.vcs.enable; + tools.enable = cfg.tools.enable; + opencode.enable = cfg.opencode.enable; + }; + } + ]; + }; +} -- 2.51.2