2024-01-25 14:49:57 +00:00
|
|
|
{ inputs
|
|
|
|
, lib
|
|
|
|
, config
|
2024-07-16 05:47:41 +00:00
|
|
|
, options
|
2024-01-25 14:49:57 +00:00
|
|
|
|
2024-01-28 03:44:39 +00:00
|
|
|
, ...
|
|
|
|
}:
|
2024-01-25 14:49:57 +00:00
|
|
|
|
|
|
|
let
|
2024-07-22 12:10:17 +00:00
|
|
|
partsConfig = config;
|
2024-01-25 14:49:57 +00:00
|
|
|
cfg = config.setups.nixvim;
|
2024-01-26 01:38:31 +00:00
|
|
|
nixvimModules = ../../nixvim;
|
2024-01-25 14:49:57 +00:00
|
|
|
|
2024-07-10 07:49:29 +00:00
|
|
|
mkNixvimConfig = {
|
|
|
|
system,
|
|
|
|
pkgs,
|
|
|
|
nixvimBranch ? "nixvim",
|
|
|
|
modules ? [ ],
|
|
|
|
specialArgs ? { },
|
|
|
|
}:
|
2024-06-10 05:25:03 +00:00
|
|
|
inputs.${nixvimBranch}.legacyPackages.${system}.makeNixvimWithModule {
|
2024-01-25 14:49:57 +00:00
|
|
|
inherit pkgs;
|
|
|
|
module = {
|
|
|
|
imports = modules;
|
|
|
|
};
|
2024-07-10 07:49:29 +00:00
|
|
|
extraSpecialArgs = specialArgs // {
|
2024-01-26 01:38:31 +00:00
|
|
|
foodogsquaredModulesPath = builtins.toString nixvimModules;
|
|
|
|
};
|
2024-01-25 14:49:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
modulesOption = lib.mkOption {
|
2024-03-27 08:34:51 +00:00
|
|
|
type = with lib.types; listOf deferredModule;
|
2024-02-02 04:40:16 +00:00
|
|
|
default = [ ];
|
2024-01-25 14:49:57 +00:00
|
|
|
};
|
|
|
|
modulesOption' = configEnv: modulesOption // {
|
|
|
|
description = ''
|
|
|
|
A list of NixVim modules to be applied across all NixVim configurations
|
|
|
|
when imported as part of ${configEnv}.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-11 08:39:16 +00:00
|
|
|
componentType = { lib, config, ... }: {
|
2024-07-16 05:47:41 +00:00
|
|
|
imports = [
|
|
|
|
./shared/nixpkgs-options.nix
|
|
|
|
(lib.mkAliasOptionModule [ "overlays" ] [ "nixpkgs" "overlays" ])
|
|
|
|
];
|
2024-01-28 03:44:39 +00:00
|
|
|
|
2024-07-16 05:47:41 +00:00
|
|
|
options = {
|
2024-06-10 05:25:03 +00:00
|
|
|
nixvimBranch = lib.mkOption {
|
|
|
|
type = lib.types.nonEmptyStr;
|
|
|
|
default = "nixvim";
|
|
|
|
example = "nixvim-unstable";
|
|
|
|
description = ''
|
2024-06-11 08:39:16 +00:00
|
|
|
The NixVim branch to be used for the NixVim configuration.
|
|
|
|
|
|
|
|
It is recommend to match the NixVim branch with the nixpkgs branch.
|
|
|
|
For example, a NixVim configuration of `nixos-24.05` should be paired
|
|
|
|
with nixpkgs `nixos-24.05` branch.
|
|
|
|
|
|
|
|
::: {.note}
|
|
|
|
This refers to your flake inputs so in order to support multiple
|
|
|
|
NixVim branches, you need to import multiple NixVim branches as part
|
|
|
|
of the `inputs` flake attribute.
|
|
|
|
:::
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
neovimPackage = lib.mkOption {
|
|
|
|
type = with lib.types; functionTo package;
|
|
|
|
default = pkgs: pkgs.neovim;
|
|
|
|
defaultText = "pkgs: pkgs.neovim";
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
pkgs: pkgs.neovim-nightly
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
The package to be used for the NixVim configuration. Since this is
|
|
|
|
used per-system, it has to be a function returning a package from the
|
|
|
|
given nixpkgs instance.
|
2024-06-10 05:25:03 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-07-16 05:47:41 +00:00
|
|
|
};
|
2024-06-10 05:25:03 +00:00
|
|
|
|
2024-07-16 05:47:41 +00:00
|
|
|
config = {
|
|
|
|
nixpkgs.config = cfg.sharedNixpkgsConfig;
|
2024-01-25 14:49:57 +00:00
|
|
|
};
|
2024-06-11 08:39:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
configType = { name, lib, config, ... }: {
|
|
|
|
options = {
|
|
|
|
components = lib.mkOption {
|
|
|
|
type = with lib.types; listOf (submodule componentType);
|
|
|
|
description = ''
|
|
|
|
A list of specific components for the NixVim configuration to be
|
|
|
|
built against.
|
|
|
|
'';
|
|
|
|
example = [
|
|
|
|
{ nixpkgsBranch = "nixos-unstable"; nixvimBranch = "nixvim-unstable"; }
|
|
|
|
{ nixpkgsBranch = "nixos-stable"; nixvimBranch = "nixvim-stable"; }
|
|
|
|
{ nixpkgsBranch = "nixos-stable"; nixvimBranch = "nixvim-stable"; neovimPackage = pkgs: pkgs.neovim-nightly; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2024-01-25 14:49:57 +00:00
|
|
|
|
|
|
|
config = {
|
|
|
|
modules = [
|
2024-02-14 13:14:06 +00:00
|
|
|
../../../configs/nixvim/${config.configName}
|
2024-01-25 14:49:57 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2024-07-22 12:10:17 +00:00
|
|
|
|
|
|
|
nixvimIntegrationModule = { name, config, lib, ... }: {
|
|
|
|
options.nixvim = {
|
|
|
|
instance = lib.mkOption {
|
|
|
|
type = with lib.types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
example = "fiesta";
|
|
|
|
description = ''
|
|
|
|
The name of the NixVim configuration from
|
|
|
|
{option}`setups.nixvim.configs.<name>` to be included as part
|
|
|
|
of the wider-scoped environment.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
branch = lib.mkOption {
|
|
|
|
type = lib.types.nonEmptyStr;
|
|
|
|
default = "nixvim";
|
|
|
|
example = "nixvim-stable";
|
|
|
|
description = ''
|
|
|
|
The branch of NixVim to be used for the module.
|
|
|
|
|
|
|
|
::: {.tip}
|
|
|
|
A rule of thumb for properly setting up NixVim with the wider-scoped
|
|
|
|
environment is it should match the nixpkgs version of it. For example,
|
|
|
|
a NixOS system of `nixos-23.11` nixpkgs branch should be paired with a NixVim
|
|
|
|
branch of `nixos-23.11`.
|
|
|
|
:::
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
additionalModules = lib.mkOption {
|
|
|
|
type = with lib.types; listOf raw;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
A list of additional NixVim modules to be included.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf (config.nixvim.instance != null) {
|
|
|
|
modules = [
|
|
|
|
({ lib, ... }: {
|
|
|
|
programs.nixvim = { ... }: {
|
|
|
|
enable = lib.mkDefault true;
|
|
|
|
imports =
|
|
|
|
partsConfig.setups.nixvim.configs.${config.nixvim.instance}.modules
|
|
|
|
++ partsConfig.setups.nixvim.sharedModules
|
|
|
|
++ config.nixvim.additionalModules;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2024-01-25 14:49:57 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.setups.nixvim = {
|
|
|
|
configs = lib.mkOption {
|
2024-07-22 13:23:52 +00:00
|
|
|
type = with lib.types; attrsOf (submodule [
|
|
|
|
(import ./shared/config-options.nix { inherit (config) systems; })
|
|
|
|
configType
|
|
|
|
]);
|
2024-02-02 04:40:16 +00:00
|
|
|
default = { };
|
2024-01-25 14:49:57 +00:00
|
|
|
description = ''
|
|
|
|
A set of NixVim configurations to be integrated into the declarative
|
|
|
|
setups configuration. Each of them will be available as part of
|
|
|
|
`nixvimConfigurations`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sharedModules = modulesOption // {
|
|
|
|
description = ''
|
|
|
|
A list of NixVim modules to be shared across all of the NixVim
|
2024-06-10 05:26:14 +00:00
|
|
|
configurations. This is also to be shared among wider-scoped
|
|
|
|
environments when NixVim-specific integrations has been enabled.
|
2024-01-25 14:49:57 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
standaloneConfigModules = modulesOption' "standalone configuration";
|
2024-07-16 05:47:41 +00:00
|
|
|
|
|
|
|
sharedNixpkgsConfig = options.setups.sharedNixpkgsConfig // {
|
|
|
|
description = ''
|
|
|
|
nixpkgs configuration to be shared among the declared NixVim instances.
|
|
|
|
'';
|
|
|
|
};
|
2024-01-25 14:49:57 +00:00
|
|
|
};
|
|
|
|
|
2024-07-22 12:10:17 +00:00
|
|
|
options.setups.nixos.configs = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (submodule [
|
|
|
|
nixvimIntegrationModule
|
|
|
|
({ config, lib, ... }: {
|
|
|
|
config.modules = [
|
|
|
|
inputs.${config.nixvim.branch}.nixosModules.nixvim
|
|
|
|
];
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
|
|
|
|
options.setups.home-manager.configs = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (submodule [
|
|
|
|
nixvimIntegrationModule
|
|
|
|
({ config, lib, ... }: {
|
|
|
|
config.modules = [
|
|
|
|
inputs.${config.nixvim.branch}.homeManagerModules.nixvim
|
|
|
|
];
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
|
2024-02-02 04:40:16 +00:00
|
|
|
config = lib.mkIf (cfg.configs != { }) {
|
2024-07-16 05:47:41 +00:00
|
|
|
setups.nixvim.sharedNixpkgsConfig = config.setups.sharedNixpkgsConfig;
|
|
|
|
|
2024-02-11 07:16:25 +00:00
|
|
|
setups.nixvim.sharedModules = [
|
|
|
|
nixvimModules
|
2024-03-03 23:44:10 +00:00
|
|
|
|
|
|
|
# Import our private modules.
|
|
|
|
../../nixvim/_private
|
2024-02-11 07:16:25 +00:00
|
|
|
];
|
2024-01-26 01:38:31 +00:00
|
|
|
|
2024-01-25 14:49:57 +00:00
|
|
|
perSystem = { system, config, lib, ... }:
|
|
|
|
(
|
|
|
|
let
|
|
|
|
validConfigs = lib.filterAttrs
|
2024-02-02 04:40:16 +00:00
|
|
|
(_: metadata: lib.elem system metadata.systems)
|
|
|
|
cfg.configs;
|
2024-01-25 14:49:57 +00:00
|
|
|
|
|
|
|
nixvimConfigurations =
|
|
|
|
let
|
|
|
|
generateNixvimConfigs = name: metadata:
|
|
|
|
let
|
2024-06-11 08:39:16 +00:00
|
|
|
mkNixvimConfig' = component:
|
2024-01-28 03:44:39 +00:00
|
|
|
let
|
2024-06-11 08:39:16 +00:00
|
|
|
pkgs = import inputs.${component.nixpkgsBranch} {
|
2024-07-16 05:47:41 +00:00
|
|
|
inherit (component.nixpkgs) config overlays;
|
2024-01-28 03:44:39 +00:00
|
|
|
inherit system;
|
|
|
|
};
|
2024-06-11 08:39:16 +00:00
|
|
|
neovimPackage = component.neovimPackage pkgs;
|
2024-01-28 03:44:39 +00:00
|
|
|
in
|
2024-06-11 08:39:16 +00:00
|
|
|
lib.nameValuePair
|
|
|
|
"${name}-${component.nixpkgsBranch}-${neovimPackage.pname}"
|
|
|
|
(mkNixvimConfig {
|
|
|
|
inherit system pkgs;
|
|
|
|
inherit (component) nixvimBranch;
|
|
|
|
modules =
|
|
|
|
cfg.sharedModules
|
|
|
|
++ cfg.standaloneConfigModules
|
|
|
|
++ metadata.modules
|
|
|
|
++ [{ package = neovimPackage; }];
|
|
|
|
});
|
|
|
|
nixvimConfigs = builtins.map mkNixvimConfig' metadata.components;
|
2024-01-25 14:49:57 +00:00
|
|
|
in
|
|
|
|
lib.listToAttrs nixvimConfigs;
|
|
|
|
in
|
|
|
|
lib.concatMapAttrs generateNixvimConfigs validConfigs;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
# We'll reuse these.
|
|
|
|
inherit nixvimConfigurations;
|
|
|
|
|
|
|
|
checks =
|
|
|
|
lib.mapAttrs'
|
|
|
|
(name: nvim:
|
|
|
|
lib.nameValuePair
|
|
|
|
"nixvim-check-${name}"
|
|
|
|
(inputs.nixvim.lib.${system}.check.mkTestDerivationFromNvim {
|
2024-02-02 04:40:16 +00:00
|
|
|
inherit nvim;
|
|
|
|
name = "${name} configuration";
|
2024-01-25 14:49:57 +00:00
|
|
|
}))
|
|
|
|
nixvimConfigurations;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|