From c2430bf407f7372bb8fd6aeba649e1fcc2ba3f0e Mon Sep 17 00:00:00 2001 From: TheColorman Date: Mon, 28 Oct 2024 22:24:04 +1100 Subject: [PATCH] Make chadrc.lua configurable --- README.md | 6 ++++++ nix/module.nix | 6 ++++++ nix/nvchad.nix | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 4056b1c..de8dac3 100644 --- a/README.md +++ b/README.md @@ -328,6 +328,12 @@ Overriding the option will expand this list. The config written in lua. It will be loaded after nvchad loaded. +#### chadrcConfig (optional) + +`string` + +Configuration that replaces chadrc.lua. Make sure to include `local M = {}` at the top, and `return M` at the bottom. + ##### gcc (optional) `pkg.gcc` diff --git a/nix/module.nix b/nix/module.nix index 5741829..dde81bd 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -25,6 +25,7 @@ let gcc_new = cfg.gcc; starterRepo = nvchad-starter; extraConfig = cfg.extraConfig; + chadrcConfig = cfg.chadrcConfig; lazy-lock = cfg.lazy-lock; extraPlugins = cfg.extraPlugins; }; @@ -71,6 +72,11 @@ in default = ""; description = "These config are loaded after nvchad in the end of init.lua in starter"; }; + chadrcConfig = mkOption { + type = types.str; + default = ""; + description = "This config replaces the chadrc.lua file. Make sure to include `local M = {}` at the top, and `return M` at the bottom."; + }; gcc = mkOption { type = types.package; default = pkgs.gcc; diff --git a/nix/nvchad.nix b/nix/nvchad.nix index 2b653ad..59b535b 100644 --- a/nix/nvchad.nix +++ b/nix/nvchad.nix @@ -20,6 +20,7 @@ tree-sitter, extraPackages ? [ ], # the default value is for import from flake.nix extraConfig ? "", + chadrcConfig ? "", starterRepo, extraPlugins ? "return {}", lazy-lock ? "", @@ -30,6 +31,7 @@ let makeBinPath licenses maintainers + optionalString ; in stdenvNoCC.mkDerivation (finalAttrs: { @@ -53,6 +55,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { end return M1 ''; + NewChadrcFile = writeText "chadrc.lua" chadrcConfig; LockFile = writeText "lazy-lock.json" lazy-lock; nativeBuildInputs = (lists.unique ( @@ -77,6 +80,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { chmod 777 $out/config chmod 777 $out/config/lua # cp make it unwritable chmod 777 $out/config/lua/plugins + ${optionalString (chadrcConfig != "") "install -Dm777 $NewChadrcFile $out/config/lua/chadrc.lua"} mv $out/config/lua/plugins/init.lua $out/config/lua/plugins/init-1.lua install -Dm777 $extraPluginsFile $out/config/lua/plugins/init-2.lua install -Dm777 $NewPluginsFile $out/config/lua/plugins/init.lua