load packages only if installed

This commit is contained in:
Daniel Winkler 2026-05-21 20:04:45 +10:00
commit d23c7f6f51
4 changed files with 92 additions and 82 deletions

View file

@ -39,10 +39,8 @@
wrappers, wrappers,
... ...
} @ inputs: let } @ inputs: let
mkWrapperConfig = pkgs: let mkWrapperConfig = pkgs: {
def = pkgs.lib.mkDefault; cats = {
in {
cats = pkgs.lib.mapAttrs (_: v: def v) {
clickhouse = false; clickhouse = false;
gitPlugins = true; gitPlugins = true;
julia = false; julia = false;
@ -55,22 +53,12 @@
}; };
settings = { settings = {
lang_packages = { lang_packages = {
python = def (with pkgs.python3Packages; [ python = [];
duckdb r = [];
polars julia = [];
]);
r = def ((with pkgs.rpkgs.rPackages; [
arrow
broom
data_table
janitor
languageserver
styler
]) ++ [ pkgs.nvimcom ]);
julia = def ["DataFramesMeta" "QuackIO"];
}; };
}; };
binName = def "vv"; binName = "vv";
}; };
wrapperSettings = pkgs: let wrapperSettings = pkgs: let
@ -78,7 +66,7 @@
in in
wrapper.config.wrap { wrapper.config.wrap {
inherit pkgs; inherit pkgs;
inherit (cfg) cats settings binName; inherit (cfg) settings binName;
}; };
systems = [ systems = [
@ -135,14 +123,29 @@
devShells = forAllSystems ( devShells = forAllSystems (
system: let system: let
pkgs = mkPkgs system; pkgs = mkPkgs system;
cfg = mkWrapperConfig pkgs;
nvimPkg = wrapperSettings pkgs; nvimPkg = wrapperSettings pkgs;
pythonPkgs = with pkgs.python3Packages; [
duckdb
polars
];
rPkgs = (with pkgs.rpkgs.rPackages; [
arrow
broom
data_table
janitor
languageserver
styler
]) ++ [ pkgs.nvimcom ];
juliaPkgs = ["DataFramesMeta" "QuackIO"];
pythonPackages = let pythonPackages = let
python_packages_fn = python_packages_fn =
if pkgs ? basePythonPackages if pkgs ? basePythonPackages
then ps: pkgs.basePythonPackages ps ++ cfg.settings.lang_packages.python then ps: pkgs.basePythonPackages ps ++ pythonPkgs
else _: cfg.settings.lang_packages.python; else _: pythonPkgs;
in in
with pkgs; [ with pkgs; [
(python3.withPackages python_packages_fn) (python3.withPackages python_packages_fn)
@ -153,7 +156,7 @@
]; ];
rPackages = let rPackages = let
r_packages = (pkgs.baseRPackages or []) ++ cfg.settings.lang_packages.r; r_packages = (pkgs.baseRPackages or []) ++ rPkgs;
in in
with pkgs; [ with pkgs; [
(rWrapper.override {packages = r_packages;}) (rWrapper.override {packages = r_packages;})
@ -167,7 +170,7 @@
]; ];
juliaPackages = let juliaPackages = let
julia_with_packages = pkgs.julia-bin.withPackages cfg.settings.lang_packages.julia; julia_with_packages = pkgs.julia-bin.withPackages juliaPkgs;
in [julia_with_packages]; in [julia_with_packages];
markdownPackages = with pkgs; [ markdownPackages = with pkgs; [

View file

@ -1,5 +1,7 @@
-- Add the key mappings only for Markdown files in a zk notebook. -- Add the key mappings only for Markdown files in a zk notebook.
if require("zk.util").notebook_root(vim.fn.expand('%:p')) ~= nil then local nix = require("config.nix")
if nix.get_cat("markdown", false) then
if require("zk.util").notebook_root(vim.fn.expand('%:p')) ~= nil then
local map = vim.keymap.set local map = vim.keymap.set
-- Open the link under the caret. -- Open the link under the caret.
map("n", "<CR>", "<Cmd>lua vim.lsp.buf.definition()<CR>", { noremap = true, silent = false, buffer = true }) map("n", "<CR>", "<Cmd>lua vim.lsp.buf.definition()<CR>", { noremap = true, silent = false, buffer = true })
@ -29,4 +31,5 @@ if require("zk.util").notebook_root(vim.fn.expand('%:p')) ~= nil then
map("v", "<leader>za", ":'<,'>lua vim.lsp.buf.range_code_action()<CR>", map("v", "<leader>za", ":'<,'>lua vim.lsp.buf.range_code_action()<CR>",
{ noremap = true, silent = false, buffer = true, desc = "Code actions" }) { noremap = true, silent = false, buffer = true, desc = "Code actions" })
end
end end

View file

@ -390,6 +390,7 @@ end)
-- zk -- zk
now_if_args(function() now_if_args(function()
if nix.get_cat("markdown", false) then
require("zk").setup({ require("zk").setup({
picker = "minipick", picker = "minipick",
lsp = { lsp = {
@ -409,4 +410,5 @@ now_if_args(function()
}, },
}) })
end
end) end)

View file

@ -71,6 +71,7 @@ end)
now(function() now(function()
vim.treesitter.language.register("markdown", { "quarto", "rmd" }) vim.treesitter.language.register("markdown", { "quarto", "rmd" })
if nix.get_cat({"r", "markdown"}, false) then
vim.api.nvim_create_autocmd("FileType", { vim.api.nvim_create_autocmd("FileType", {
pattern = { "quarto" }, pattern = { "quarto" },
callback = function() callback = function()
@ -87,6 +88,7 @@ now(function()
write_to_disk = true, write_to_disk = true,
}, },
}) })
end
end) end)
later(function() later(function()