From addf563bfc05059fc5c52121c75f24d4fe81d4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sun, 16 Mar 2025 16:10:02 +0100 Subject: [PATCH] refactor: move modules to their own dir --- flake-modules/docs.nix | 7 +- flake-modules/nixos-modules.nix | 115 ++++++++++++------ flake-modules/nvim.nix | 2 +- {home => modules/hm}/default.nix | 20 +-- {home => modules/hm}/gui/default.nix | 0 {home => modules/hm}/gui/keybindings.nix | 0 {home => modules/hm}/gui/sway-config.nix | 0 {home => modules/hm}/gui/waybar-settings.nix | 0 {home => modules/hm}/options.nix | 0 {home => modules/hm}/users.nix | 0 {system => modules/nixos}/default.nix | 2 - {system => modules/nixos}/gui/default.nix | 0 {system => modules/nixos}/options.nix | 0 .../nixos}/starship-nerdfont-symbols.nix | 0 .../nixos}/starship-shorter-text.nix | 0 {system => modules/nixos}/stylix-config.nix | 0 {nvim => modules/nixvim}/augroups.nix | 0 {nvim => modules/nixvim}/default.nix | 0 {nvim => modules/nixvim}/dev-plugins.nix | 0 .../nixvim}/extraPlugins/default.nix | 0 .../nixvim}/extraPlugins/generated.nix | 0 {nvim => modules/nixvim}/extraPlugins/plugins | 0 {nvim => modules/nixvim}/mappings.nix | 0 {nvim => modules/nixvim}/options.nix | 0 {nvim => modules/nixvim}/plugins.nix | 0 {nvim => modules/nixvim}/standalone.nix | 0 26 files changed, 86 insertions(+), 60 deletions(-) rename {home => modules/hm}/default.nix (96%) rename {home => modules/hm}/gui/default.nix (100%) rename {home => modules/hm}/gui/keybindings.nix (100%) rename {home => modules/hm}/gui/sway-config.nix (100%) rename {home => modules/hm}/gui/waybar-settings.nix (100%) rename {home => modules/hm}/options.nix (100%) rename {home => modules/hm}/users.nix (100%) rename {system => modules/nixos}/default.nix (98%) rename {system => modules/nixos}/gui/default.nix (100%) rename {system => modules/nixos}/options.nix (100%) rename {system => modules/nixos}/starship-nerdfont-symbols.nix (100%) rename {system => modules/nixos}/starship-shorter-text.nix (100%) rename {system => modules/nixos}/stylix-config.nix (100%) rename {nvim => modules/nixvim}/augroups.nix (100%) rename {nvim => modules/nixvim}/default.nix (100%) rename {nvim => modules/nixvim}/dev-plugins.nix (100%) rename {nvim => modules/nixvim}/extraPlugins/default.nix (100%) rename {nvim => modules/nixvim}/extraPlugins/generated.nix (100%) rename {nvim => modules/nixvim}/extraPlugins/plugins (100%) rename {nvim => modules/nixvim}/mappings.nix (100%) rename {nvim => modules/nixvim}/options.nix (100%) rename {nvim => modules/nixvim}/plugins.nix (100%) rename {nvim => modules/nixvim}/standalone.nix (100%) diff --git a/flake-modules/docs.nix b/flake-modules/docs.nix index cc85766..76ffb19 100644 --- a/flake-modules/docs.nix +++ b/flake-modules/docs.nix @@ -5,17 +5,18 @@ { packages = let + modules = ../modules; filterVisible = toplevelOption: option: option // { visible = option.visible && builtins.elemAt option.loc 0 == toplevelOption; }; home-eval = lib.evalModules { - modules = [ ../home/options.nix ]; + modules = [ (modules + "/hm/options.nix") ]; specialArgs = { inherit pkgs; }; }; - nvim-eval = lib.evalModules { modules = [ ../nvim/options.nix ]; }; - nixos-eval = lib.evalModules { modules = [ ../system/options.nix ]; }; + nvim-eval = lib.evalModules { modules = [ (modules + "/nixvim/options.nix") ]; }; + nixos-eval = lib.evalModules { modules = [ (modules + "/nixos/options.nix") ]; }; home-markdown = (pkgs.nixosOptionsDoc { inherit (home-eval) options; diff --git a/flake-modules/nixos-modules.nix b/flake-modules/nixos-modules.nix index 1422669..3606a3f 100644 --- a/flake-modules/nixos-modules.nix +++ b/flake-modules/nixos-modules.nix @@ -1,45 +1,82 @@ -{ inputs, lib, ... }: { - flake.nixosModules = - let - nvim-config = { - imports = [ - inputs.nixvim.homeManagerModules.nixvim - ../nvim - ]; - }; - homeManagerModuleSandalone = import ../home { - inherit nvim-config; - inherit (inputs) stylix; - }; - homeManagerModuleNixOS = import ../home { inherit nvim-config; }; - nixosModule = { - imports = [ - (import ../system { inherit (inputs) stylix; }) - inputs.home-manager.nixosModules.home-manager - ] ++ lib.optional (inputs.lix-module != null) inputs.lix-module.nixosModules.default; - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - sharedModules = [ homeManagerModuleNixOS ]; + self, + inputs, + lib, + ... +}: +let + modules = ../modules; +in +{ + flake = { + nixvimModules = + let + standalone = modules + "/nixvim/standalone.nix"; + homeManager = { + imports = [ + inputs.nixvim.homeManagerModules.nixvim + (modules + "/nixvim") + ]; }; - # Pin nixpkgs - nix.registry.nixpkgs.flake = inputs.nixpkgs; + in + { + inherit standalone homeManager; }; - - machines = [ "vm" ]; - mkMachine = hostname: { - imports = [ - nixosModule - (import (../machines + "/${hostname}")) + homeManagerModules = + let + defaultModules = [ + self.nixvimModules.homeManager + (modules + "/hm") ]; - home-manager.sharedModules = [ { jhome.hostName = hostname; } ]; + nixos = { + imports = defaultModules; + }; + standalone = { + imports = defaultModules ++ [ + inputs.stylix.homeManagerModules.stilyx + ( + { config, ... }: + { + stylix.image = config.jhome.sway.background; + } + ) + ]; + }; + in + { + inherit standalone nixos; }; - machineModules = lib.genAttrs machines mkMachine; - in - { - default = nixosModule; - inherit nixosModule homeManagerModuleNixOS homeManagerModuleSandalone; - } - // machineModules; + nixosModules = + let + nixosModule = { + imports = [ + inputs.stylix.nixosModules.stylix + inputs.home-manager.nixosModules.home-manager + (modules + "/nixos") + ] ++ lib.optional (inputs.lix-module != null) inputs.lix-module.nixosModules.default; + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + sharedModules = [ self.homeManagerModules.nixos ]; + }; + # Pin nixpkgs + nix.registry.nixpkgs.flake = inputs.nixpkgs; + }; + + machines = [ "vm" ]; + mkMachine = hostname: { + imports = [ + nixosModule + (import (../machines + "/${hostname}")) + ]; + home-manager.sharedModules = [ { jhome.hostName = hostname; } ]; + }; + machineModules = lib.genAttrs machines mkMachine; + in + { + default = nixosModule; + inherit nixosModule; + } + // machineModules; + }; } diff --git a/flake-modules/nvim.nix b/flake-modules/nvim.nix index 89832f3..f62c7ff 100644 --- a/flake-modules/nvim.nix +++ b/flake-modules/nvim.nix @@ -9,7 +9,7 @@ nvimModule = extraConfig: { pkgs = inputs.unstable.legacyPackages.${system}; module = { - imports = [ ../nvim/standalone.nix ]; + imports = [ ../modules/nixvim/standalone.nix ]; config = lib.mkMerge [ { performance.combinePlugins.enable = true; } extraConfig diff --git a/home/default.nix b/modules/hm/default.nix similarity index 96% rename from home/default.nix rename to modules/hm/default.nix index 2a8e6a5..0f1e59a 100644 --- a/home/default.nix +++ b/modules/hm/default.nix @@ -1,7 +1,3 @@ -{ - nvim-config, - stylix ? null, -}: { config, pkgs, @@ -17,17 +13,11 @@ let path: default: if osConfig == null then default else lib.attrsets.attrByPath path default osConfig; in { - imports = - [ - nvim-config - ./options.nix - ./gui - ./users.nix - ] - ++ lib.optionals (stylix != null) [ - stylix.homeManagerModules.stylix - { stylix.image = cfg.sway.background; } - ]; + imports = [ + ./options.nix + ./gui + ./users.nix + ]; config = lib.mkMerge [ (lib.mkIf (cfg.enable && cfg.styling.enable) { diff --git a/home/gui/default.nix b/modules/hm/gui/default.nix similarity index 100% rename from home/gui/default.nix rename to modules/hm/gui/default.nix diff --git a/home/gui/keybindings.nix b/modules/hm/gui/keybindings.nix similarity index 100% rename from home/gui/keybindings.nix rename to modules/hm/gui/keybindings.nix diff --git a/home/gui/sway-config.nix b/modules/hm/gui/sway-config.nix similarity index 100% rename from home/gui/sway-config.nix rename to modules/hm/gui/sway-config.nix diff --git a/home/gui/waybar-settings.nix b/modules/hm/gui/waybar-settings.nix similarity index 100% rename from home/gui/waybar-settings.nix rename to modules/hm/gui/waybar-settings.nix diff --git a/home/options.nix b/modules/hm/options.nix similarity index 100% rename from home/options.nix rename to modules/hm/options.nix diff --git a/home/users.nix b/modules/hm/users.nix similarity index 100% rename from home/users.nix rename to modules/hm/users.nix diff --git a/system/default.nix b/modules/nixos/default.nix similarity index 98% rename from system/default.nix rename to modules/nixos/default.nix index 3fdd0cf..58eb1e4 100644 --- a/system/default.nix +++ b/modules/nixos/default.nix @@ -1,4 +1,3 @@ -{ stylix }: { config, pkgs, @@ -22,7 +21,6 @@ in imports = [ ./options.nix ./gui - stylix.nixosModules.stylix { stylix = import ./stylix-config.nix { inherit config pkgs; }; } ]; diff --git a/system/gui/default.nix b/modules/nixos/gui/default.nix similarity index 100% rename from system/gui/default.nix rename to modules/nixos/gui/default.nix diff --git a/system/options.nix b/modules/nixos/options.nix similarity index 100% rename from system/options.nix rename to modules/nixos/options.nix diff --git a/system/starship-nerdfont-symbols.nix b/modules/nixos/starship-nerdfont-symbols.nix similarity index 100% rename from system/starship-nerdfont-symbols.nix rename to modules/nixos/starship-nerdfont-symbols.nix diff --git a/system/starship-shorter-text.nix b/modules/nixos/starship-shorter-text.nix similarity index 100% rename from system/starship-shorter-text.nix rename to modules/nixos/starship-shorter-text.nix diff --git a/system/stylix-config.nix b/modules/nixos/stylix-config.nix similarity index 100% rename from system/stylix-config.nix rename to modules/nixos/stylix-config.nix diff --git a/nvim/augroups.nix b/modules/nixvim/augroups.nix similarity index 100% rename from nvim/augroups.nix rename to modules/nixvim/augroups.nix diff --git a/nvim/default.nix b/modules/nixvim/default.nix similarity index 100% rename from nvim/default.nix rename to modules/nixvim/default.nix diff --git a/nvim/dev-plugins.nix b/modules/nixvim/dev-plugins.nix similarity index 100% rename from nvim/dev-plugins.nix rename to modules/nixvim/dev-plugins.nix diff --git a/nvim/extraPlugins/default.nix b/modules/nixvim/extraPlugins/default.nix similarity index 100% rename from nvim/extraPlugins/default.nix rename to modules/nixvim/extraPlugins/default.nix diff --git a/nvim/extraPlugins/generated.nix b/modules/nixvim/extraPlugins/generated.nix similarity index 100% rename from nvim/extraPlugins/generated.nix rename to modules/nixvim/extraPlugins/generated.nix diff --git a/nvim/extraPlugins/plugins b/modules/nixvim/extraPlugins/plugins similarity index 100% rename from nvim/extraPlugins/plugins rename to modules/nixvim/extraPlugins/plugins diff --git a/nvim/mappings.nix b/modules/nixvim/mappings.nix similarity index 100% rename from nvim/mappings.nix rename to modules/nixvim/mappings.nix diff --git a/nvim/options.nix b/modules/nixvim/options.nix similarity index 100% rename from nvim/options.nix rename to modules/nixvim/options.nix diff --git a/nvim/plugins.nix b/modules/nixvim/plugins.nix similarity index 100% rename from nvim/plugins.nix rename to modules/nixvim/plugins.nix diff --git a/nvim/standalone.nix b/modules/nixvim/standalone.nix similarity index 100% rename from nvim/standalone.nix rename to modules/nixvim/standalone.nix