mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
standalone: Allow to extend a standalone derivation with a new module (#1142)
This adds the `nixvimExtend` attribute to the generated standalone derivation, this attribute takes a module as an argument and returns a new standalone derivation with the initial module & the extended module merged together.
This commit is contained in:
parent
66c019d638
commit
9cd3721adf
6 changed files with 91 additions and 24 deletions
|
@ -34,6 +34,7 @@
|
||||||
cat \
|
cat \
|
||||||
${./nixvim-header-start.5} \
|
${./nixvim-header-start.5} \
|
||||||
${mkMDSection ../user-guide/helpers.md} \
|
${mkMDSection ../user-guide/helpers.md} \
|
||||||
|
${mkMDSection ../user-guide/extending-config.md} \
|
||||||
${mkMDSection ../user-guide/faq.md} \
|
${mkMDSection ../user-guide/faq.md} \
|
||||||
${./nixvim-header-end.5} \
|
${./nixvim-header-end.5} \
|
||||||
>$out/nixvim-header.5
|
>$out/nixvim-header.5
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
- [Installation](./user-guide/install.md)
|
- [Installation](./user-guide/install.md)
|
||||||
- [Helpers](./user-guide/helpers.md)
|
- [Helpers](./user-guide/helpers.md)
|
||||||
|
- [Extending a standalone configuration](./user-guide/extending-config.md)
|
||||||
- [FAQ](./user-guide/faq.md)
|
- [FAQ](./user-guide/faq.md)
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
|
|
26
docs/user-guide/extending-config.md
Normal file
26
docs/user-guide/extending-config.md
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# Extending a standalone configuration
|
||||||
|
|
||||||
|
Given a `nvim` derivation obtained from `makeNixvim` or `makeNivxmiWithModule` it is possible to create a new derivation with additional options.
|
||||||
|
|
||||||
|
This is done through the `nvim.nixvimExtend` function. This function takes a NixOS module that is going to be merged with the currently set options.
|
||||||
|
|
||||||
|
This attribute is recursive, meaning that it can be applied an arbitrary number of times.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{makeNixvimWithModule}: let
|
||||||
|
first = makeNixvimWithModule {
|
||||||
|
module = {
|
||||||
|
extraConfigLua = "-- first stage";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
second = first.nixvimExtend {extraConfigLua = "-- second stage";};
|
||||||
|
|
||||||
|
third = second.nixvimExtend {extraConfigLua = "-- third stage";};
|
||||||
|
in
|
||||||
|
third
|
||||||
|
```
|
||||||
|
|
||||||
|
This will generate a `init.lua` that will contain the three comments from each stages.
|
|
@ -25,6 +25,10 @@
|
||||||
inherit makeNixvimWithModule;
|
inherit makeNixvimWithModule;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extend = import ../tests/extend.nix {
|
||||||
|
inherit pkgs makeNixvimWithModule;
|
||||||
|
};
|
||||||
|
|
||||||
enable-except-in-tests = import ../tests/enable-except-in-tests.nix {
|
enable-except-in-tests = import ../tests/enable-except-in-tests.nix {
|
||||||
inherit pkgs makeNixvimWithModule;
|
inherit pkgs makeNixvimWithModule;
|
||||||
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule;
|
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule;
|
||||||
|
|
28
tests/extend.nix
Normal file
28
tests/extend.nix
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
makeNixvimWithModule,
|
||||||
|
pkgs,
|
||||||
|
}: let
|
||||||
|
firstStage = makeNixvimWithModule {
|
||||||
|
module = {
|
||||||
|
extraConfigLua = "-- first stage";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
secondStage = firstStage.nixvimExtend {extraConfigLua = "-- second stage";};
|
||||||
|
|
||||||
|
generated = secondStage.nixvimExtend {extraConfigLua = "-- third stage";};
|
||||||
|
in
|
||||||
|
pkgs.runCommand "extend-test" {
|
||||||
|
printConfig = "${generated}/bin/nixvim-print-init";
|
||||||
|
} ''
|
||||||
|
config=$($printConfig)
|
||||||
|
for stage in "first" "second" "third"; do
|
||||||
|
if ! "$printConfig" | grep -q -- "-- $stage stage"; then
|
||||||
|
echo "Missing $stage stage in config"
|
||||||
|
echo "$config"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
touch $out
|
||||||
|
''
|
|
@ -16,10 +16,11 @@ default_pkgs: {
|
||||||
config = {};
|
config = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
eval = lib.evalModules {
|
mkEval = mod:
|
||||||
|
lib.evalModules {
|
||||||
modules =
|
modules =
|
||||||
[
|
[
|
||||||
module
|
mod
|
||||||
{wrapRc = true;}
|
{wrapRc = true;}
|
||||||
]
|
]
|
||||||
++ shared.topLevelModules;
|
++ shared.topLevelModules;
|
||||||
|
@ -37,9 +38,10 @@ default_pkgs: {
|
||||||
then throw "\nFailed assertions:\n${builtins.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
then throw "\nFailed assertions:\n${builtins.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
||||||
else lib.showWarnings config.warnings config;
|
else lib.showWarnings config.warnings config;
|
||||||
|
|
||||||
config = handleAssertions eval.config;
|
mkNvim = mod: let
|
||||||
in
|
config = handleAssertions (mkEval mod).config;
|
||||||
pkgs.symlinkJoin {
|
in
|
||||||
|
(pkgs.symlinkJoin {
|
||||||
name = "nixvim";
|
name = "nixvim";
|
||||||
paths =
|
paths =
|
||||||
[
|
[
|
||||||
|
@ -48,4 +50,9 @@ in
|
||||||
]
|
]
|
||||||
++ pkgs.lib.optional config.enableMan self.packages.${pkgs.system}.man-docs;
|
++ pkgs.lib.optional config.enableMan self.packages.${pkgs.system}.man-docs;
|
||||||
meta.mainProgram = "nvim";
|
meta.mainProgram = "nvim";
|
||||||
}
|
})
|
||||||
|
// {
|
||||||
|
nixvimExtend = extension: mkNvim {imports = [mod extension];};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
mkNvim module
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue