Skip to content

Commit

Permalink
lib: include standalone wrapper in top-level lib
Browse files Browse the repository at this point in the history
- Defragment lib-related flake-modules
- Expose the standalone-wrapper functions in the `lib`
  • Loading branch information
MattSturgeon committed Sep 7, 2024
1 parent 86a4021 commit 7aa0fa3
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 46 deletions.
2 changes: 0 additions & 2 deletions flake-modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
{
imports = [
./dev
./helpers.nix
./lib.nix
./legacy-packages.nix
./overlays.nix
./packages.nix
./templates.nix
Expand Down
7 changes: 0 additions & 7 deletions flake-modules/helpers.nix

This file was deleted.

15 changes: 0 additions & 15 deletions flake-modules/legacy-packages.nix

This file was deleted.

29 changes: 25 additions & 4 deletions flake-modules/lib.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
{
self,
config,
lib,
withSystem,
getSystem,
...
}:
{
flake.lib = lib.genAttrs config.systems (
lib.flip withSystem ({ pkgs, ... }: import ../lib { inherit pkgs lib; })
);
perSystem =
{ self', pkgs, ... }:
{
# `helpers` is used throughout the flake modules
_module.args = {
inherit (self'.lib) helpers;
};

legacyPackages = {
# Export nixvim's lib in legacyPackages
lib = import ../lib {
inherit pkgs lib;
flake = self;
};

# Historically, we exposed these at the top-level of legacyPackages
# TODO: Consider renaming the new location, and keeping the old name here?
inherit (self'.legacyPackages.lib) makeNixvimWithModule makeNixvim;
};
};

# Also expose `legacyPackages.<system>.lib` as `lib.<system>`
flake.lib = lib.genAttrs config.systems (system: (getSystem system).legacyPackages.lib);
}
18 changes: 7 additions & 11 deletions flake-modules/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,35 @@
{
perSystem =
{
self',
pkgs,
pkgsUnfree,
system,
helpers,
makeNixvimWithModule,
...
}:
let
inherit (self'.legacyPackages.lib) helpers makeNixvimWithModule;
inherit (self'.legacyPackages.lib.check) mkTestDerivationFromNvim mkTestDerivationFromNixvimModule;
evaluatedNixvim = helpers.modules.evalNixvim { check = false; };
in
{
checks = {
extra-args-tests = import ../tests/extra-args.nix {
inherit pkgs;
inherit makeNixvimWithModule;
};
extra-args-tests = import ../tests/extra-args.nix { inherit pkgs makeNixvimWithModule; };

extend = import ../tests/extend.nix { inherit pkgs makeNixvimWithModule; };

extra-files = import ../tests/extra-files.nix { inherit pkgs makeNixvimWithModule; };

enable-except-in-tests = import ../tests/enable-except-in-tests.nix {
inherit pkgs makeNixvimWithModule;
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule;
inherit pkgs makeNixvimWithModule mkTestDerivationFromNixvimModule;
};

failing-tests = pkgs.callPackage ../tests/failing-tests.nix {
inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule;
inherit mkTestDerivationFromNixvimModule;
};

no-flake = import ../tests/no-flake.nix {
inherit system;
inherit (self.lib.${system}.check) mkTestDerivationFromNvim;
inherit system mkTestDerivationFromNvim;
nixvim = "${self}";
};

Expand Down
4 changes: 0 additions & 4 deletions flake-modules/wrappers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
perSystem =
{ system, pkgs, ... }:
{
_module.args = {
makeNixvimWithModule = import ../wrappers/standalone.nix pkgs self;
};

checks =
{
home-manager-module =
Expand Down
10 changes: 7 additions & 3 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Args probably only needs pkgs and lib
{
flake,
pkgs,
lib ? pkgs.lib,
_nixvimTests ? false,
...
}@args:
{
lib.fix (self: {
# Add all exported modules here
check = import ./tests.nix { inherit lib pkgs; };
helpers = import ./helpers.nix (args // { inherit _nixvimTests; });
}

# TODO: Consider renaming these?
makeNixvimWithModule = import ../wrappers/standalone.nix pkgs flake;
makeNixvim = module: self.makeNixvimWithModule { inherit module; };
})

0 comments on commit 7aa0fa3

Please sign in to comment.