diff --git a/docs/conventions.md b/docs/conventions.md index 78df889..93e2666 100644 --- a/docs/conventions.md +++ b/docs/conventions.md @@ -172,7 +172,9 @@ The integration block at the bottom of `modules/system/users.nix` turns the cata **New NixOS leaf:** export `flake.nixosModules.whatever`, wire from `system/default.nix` or `desktop/default.nix` if it's global, or only from a host `configuration.nix` if it's not. `nix flake check`. Git-add new paths if eval uses the git tree. -**New HM slice:** add `modules/wisdom/.../foo.nix` exporting `flake.homeManagerModules.wisdomFoo` (import-tree picks it up; `wisdomCatalogExtraModules` includes every `wisdom*` export except `wisdom` / `wisdomShellBash`). Gate packages on `chiasson.home.*.enable`, and set the slice's own `enable` default (`mkEnableOption "…" // { default = true/false }`) in that same module — defaults live with the option that owns them, not in a shared defaults file. Hosts flip toggles in `home.nix`. Upstream HM deps stay imported unconditionally — use `mkIf` on `cfg.enable` for config (never `config`-dependent `imports`; that recurses). +**New HM slice:** add `modules/wisdom/.../foo.nix` exporting `flake.homeManagerModules.wisdomFoo` (import-tree picks it up; `wisdomCatalogExtraModules` includes every `wisdom*` export). Every `wisdom*` slice auto-catalogs — including the bash shell — so the root module no longer manually `imports` it. Gate packages on `chiasson.home.*.enable`, and set the slice's own `enable` default with `mkEnableOption "…" // { default = true/false }` in that same module — defaults live with the option that owns them, not in a shared defaults file. Hosts flip toggles in `home.nix`. Upstream HM deps stay imported unconditionally — use `mkIf` on `cfg.enable` for config (never `config`-dependent `imports`; that recurses). + +**Trivial single-package slice:** use `self.lib.wisdomSimpleSlice { path = "a.b"; default = true/false; description = "…"; packages = pkgs: [ … ]; }` instead of the `root`/`cfg` + `mkIf (root.enable && cfg.enable)` boilerplate. `packages` is a `pkgs -> [ drv ]` function responsible for its own `availableOn`/platform gating. Several such slices may share one `simple.nix` in their category dir (each still exporting its own `wisdom*` module), rather than one file per slice. **Derivations:** `let` inside a fragment, or `flake.packages` / `flake.lib` — not a bare `mkDerivation` file import-tree will try to load. diff --git a/modules/desktop/options.nix b/modules/desktop/options.nix index cf0e008..2ceac0d 100644 --- a/modules/desktop/options.nix +++ b/modules/desktop/options.nix @@ -7,13 +7,33 @@ self: let names = lib.sort builtins.lessThan ( - lib.filter (n: lib.hasPrefix "wisdom" n && n != "wisdom" && n != "wisdomShellBash") ( + lib.filter (n: lib.hasPrefix "wisdom" n && n != "wisdom") ( builtins.attrNames self.homeManagerModules ) ); in map (name: self.homeManagerModules.${name}) names; + # Thin HM slice: an `enable` toggle that adds packages to `home.packages`, skipping + # any not `availableOn` this platform. `packages` is a `pkgs -> [ drv ]` function so + # callers only name each package once (the helper owns the platform-gating). Used by + # the trivial single-package wisdom slices so they stay one declarative block instead + # of the repeated `root/cfg` + `mkIf (root.enable && cfg.enable)` boilerplate. + flake.lib.wisdomSimpleSlice = + { path, default, description, packages }: + { config, lib, pkgs, ... }: + let + segs = lib.splitString "." path; + optPath = [ "chiasson" "home" ] ++ segs ++ [ "enable" ]; + enabled = lib.getAttrFromPath optPath config; + in + { + options = lib.setAttrByPath optPath (lib.mkEnableOption description // { inherit default; }); + config = lib.mkIf (config.chiasson.home.enable && enabled) { + home.packages = lib.filter (lib.meta.availableOn pkgs.stdenv.hostPlatform) (packages pkgs); + }; + }; + flake.nixosModules.desktopOptions = { config, options, lib, pkgs, self, inputs, ... }: let diff --git a/modules/wisdom/browsers/chrome.nix b/modules/wisdom/browsers/chrome.nix index 3834e91..6363914 100644 --- a/modules/wisdom/browsers/chrome.nix +++ b/modules/wisdom/browsers/chrome.nix @@ -1,21 +1,8 @@ -{ ... }: { - flake.homeManagerModules.wisdomBrowsersChrome = - { config, lib, pkgs, ... }: - let - root = config.chiasson.home; - cfg = config.chiasson.home.browsers.chrome; - in - { - options.chiasson.home.browsers.chrome.enable = lib.mkEnableOption '' - Chrome (unfree, needs `allowUnfree`); skipped if nixpkgs has no build for this platform. - '' // { - default = false; - }; - - config = lib.mkIf (root.enable && cfg.enable) { - home.packages = lib.optional ( - lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.google-chrome - ) pkgs.google-chrome; - }; - }; +{ self, ... }: { + flake.homeManagerModules.wisdomBrowsersChrome = self.lib.wisdomSimpleSlice { + path = "browsers.chrome"; + default = false; + description = "Chrome (unfree, needs `allowUnfree`); skipped if nixpkgs has no build for this platform."; + packages = pkgs: [ pkgs.google-chrome ]; + }; } diff --git a/modules/wisdom/browsers/edge.nix b/modules/wisdom/browsers/edge.nix index 590198c..367a92d 100644 --- a/modules/wisdom/browsers/edge.nix +++ b/modules/wisdom/browsers/edge.nix @@ -1,19 +1,8 @@ -{ ... }: { - flake.homeManagerModules.wisdomBrowsersEdge = - { config, lib, pkgs, ... }: - let - root = config.chiasson.home; - cfg = config.chiasson.home.browsers.edge; - in - { - options.chiasson.home.browsers.edge.enable = lib.mkEnableOption "Edge (unfree); skipped if unavailable on this platform." // { - default = false; - }; - - config = lib.mkIf (root.enable && cfg.enable) { - home.packages = lib.optional ( - lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.microsoft-edge - ) pkgs.microsoft-edge; - }; - }; +{ self, ... }: { + flake.homeManagerModules.wisdomBrowsersEdge = self.lib.wisdomSimpleSlice { + path = "browsers.edge"; + default = false; + description = "Edge (unfree); skipped if unavailable on this platform."; + packages = pkgs: [ pkgs.microsoft-edge ]; + }; } diff --git a/modules/wisdom/default.nix b/modules/wisdom/default.nix index d65abf1..c0d73ba 100644 --- a/modules/wisdom/default.nix +++ b/modules/wisdom/default.nix @@ -1,24 +1,23 @@ # HM side of the flake; option tree is `chiasson.home.*` (docs/conventions.md). { self, inputs, ... }: { - # Root module: chiasson.home.enable + bash. Other `wisdom*` slices auto-wire via - # `lib.wisdomCatalogExtraModules`; hosts flip `chiasson.home.*.enable` rather than re-importing. + # Root module: chiasson.home.enable + git identity. Other `wisdom*` slices (including + # the bash shell) auto-wire via `lib.wisdomCatalogExtraModules`; hosts flip + # `chiasson.home.*.enable` rather than re-importing. flake.homeManagerModules.wisdom = { config, lib, pkgs, ... }: let cfg = config.chiasson.home; in { - imports = [ - self.homeManagerModules.wisdomShellBash - ]; - options.chiasson.home = { - enable = lib.mkEnableOption '' - HM profile root for this flake (bash on by default). Desktop hosts use - `lib.wisdomCatalogExtraModules` once per user and flip `chiasson.home.*.enable` on the host. - '' // { - default = true; - }; + enable = + lib.mkEnableOption '' + HM profile root for this flake (bash on by default). Desktop hosts use + `lib.wisdomCatalogExtraModules` once per user and flip `chiasson.home.*.enable` on the host. + '' + // { + default = true; + }; extraPackages = lib.mkOption { type = lib.types.listOf lib.types.package; @@ -29,20 +28,25 @@ }; }; - config = lib.mkIf cfg.enable (lib.mkMerge [ - { home.packages = cfg.extraPackages; } + config = lib.mkIf cfg.enable ( + lib.mkMerge [ + { home.packages = cfg.extraPackages; } - # Base git identity + encryption/player tools shared by every HM user. - { - programs.git = { - enable = true; - settings.user = { - name = "OlivierChiasson"; - email = "olivierchiasson@hotmail.fr"; + # Base git identity + encryption/player tools shared by every HM user. + { + programs.git = { + enable = true; + settings.user = { + name = "OlivierChiasson"; + email = "olivierchiasson@hotmail.fr"; + }; }; - }; - home.packages = [ pkgs.git-crypt pkgs.feishin ]; - } - ]); + home.packages = [ + pkgs.git-crypt + pkgs.feishin + ]; + } + ] + ); }; } diff --git a/modules/wisdom/editors/kate.nix b/modules/wisdom/editors/kate.nix index b13ebda..ee00861 100644 --- a/modules/wisdom/editors/kate.nix +++ b/modules/wisdom/editors/kate.nix @@ -1,19 +1,8 @@ -{ ... }: { - flake.homeManagerModules.wisdomEditorsKate = - { config, lib, pkgs, ... }: - let - root = config.chiasson.home; - cfg = config.chiasson.home.editors.kate; - in - { - options.chiasson.home.editors.kate.enable = lib.mkEnableOption "Kate." // { - default = false; - }; - - config = lib.mkIf (root.enable && cfg.enable) { - home.packages = lib.optional ( - lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.kdePackages.kate - ) pkgs.kdePackages.kate; - }; - }; +{ self, ... }: { + flake.homeManagerModules.wisdomEditorsKate = self.lib.wisdomSimpleSlice { + path = "editors.kate"; + default = false; + description = "Kate."; + packages = pkgs: [ pkgs.kdePackages.kate ]; + }; } diff --git a/modules/wisdom/editors/obsidian.nix b/modules/wisdom/editors/obsidian.nix index 875890d..9ff2f8c 100644 --- a/modules/wisdom/editors/obsidian.nix +++ b/modules/wisdom/editors/obsidian.nix @@ -1,21 +1,8 @@ -{ ... }: { - flake.homeManagerModules.wisdomEditorsObsidian = - { config, lib, pkgs, ... }: - let - root = config.chiasson.home; - cfg = config.chiasson.home.editors.obsidian; - in - { - options.chiasson.home.editors.obsidian.enable = lib.mkEnableOption '' - Obsidian (unfree); skipped if unavailable here. - '' // { - default = true; - }; - - config = lib.mkIf (root.enable && cfg.enable) { - home.packages = lib.optional ( - lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.obsidian - ) pkgs.obsidian; - }; - }; +{ self, ... }: { + flake.homeManagerModules.wisdomEditorsObsidian = self.lib.wisdomSimpleSlice { + path = "editors.obsidian"; + default = true; + description = "Obsidian (unfree); skipped if unavailable here."; + packages = pkgs: [ pkgs.obsidian ]; + }; }