nvimConfig/modules/module/settings/cat-packages.nix
Daniel Winkler 9a6e20110e Make settings.lang_packages append instead of replace
Downstream modules assign settings.lang_packages.<lang> plainly, which
out-priorities mkOptionDefault and silently dropped the built-in
defaults (e.g. lintr, breaking R linting in downstream wrappers like the
project-template ed flake).

Move the built-in defaults into a separate settings.langPackageDefaults
option and compose defaults ++ lang_packages at the consumption sites
(catPkgs r/python/julia, quarto extraRPackages, neovide R host). A new
append-semantics check fails if defaults migrate back into lang_packages.

Also fix pre-existing inverted assertions in downstream-overrides check:
the override module sets cats.r = true, so assert presence, not absence.
2026-08-25 11:33:02 +10:00

147 lines
3.1 KiB
Nix

{
config,
pkgs,
lib,
...
}:
let
# Include packages from a category only if that category is enabled.
# NOTE: Package list expressions are lazily evaluated, and derivations are
# not built until needed, so keep side-effecting expressions out of these
# lists.
maybe = cat: pkgsList: lib.optionals (config.cats.${cat} or false) pkgsList;
rPackages =
(pkgs.baseRPackages or [ ])
++ config.settings.langPackageDefaults.r
++ config.settings.lang_packages.r;
rWrapperPackages = rPackages;
quartoPkg =
if config.cats.r or false then
pkgs.rpkgs.quarto.override { extraRPackages = rPackages; }
else
pkgs.quarto;
in
{
options.catPkgs = lib.mkOption {
type = lib.types.attrsOf (lib.types.listOf lib.types.package);
description = "Per-cat package lists, gated by cat toggles. Single source of truth for runtimeDeps and devShells.";
};
config.catPkgs = {
always = maybe "always" (
with pkgs;
[
ripgrep
]
);
clickhouse = maybe "clickhouse" (with pkgs; [ clickhouse-lts ]);
external = maybe "external" (
with pkgs;
[
nodejs
perl
ruby
shfmt
sqlfluff
tree-sitter
]
);
julia = maybe "julia" [
(pkgs.julia-bin.withPackages (
config.settings.langPackageDefaults.julia ++ config.settings.lang_packages.julia
))
];
lua = maybe "lua" (with pkgs; [ lua-language-server ]);
markdown = maybe "markdown" (
with pkgs;
[
python3Packages.pylatexenc
quartoPkg
zk
marksman
texlab
imagemagick
harper
]
);
nix = maybe "nix" (
with pkgs;
[
alejandra
nix-doc
nixd
]
);
optional = maybe "optional" (
with pkgs;
[
bat
broot
devenv
dust
fd
fzf
gawk
gh
git
hunspell
hunspellDicts.de-at
hunspellDicts.en-us
ispell
jq
just
lazygit
man
ncdu
pigz
poppler
ripgrep
tokei
wget
yq
]
);
python = maybe "python" (
let
python_packages_fn =
if pkgs ? basePythonPackages then
ps:
pkgs.basePythonPackages ps
++ config.settings.langPackageDefaults.python
++ config.settings.lang_packages.python
else
_: config.settings.langPackageDefaults.python ++ config.settings.lang_packages.python;
python_with_packages = pkgs.python3.withPackages python_packages_fn;
in
with pkgs;
[
python_with_packages
ruff
basedpyright
uv
]
);
r = maybe "r" [
(pkgs.rpkgs.rWrapper.override { packages = rWrapperPackages; })
pkgs.rpkgs.radianWrapper
quartoPkg
pkgs.air-formatter
pkgs.yaml-language-server
];
# cats without packages get empty lists
general = [ ];
gitPlugins = [ ];
treesitterParsers = [ ];
utils = [ ];
};
}