Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions flake/wrappers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@
...
}:
let
inherit (lib.modules) importApply;
# Added 2025-05-25; warning shown since 2025-08-01 (25.11)
# NOTE: top-level binding of a fully resolved value, to avoid printing multiple times
homeManagerModulesWarning = lib.warn "nixvim: flake output `homeManagerModules` has been renamed to `homeModules`." null;

# A base configuration used to evaluate the wrapper modules.
#
# While we don't define a `pkgs` or `hostPlatform` here, which would normally
# lead to eval errors, disabling option-declaration checking gives us enough
# laziness to evaluate the options we need.
#
# The `_module.check` module has a key, so we can disable it later in the
# platform wrapper modules.
configuration = self.lib.evalNixvim {
modules = [
{
key = "<internal:nixvim-nocheck-base-eval>";
config._module.check = false;
}
];
};
in
{
perSystem =
Expand All @@ -27,17 +43,17 @@ in

flake = {
nixosModules = {
nixvim = importApply ../wrappers/nixos.nix self;
nixvim = configuration.config.build.nixosModule;
default = self.nixosModules.nixvim;
};
# Alias for backward compatibility
homeManagerModules = lib.mapAttrs (_: lib.seq homeManagerModulesWarning) self.homeModules;
homeModules = {
nixvim = importApply ../wrappers/hm.nix self;
nixvim = configuration.config.build.homeModule;
default = self.homeModules.nixvim;
};
nixDarwinModules = {
nixvim = importApply ../wrappers/darwin.nix self;
nixvim = configuration.config.build.nixDarwinModule;
default = self.nixDarwinModules.nixvim;
};
};
Expand Down
1 change: 1 addition & 0 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
./output.nix
./performance.nix
./plugins.nix
./wrappers.nix
];
}
40 changes: 40 additions & 0 deletions modules/wrappers.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
lib,
extendModules,
config,
...
}:
{
options.build = {
nixosModule = lib.mkOption {
type = lib.types.deferredModule;
description = "A NixOS module that installs this Nixvim configuration.";
readOnly = true;
};
homeModule = lib.mkOption {
type = lib.types.deferredModule;
description = "A Home Manager module that installs this Nixvim configuration.";
readOnly = true;
};
nixDarwinModule = lib.mkOption {
type = lib.types.deferredModule;
description = "A nix-darwin module that installs this Nixvim configuration.";
readOnly = true;
};
};

config.build = {
nixosModule = lib.modules.importApply ../wrappers/nixos.nix {
self = config.flake;
inherit extendModules;
};
homeModule = lib.modules.importApply ../wrappers/hm.nix {
self = config.flake;
inherit extendModules;
};
nixDarwinModule = lib.modules.importApply ../wrappers/darwin.nix {
self = config.flake;
inherit extendModules;
};
};
}
19 changes: 9 additions & 10 deletions wrappers/_shared.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
# The nixvim flake
self,
# Extra args for the `evalNixvim` call that produces the type for `programs.nixvim`
evalArgs ? { },
# Function used to evaluate the `programs.nixvim` configuration
extendModules,
# Option path where extraFiles should go
filesOpt ? null,
# Filepath prefix to apply to extraFiles
Expand Down Expand Up @@ -45,14 +45,13 @@ let
};
};

nixvimConfiguration = config.lib.nixvim.modules.evalNixvim (
evalArgs
// {
modules = evalArgs.modules or [ ] ++ [
nixpkgsModule
];
}
);
nixvimConfiguration = extendModules {
modules = [
nixpkgsModule
{ disabledModules = [ "<internal:nixvim-nocheck-base-eval>" ]; }
];
};

extraFiles = lib.filter (file: file.enable) (lib.attrValues cfg.extraFiles);
in
{
Expand Down
26 changes: 16 additions & 10 deletions wrappers/darwin.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
self:
{
self,
extendModules,
}:
{
config,
lib,
Expand All @@ -12,19 +15,22 @@ let
importApply
;
cfg = config.programs.nixvim;
evalArgs = {
extraSpecialArgs = {
darwinConfig = config;
};
modules = [
./modules/darwin.nix
];
};
in
{
_file = ./darwin.nix;

imports = [ (importApply ./_shared.nix { inherit self evalArgs; }) ];
imports = [
(importApply ./_shared.nix {
inherit self;
inherit
(extendModules {
specialArgs.darwinConfig = config;
modules = [ ./modules/darwin.nix ];
})
extendModules
;
})
];

config = mkIf cfg.enable {
environment.systemPackages = [
Expand Down
22 changes: 12 additions & 10 deletions wrappers/hm.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
self:
{
self,
extendModules,
}:
{
config,
lib,
Expand All @@ -9,21 +12,20 @@ let
mkIf
;
cfg = config.programs.nixvim;
evalArgs = {
extraSpecialArgs = {
hmConfig = config;
};
modules = [
./modules/hm.nix
];
};
in
{
_file = ./hm.nix;

imports = [
(import ./_shared.nix {
inherit self evalArgs;
inherit self;
inherit
(extendModules {
specialArgs.hmConfig = config;
modules = [ ./modules/hm.nix ];
})
extendModules
;
filesOpt = [
"xdg"
"configFile"
Expand Down
22 changes: 12 additions & 10 deletions wrappers/nixos.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
self:
{
self,
extendModules,
}:
{
config,
lib,
Expand All @@ -9,21 +12,20 @@ let
mkIf
;
cfg = config.programs.nixvim;
evalArgs = {
extraSpecialArgs = {
nixosConfig = config;
};
modules = [
./modules/nixos.nix
];
};
in
{
_file = ./nixos.nix;

imports = [
(import ./_shared.nix {
inherit self evalArgs;
inherit self;
inherit
(extendModules {
specialArgs.nixosConfig = config;
modules = [ ./modules/nixos.nix ];
})
extendModules
;
filesOpt = [
"environment"
"etc"
Expand Down