nvf/flake/modules/nixos.nix
Ching Pei Yang 72ae20dc3d
blink: fix missing inputs.self in HM and NixOS modules (#644)
* home-manager: fix missing inputs.self

some options in nvf module uses inputs.self but it's not exposed in the
inputs we pass to home-manager module:

example flake.nix:

```
{
	inputs = { /* ... */ };
	outputs = {nixpkgs, ...}@inputs: {
		testing = {
			a = inputs.self             # valid
			b = inputs.self.inputs      # valid
			c = inputs.self.inputs.self # does not exist

			# prior to this change, inputs.self.inputs was passed to the hm
			# module, which lacks the self attr
			#
			# This change passes in the "top-level" inputs instead.
		};
	};
}
```

* nixos: fix missing inputs.self

see previous commit for details
2025-02-16 11:35:13 +00:00

97 lines
2.3 KiB
Nix

# NixOS module
{
inputs,
lib,
}: {
config,
pkgs,
...
}: let
inherit (inputs.self) packages;
inherit (lib) maintainers;
inherit (lib.modules) mkIf mkOverride mkAliasOptionModule;
inherit (lib.lists) optional;
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) anything bool submoduleWith;
cfg = config.programs.nvf;
nvfModule = submoduleWith {
description = "Nvf module";
class = "nvf";
specialArgs = {
inherit pkgs lib inputs;
};
modules = import ../../modules/modules.nix {inherit pkgs lib;};
};
in {
imports = [
(mkAliasOptionModule ["programs" "neovim-flake"] ["programs" "nvf"])
];
meta.maintainers = with maintainers; [NotAShelf];
options.programs.nvf = {
enable = mkEnableOption "nvf, the extensible neovim configuration wrapper";
enableManpages = mkOption {
type = bool;
default = false;
description = "Whether to enable manpages for nvf.";
};
defaultEditor = mkOption {
type = bool;
default = false;
description = ''
Whether to set `nvf` as the default editor.
This will set the `EDITOR` environment variable as `nvim`
if set to true.
'';
};
finalPackage = mkOption {
type = anything;
visible = false;
readOnly = true;
description = ''
The built nvf package, wrapped with the user's configuration.
'';
};
settings = mkOption {
type = nvfModule;
default = {};
description = "Attribute set of nvf preferences.";
example = literalExpression ''
{
vim.viAlias = false;
vim.vimAlias = true;
vim.lsp = {
enable = true;
formatOnSave = true;
lightbulb.enable = true;
lspsaga.enable = false;
trouble.enable = true;
lspSignature.enable = true;
rust.enable = false;
nix = true;
};
}
'';
};
};
config = mkIf cfg.enable {
programs.nvf.finalPackage = cfg.settings.vim.build.finalPackage;
environment = {
variables.EDITOR = mkIf cfg.defaultEditor (mkOverride 900 "nvim");
systemPackages =
[cfg.finalPackage]
++ optional cfg.enableManpages packages.${pkgs.stdenv.system}.docs-manpages;
};
};
_file = ./nixos.nix;
}