feat(wisdom): introduce wisdomSimpleSlice helper for package modules

Implement a `wisdomSimpleSlice` helper in `desktop/options.nix` to reduce
boilerplate for simple Home Manager modules that only manage packages.
This helper handles the `enable` option creation, platform-gating via
`availableOn`, and conditional inclusion in `home.packages`.

Refactor several existing wisdom modules to use this new helper:
- `wisdomBrowsersChrome`
- `wisdomBrowsersEdge`
- `wisdomEditorsKate`
- `wisdomEditorsObsidian`

Additionally, clean up `wisdom/default.nix` by removing the explicit
import of `wisdomShellBash` (which is now handled via auto-wiring) and
improving code formatting.
This commit is contained in:
2026-07-16 19:46:23 -03:00
parent 13f35677be
commit 103a485bf8
7 changed files with 81 additions and 103 deletions
+3 -1
View File
@@ -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 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. **Derivations:** `let` inside a fragment, or `flake.packages` / `flake.lib` — not a bare `mkDerivation` file import-tree will try to load.
+21 -1
View File
@@ -7,13 +7,33 @@
self: self:
let let
names = lib.sort builtins.lessThan ( 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 builtins.attrNames self.homeManagerModules
) )
); );
in in
map (name: self.homeManagerModules.${name}) names; 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 = flake.nixosModules.desktopOptions =
{ config, options, lib, pkgs, self, inputs, ... }: { config, options, lib, pkgs, self, inputs, ... }:
let let
+7 -20
View File
@@ -1,21 +1,8 @@
{ ... }: { { self, ... }: {
flake.homeManagerModules.wisdomBrowsersChrome = flake.homeManagerModules.wisdomBrowsersChrome = self.lib.wisdomSimpleSlice {
{ config, lib, pkgs, ... }: path = "browsers.chrome";
let default = false;
root = config.chiasson.home; description = "Chrome (unfree, needs `allowUnfree`); skipped if nixpkgs has no build for this platform.";
cfg = config.chiasson.home.browsers.chrome; packages = pkgs: [ pkgs.google-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;
};
};
} }
+7 -18
View File
@@ -1,19 +1,8 @@
{ ... }: { { self, ... }: {
flake.homeManagerModules.wisdomBrowsersEdge = flake.homeManagerModules.wisdomBrowsersEdge = self.lib.wisdomSimpleSlice {
{ config, lib, pkgs, ... }: path = "browsers.edge";
let default = false;
root = config.chiasson.home; description = "Edge (unfree); skipped if unavailable on this platform.";
cfg = config.chiasson.home.browsers.edge; packages = pkgs: [ pkgs.microsoft-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;
};
};
} }
+29 -25
View File
@@ -1,24 +1,23 @@
# HM side of the flake; option tree is `chiasson.home.*` (docs/conventions.md). # HM side of the flake; option tree is `chiasson.home.*` (docs/conventions.md).
{ self, inputs, ... }: { { self, inputs, ... }: {
# Root module: chiasson.home.enable + bash. Other `wisdom*` slices auto-wire via # Root module: chiasson.home.enable + git identity. Other `wisdom*` slices (including
# `lib.wisdomCatalogExtraModules`; hosts flip `chiasson.home.*.enable` rather than re-importing. # the bash shell) auto-wire via `lib.wisdomCatalogExtraModules`; hosts flip
# `chiasson.home.*.enable` rather than re-importing.
flake.homeManagerModules.wisdom = flake.homeManagerModules.wisdom =
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
cfg = config.chiasson.home; cfg = config.chiasson.home;
in in
{ {
imports = [
self.homeManagerModules.wisdomShellBash
];
options.chiasson.home = { options.chiasson.home = {
enable = lib.mkEnableOption '' enable =
HM profile root for this flake (bash on by default). Desktop hosts use lib.mkEnableOption ''
`lib.wisdomCatalogExtraModules` once per user and flip `chiasson.home.*.enable` on the host. 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; ''
}; // {
default = true;
};
extraPackages = lib.mkOption { extraPackages = lib.mkOption {
type = lib.types.listOf lib.types.package; type = lib.types.listOf lib.types.package;
@@ -29,20 +28,25 @@
}; };
}; };
config = lib.mkIf cfg.enable (lib.mkMerge [ config = lib.mkIf cfg.enable (
{ home.packages = cfg.extraPackages; } lib.mkMerge [
{ home.packages = cfg.extraPackages; }
# Base git identity + encryption/player tools shared by every HM user. # Base git identity + encryption/player tools shared by every HM user.
{ {
programs.git = { programs.git = {
enable = true; enable = true;
settings.user = { settings.user = {
name = "OlivierChiasson"; name = "OlivierChiasson";
email = "olivierchiasson@hotmail.fr"; email = "olivierchiasson@hotmail.fr";
};
}; };
}; home.packages = [
home.packages = [ pkgs.git-crypt pkgs.feishin ]; pkgs.git-crypt
} pkgs.feishin
]); ];
}
]
);
}; };
} }
+7 -18
View File
@@ -1,19 +1,8 @@
{ ... }: { { self, ... }: {
flake.homeManagerModules.wisdomEditorsKate = flake.homeManagerModules.wisdomEditorsKate = self.lib.wisdomSimpleSlice {
{ config, lib, pkgs, ... }: path = "editors.kate";
let default = false;
root = config.chiasson.home; description = "Kate.";
cfg = config.chiasson.home.editors.kate; packages = pkgs: [ pkgs.kdePackages.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;
};
};
} }
+7 -20
View File
@@ -1,21 +1,8 @@
{ ... }: { { self, ... }: {
flake.homeManagerModules.wisdomEditorsObsidian = flake.homeManagerModules.wisdomEditorsObsidian = self.lib.wisdomSimpleSlice {
{ config, lib, pkgs, ... }: path = "editors.obsidian";
let default = true;
root = config.chiasson.home; description = "Obsidian (unfree); skipped if unavailable here.";
cfg = config.chiasson.home.editors.obsidian; packages = pkgs: [ pkgs.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;
};
};
} }