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 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.
+21 -1
View File
@@ -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
+5 -18
View File
@@ -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.
'' // {
{ self, ... }: {
flake.homeManagerModules.wisdomBrowsersChrome = self.lib.wisdomSimpleSlice {
path = "browsers.chrome";
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;
};
description = "Chrome (unfree, needs `allowUnfree`); skipped if nixpkgs has no build for this platform.";
packages = pkgs: [ pkgs.google-chrome ];
};
}
+5 -16
View File
@@ -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." // {
{ self, ... }: {
flake.homeManagerModules.wisdomBrowsersEdge = self.lib.wisdomSimpleSlice {
path = "browsers.edge";
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;
};
description = "Edge (unfree); skipped if unavailable on this platform.";
packages = pkgs: [ pkgs.microsoft-edge ];
};
}
+15 -11
View File
@@ -1,22 +1,21 @@
# 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 ''
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;
};
@@ -29,7 +28,8 @@
};
};
config = lib.mkIf cfg.enable (lib.mkMerge [
config = lib.mkIf cfg.enable (
lib.mkMerge [
{ home.packages = cfg.extraPackages; }
# Base git identity + encryption/player tools shared by every HM user.
@@ -41,8 +41,12 @@
email = "olivierchiasson@hotmail.fr";
};
};
home.packages = [ pkgs.git-crypt pkgs.feishin ];
home.packages = [
pkgs.git-crypt
pkgs.feishin
];
}
]);
]
);
};
}
+5 -16
View File
@@ -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." // {
{ self, ... }: {
flake.homeManagerModules.wisdomEditorsKate = self.lib.wisdomSimpleSlice {
path = "editors.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;
};
description = "Kate.";
packages = pkgs: [ pkgs.kdePackages.kate ];
};
}
+5 -18
View File
@@ -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.
'' // {
{ self, ... }: {
flake.homeManagerModules.wisdomEditorsObsidian = self.lib.wisdomSimpleSlice {
path = "editors.obsidian";
default = true;
};
config = lib.mkIf (root.enable && cfg.enable) {
home.packages = lib.optional (
lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.obsidian
) pkgs.obsidian;
};
description = "Obsidian (unfree); skipped if unavailable here.";
packages = pkgs: [ pkgs.obsidian ];
};
}