standalone: rename nixvimExtend to extend

This is our scope, so there's no need to be explicit.

This also follows the precedent set by `lib.extend`, although that takes
an overlay function.
This commit is contained in:
Matt Sturgeon 2024-07-01 14:20:12 +01:00
parent 3bfe71f1ae
commit 55fee7051f
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 20 additions and 19 deletions

View file

@ -24,34 +24,34 @@ The example assumes your standalone config is the `default` package of a flake,
## Extending an existing configuration ## Extending an existing configuration
Given a `nvim` derivation obtained from `makeNixvim` or `makeNivxmiWithModule` it is possible to create a new derivation with additional options. Given a `<nixvim>` 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 is done through the `<nixvim>.extend` function. This function takes a Nixvim module that is merged with the options used to build `<nixvim>`.
This attribute is recursive, meaning that it can be applied an arbitrary number of times. This function is recursive, meaning that it can be applied an arbitrary number of times.
### Example ### Example
```nix ```nix
{makeNixvimWithModule}: let {makeNixvim}: let
first = makeNixvimWithModule { first = makeNixvim { extraConfigLua = "-- first stage"; };
module = { second = first.extend {extraConfigLua = "-- second stage";};
extraConfigLua = "-- first stage"; third = second.extend {extraConfigLua = "-- third stage";};
};
};
second = first.nixvimExtend {extraConfigLua = "-- second stage";};
third = second.nixvimExtend {extraConfigLua = "-- third stage";};
in in
third third
``` ```
This will generate a `init.lua` that will contain the three comments from each stages. This will generate a `init.lua` that will contain the comments from each stages:
```lua
-- first stage
-- second stage
-- third stage
```
## Accessing options used in an existing configuration ## Accessing options used in an existing configuration
The `config` used to produce a standalone nixvim derivation can be accessed as an attribute on the derivation, similar to `nixvimExtend`. The `config` used to produce a standalone nixvim derivation can be accessed as an attribute on the derivation, similar to `<nixvim>.extend`.
This may be useful if you want unrelated parts of your NixOS or home-manager configuration to use the same value as something in your nixvim configuration. This may be useful if you want unrelated parts of your NixOS or home-manager configuration to use the same value as something in your nixvim configuration.

View file

@ -6,9 +6,9 @@ let
}; };
}; };
secondStage = firstStage.nixvimExtend { extraConfigLua = "-- second stage"; }; secondStage = firstStage.extend { extraConfigLua = "-- second stage"; };
generated = secondStage.nixvimExtend { extraConfigLua = "-- third stage"; }; generated = secondStage.extend { extraConfigLua = "-- third stage"; };
in in
pkgs.runCommand "extend-test" { printConfig = "${generated}/bin/nixvim-print-init"; } '' pkgs.runCommand "extend-test" { printConfig = "${generated}/bin/nixvim-print-init"; } ''
config=$($printConfig) config=$($printConfig)

View file

@ -55,10 +55,10 @@ let
] ++ pkgs.lib.optional config.enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs; ] ++ pkgs.lib.optional config.enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs;
meta.mainProgram = "nvim"; meta.mainProgram = "nvim";
}) })
// { // rec {
inherit config; inherit config;
inherit (evaledModule) options; inherit (evaledModule) options;
nixvimExtend = extend =
extension: extension:
mkNvim { mkNvim {
imports = [ imports = [
@ -66,6 +66,7 @@ let
extension extension
]; ];
}; };
nixvimExtend = lib.warn "<nixvim>.nixvimExtend has been renamed to <nixvim>.extend" extend;
}; };
in in
mkNvim module mkNvim module