Skip to content

Commit

Permalink
wrappers/standalone: make pkgs arg optional, allow specifying system
Browse files Browse the repository at this point in the history
  • Loading branch information
MattSturgeon committed Dec 23, 2024
1 parent 2589af1 commit acb3694
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
12 changes: 10 additions & 2 deletions flake-modules/wrappers.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{ inputs, self, ... }:
{
inputs,
self,
lib,
...
}:
{
perSystem =
{ system, pkgs, ... }:
{
_module.args = {
makeNixvimWithModule = import ../wrappers/standalone.nix pkgs self;
makeNixvimWithModule = import ../wrappers/standalone.nix {
inherit lib self;
defaultSystem = system;
};
};

checks =
Expand Down
4 changes: 2 additions & 2 deletions templates/simple/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
];

perSystem =
{ pkgs, system, ... }:
{ system, ... }:
let
nixvimLib = nixvim.lib.${system};
nixvim' = nixvim.legacyPackages.${system};
nixvimModule = {
inherit pkgs;
inherit system; # or alternatively, set `pkgs`
module = import ./config; # import the module directly
# You can use `extraSpecialArgs` to pass additional arguments to your module files
extraSpecialArgs = {
Expand Down
32 changes: 23 additions & 9 deletions wrappers/standalone.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
default_pkgs: self:
{
self,
lib,
defaultSystem,
}:
{
# TODO: Deprecate this arg in favour of using module options
pkgs ? default_pkgs,
lib ? pkgs.lib,
pkgs ? null,
# NOTE: `defaultSystem` is the only reason this function can't go in `<nixvim>.lib`
system ? defaultSystem,
extraSpecialArgs ? { },
_nixvimTests ? false,
module,
Expand All @@ -12,23 +17,32 @@ let
helpers = self.lib.nixvim.override { inherit _nixvimTests; };
inherit (helpers.modules) evalNixvim;

systemMod =
if pkgs == null then
{
_file = ./standalone.nix;
nixpkgs.hostPlatform = lib.mkDefault { inherit system; };
}
else
{
_file = ./standalone.nix;
nixpkgs.pkgs = lib.mkDefault pkgs;
};

mkNvim =
mod:
let
nixvimConfig = evalNixvim {
modules = [
mod
# TODO: only include this when `args?pkgs`:
{
_file = ./standalone.nix;
nixpkgs.pkgs = lib.mkDefault pkgs;
}
systemMod
];
inherit extraSpecialArgs;
};
inherit (nixvimConfig.config) enableMan build;
inherit (nixvimConfig._module.args.pkgs) symlinkJoin;
in
(pkgs.symlinkJoin {
(symlinkJoin {
name = "nixvim";
paths = [
build.package
Expand Down

0 comments on commit acb3694

Please sign in to comment.