mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +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 \
|
||||
${./nixvim-header-start.5} \
|
||||
${mkMDSection ../user-guide/helpers.md} \
|
||||
${mkMDSection ../user-guide/extending-config.md} \
|
||||
${mkMDSection ../user-guide/faq.md} \
|
||||
${./nixvim-header-end.5} \
|
||||
>$out/nixvim-header.5
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
- [Installation](./user-guide/install.md)
|
||||
- [Helpers](./user-guide/helpers.md)
|
||||
- [Extending a standalone configuration](./user-guide/extending-config.md)
|
||||
- [FAQ](./user-guide/faq.md)
|
||||
|
||||
# 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;
|
||||
};
|
||||
|
||||
extend = import ../tests/extend.nix {
|
||||
inherit pkgs makeNixvimWithModule;
|
||||
};
|
||||
|
||||
enable-except-in-tests = import ../tests/enable-except-in-tests.nix {
|
||||
inherit pkgs makeNixvimWithModule;
|
||||
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,19 +16,20 @@ default_pkgs: {
|
|||
config = {};
|
||||
};
|
||||
|
||||
eval = lib.evalModules {
|
||||
modules =
|
||||
[
|
||||
module
|
||||
{wrapRc = true;}
|
||||
]
|
||||
++ shared.topLevelModules;
|
||||
specialArgs =
|
||||
{
|
||||
inherit helpers;
|
||||
}
|
||||
// extraSpecialArgs;
|
||||
};
|
||||
mkEval = mod:
|
||||
lib.evalModules {
|
||||
modules =
|
||||
[
|
||||
mod
|
||||
{wrapRc = true;}
|
||||
]
|
||||
++ shared.topLevelModules;
|
||||
specialArgs =
|
||||
{
|
||||
inherit helpers;
|
||||
}
|
||||
// extraSpecialArgs;
|
||||
};
|
||||
|
||||
handleAssertions = config: let
|
||||
failedAssertions = map (x: x.message) (lib.filter (x: !x.assertion) config.assertions);
|
||||
|
@ -37,15 +38,21 @@ default_pkgs: {
|
|||
then throw "\nFailed assertions:\n${builtins.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
||||
else lib.showWarnings config.warnings config;
|
||||
|
||||
config = handleAssertions eval.config;
|
||||
mkNvim = mod: let
|
||||
config = handleAssertions (mkEval mod).config;
|
||||
in
|
||||
(pkgs.symlinkJoin {
|
||||
name = "nixvim";
|
||||
paths =
|
||||
[
|
||||
config.finalPackage
|
||||
config.printInitPackage
|
||||
]
|
||||
++ pkgs.lib.optional config.enableMan self.packages.${pkgs.system}.man-docs;
|
||||
meta.mainProgram = "nvim";
|
||||
})
|
||||
// {
|
||||
nixvimExtend = extension: mkNvim {imports = [mod extension];};
|
||||
};
|
||||
in
|
||||
pkgs.symlinkJoin {
|
||||
name = "nixvim";
|
||||
paths =
|
||||
[
|
||||
config.finalPackage
|
||||
config.printInitPackage
|
||||
]
|
||||
++ pkgs.lib.optional config.enableMan self.packages.${pkgs.system}.man-docs;
|
||||
meta.mainProgram = "nvim";
|
||||
}
|
||||
mkNvim module
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue