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.
This commit is contained in:
Daniel Winkler 2026-08-25 11:25:05 +10:00
commit 9a6e20110e
6 changed files with 206 additions and 113 deletions

View file

@ -9,14 +9,17 @@ let
# 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.lang_packages.r;
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;
if config.cats.r or false then
pkgs.rpkgs.quarto.override { extraRPackages = rPackages; }
else
pkgs.quarto;
in
{
options.catPkgs = lib.mkOption {
@ -25,83 +28,107 @@ in
};
config.catPkgs = {
always = maybe "always" (with pkgs; [
ripgrep
]);
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
]);
external = maybe "external" (
with pkgs;
[
nodejs
perl
ruby
shfmt
sqlfluff
tree-sitter
]
);
julia = maybe "julia" [
(pkgs.julia-bin.withPackages config.settings.lang_packages.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
]);
markdown = maybe "markdown" (
with pkgs;
[
python3Packages.pylatexenc
quartoPkg
zk
marksman
texlab
imagemagick
harper
]
);
nix = maybe "nix" (with pkgs; [
alejandra
nix-doc
nixd
]);
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
]);
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.lang_packages.python
else _: config.settings.lang_packages.python;
python_with_packages = pkgs.python3.withPackages python_packages_fn;
in
with pkgs; [
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; })

View file

@ -14,6 +14,15 @@
# R.nvim v1.x owns its cache and temporary directories and exports
# RNVIM_COMPLDIR/RNVIM_TMPDIR during setup. Do not inject literal `$PWD`
# values into the wrapper environment.
#
# ponytail: with R_LIBS_USER unset-or-empty, loading compiled namespaces
# (S7 via btw) segfaults on macOS for bare-terminal launches outside the
# devShell hook. Any non-empty value avoids it; this store path exists,
# contains no libraries, and stays inert. The devShell hook overrides it
# with $PWD/.r-libs. Upgrade path: teach wlib to emit expandable defaults.
(lib.mkIf (config.cats.r or false) {
R_LIBS_USER = "${pkgs.rpkgs.rWrapper}";
})
];
# Environment variables with defaults (can be overridden by user)

View file

@ -5,7 +5,10 @@
...
}:
let
rPackages = (pkgs.baseRPackages or [ ]) ++ config.settings.lang_packages.r;
rPackages =
(pkgs.baseRPackages or [ ])
++ config.settings.langPackageDefaults.r
++ config.settings.lang_packages.r;
rWrapperPkg = pkgs.rpkgs.rWrapper.override { packages = rPackages ++ [pkgs.nvimcom]; };
in
{

View file

@ -5,53 +5,75 @@
...
}:
{
options.settings.lang_packages = lib.mkOption {
type = lib.types.submodule {
options = {
python = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [ ];
description = "Additional Python-related packages appended to the python spec (overlay defaults remain).";
};
r = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [ ];
description = "Additional R-related packages appended to the r spec (overlay defaults remain).";
};
julia = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "Additional Julia packages (names) passed to julia-bin.withPackages.";
options.settings = {
# Built-in language libraries composed into every language spec.
# Consumers extend via settings.lang_packages, which is APPENDED to these.
langPackageDefaults = lib.mkOption {
type = lib.types.submodule {
options = {
python = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [ ];
};
r = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [ ];
};
julia = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
};
};
};
default = { };
};
lang_packages = lib.mkOption {
type = lib.types.submodule {
options = {
python = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [ ];
description = "Additional Python-related packages appended to the python spec (overlay defaults remain).";
};
r = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [ ];
description = "Additional R-related packages appended to the r spec (overlay defaults remain).";
};
julia = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "Additional Julia packages (names) passed to julia-bin.withPackages.";
};
};
};
default = { };
description = ''
Project-specific language libraries. Appended to settings.langPackageDefaults
in each language spec's runtime packages.
'';
};
default = { };
description = ''
Language-specific package defaults and downstream overrides appended to each
language spec's runtime packages.
'';
};
config.settings.lang_packages = {
python = lib.mkDefault (with pkgs.python3Packages; [
config.settings.langPackageDefaults = {
python = with pkgs.python3Packages; [
duckdb
polars
]);
r = lib.mkDefault (
(with pkgs.rpkgs.rPackages; [
arrow
broom
data_table
janitor
styler
# vscDebugger is not on CRAN/Bioconductor, so it is not available in
# pkgs.rpkgs.rPackages. Install it manually in your R library if you
# want to use the nvim-dap R adapter (see plugin/26_dap.lua).
# vscDebugger
lintr
])
);
julia = lib.mkDefault [
];
r = with pkgs.rpkgs.rPackages; [
arrow
broom
data_table
janitor
styler
# vscDebugger is not on CRAN/Bioconductor, so it is not available in
# pkgs.rpkgs.rPackages. Install it manually in your R library if you
# want to use the nvim-dap R adapter (see plugin/26_dap.lua).
# vscDebugger
lintr
];
julia = [
"DataFramesMeta"
"QuackIO"
];