Skip to content

Commit

Permalink
lib: make overrideable & access via flake
Browse files Browse the repository at this point in the history
Add a non-system specific `<flake>.lib.nixvim` output, which is
equivalent to the existing `<flake>.lib.<system>.helpers` output.

This is now also wrapped with `lib.makeOverridable` to allow overriding
the function args used to construct the nixvim-lib.

Consistently access nixvim-lib via the new flake output, overriding
where necessary.
  • Loading branch information
MattSturgeon committed Dec 21, 2024
1 parent e2ef15a commit 4b3b67f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 35 deletions.
2 changes: 1 addition & 1 deletion docs/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
helpers,
system,
nixpkgs,
nuschtosSearch,
Expand All @@ -7,7 +8,6 @@ let
# We overlay a few tweaks into pkgs, for use in the docs
pkgs = import ./pkgs.nix { inherit system nixpkgs; };
inherit (pkgs) lib;
helpers = import ../lib { inherit lib; };

nixvimPath = toString ./..;

Expand Down
41 changes: 23 additions & 18 deletions flake-modules/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@
...
}:
{
_module.args.helpers = import ../lib {
inherit lib;
flake = self;
# Expose lib as a flake-parts module arg
_module.args = {
helpers = self.lib.nixvim;
};

# TODO: output lib without pkgs at the top-level
flake.lib = lib.genAttrs config.systems (
lib.flip withSystem (
{ pkgs, ... }:
{
# NOTE: this is the publicly documented flake output we've had for a while
check = import ../lib/tests.nix { inherit self lib pkgs; };
# TODO: no longer needs to be per-system
helpers = import ../lib {
inherit lib;
flake = self;
};
}
)
);
# Public `lib` flake output
flake.lib =
{
nixvim = lib.makeOverridable (import ../lib) {
inherit lib;
flake = self;
};
}
// lib.genAttrs config.systems (
lib.flip withSystem (
{ pkgs, ... }:
{
# NOTE: this is the publicly documented flake output we've had for a while
check = pkgs.callPackage ../lib/tests.nix { inherit self; };

# NOTE: no longer needs to be per-system
helpers = self.lib.nixvim;
}
)
);
}
7 changes: 6 additions & 1 deletion flake-modules/packages.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{ inputs, ... }:
{
inputs,
helpers,
...
}:
{
perSystem =
{
Expand All @@ -9,6 +13,7 @@
}:
{
packages = import ../docs {
inherit helpers;
inherit system;
inherit (inputs) nixpkgs;
inherit (inputs') nuschtosSearch;
Expand Down
4 changes: 1 addition & 3 deletions lib/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ let
}@args:
let
# NOTE: we are importing this just for evalNixvim
helpers = import ../lib {
inherit lib;
flake = self;
helpers = self.lib.nixvim.override {
# TODO: deprecate helpers.enableExceptInTests,
# add a context option e.g. `config.isTest`?
_nixvimTests = true;
Expand Down
8 changes: 1 addition & 7 deletions wrappers/_shared.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ in
config = mkMerge [
{
# Make our lib available to the host modules
# NOTE: user-facing so we must include the legacy `pkgs` argument
lib.nixvim = lib.mkDefault (
import ../lib {
inherit lib;
flake = self;
}
);
lib.nixvim = lib.mkDefault self.lib.nixvim;

# Make nixvim's "extended" lib available to the host's module args
_module.args.nixvimLib = lib.mkDefault config.lib.nixvim.extendedLib;
Expand Down
6 changes: 1 addition & 5 deletions wrappers/standalone.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ default_pkgs: self:
}:
let
# NOTE: we are importing this just for evalNixvim
helpers = import ../lib {
inherit lib _nixvimTests;
flake = self;
};

helpers = self.lib.nixvim.override { inherit _nixvimTests; };
inherit (helpers.modules) evalNixvim;

mkNvim =
Expand Down

0 comments on commit 4b3b67f

Please sign in to comment.