flake-parts/setups/nixvim: merge into a unified list of components

At least, it made the module code and configuration easier with
`nixpkgs.lib.cartesianProductOfSets`.
This commit is contained in:
Gabriel Arazas 2024-06-11 16:39:16 +08:00
parent 17c36bf29c
commit 2dd2175250
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
2 changed files with 95 additions and 64 deletions

View File

@ -1,27 +1,32 @@
{ inputs, ... }: { inputs, lib, ... }:
{ {
setups.nixvim.configs = { setups.nixvim.configs = {
fiesta = { fiesta = {
nixpkgsBranches = [ components = [
"nixos-unstable" {
]; nixpkgsBranch = "nixos-unstable";
nixvimBranch = "nixvim-unstable"; nixvimBranch = "nixvim-unstable";
neovimPackages = p: with p; [ neovimPackage = pkgs: pkgs.neovim;
neovim overlays = [
inputs.neovim-nightly-overlay.overlays.default
];
}
]; ];
}; };
trovebelt = { trovebelt = {
nixpkgsBranches = [ components = lib.cartesianProductOfSets {
"nixos-unstable" nixpkgsBranch = [ "nixos-unstable" ];
]; nixvimBranch = [ "nixvim-unstable" ];
nixvimBranch = "nixos-unstable"; neovimPackage = [ (pkgs: pkgs.neovim) ];
neovimPackages = p: with p; [ overlays = [
neovim [ inputs.neovim-nightly-overlay.overlays.default ]
[ ]
]; ];
}; };
}; };
};
setups.nixvim.sharedModules = [ setups.nixvim.sharedModules = [
# The rainbow road to ricing your raw materials. # The rainbow road to ricing your raw materials.

View File

@ -2,8 +2,6 @@
, lib , lib
, config , config
, defaultOverlays
, ... , ...
}: }:
@ -33,18 +31,22 @@ let
''; '';
}; };
configType = { name, lib, config, ... }: { componentType = { lib, config, ... }: {
options = { options = {
nixpkgsBranches = lib.mkOption { nixpkgsBranch = lib.mkOption {
type = with lib.types; listOf str; type = lib.types.nonEmptyStr;
default = "nixpkgs";
example = "nixos-unstable";
description = '' description = ''
A list of nixpkgs branches for the NixVim configuration to be built The nixpkgs branch for the NixVim configuration to be built
against. against.
::: {.note}
This refers to your flake inputs so in order to support multiple
nixpkgs branches, you need to import multiple nixpkgs as part of the
`inputs` flake attribute.
:::
''; '';
example = [
"nixos-unstable"
"nixos-stable"
];
}; };
nixvimBranch = lib.mkOption { nixvimBranch = lib.mkOption {
@ -52,28 +54,64 @@ let
default = "nixvim"; default = "nixvim";
example = "nixvim-unstable"; example = "nixvim-unstable";
description = '' description = ''
The NixVim branch to be used for the configuration. 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.
:::
''; '';
}; };
neovimPackages = lib.mkOption { neovimPackage = lib.mkOption {
type = with lib.types; functionTo (listOf package); type = with lib.types; functionTo package;
default = pkgs: with pkgs; [ neovim ]; default = pkgs: pkgs.neovim;
defaultText = "pkgs: with pkgs; [ neovim ]"; defaultText = "pkgs: pkgs.neovim";
example = lib.literalExpression '' example = lib.literalExpression ''
pkgs: with pkgs; [ pkgs: pkgs.neovim-nightly
(wrapNeovim neovim-unwrapped { }) '';
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.
'';
};
overlays = lib.mkOption {
type = with lib.types; listOf (functionTo raw);
default = [ ];
example = lib.literalExpression ''
[
inputs.neovim-nightly-overlay.overlays.default
] ]
''; '';
description = '' description = ''
A list of Neovim packages from different branches to be built A list of overlays to be applied for the nixpkgs instance.
against. Since this is to be used per-system, it should be a function
that returns a list of packages where the given statement is the
nixpkgs instance.
''; '';
}; };
}; };
};
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; }
];
};
};
config = { config = {
modules = [ modules = [
@ -129,38 +167,26 @@ in
let let
generateNixvimConfigs = name: metadata: generateNixvimConfigs = name: metadata:
let let
iterateThruBranches = nixpkgsBranch: mkNixvimConfig' = component:
let let
pkgs = import inputs.${nixpkgsBranch} { pkgs = import inputs.${component.nixpkgsBranch} {
inherit (component) overlays;
inherit system; inherit system;
overlays = defaultOverlays ++ [
inputs.neovim-nightly-overlay.overlays.default
];
config.allowUnfree = true;
}; };
neovimPackage = component.neovimPackage pkgs;
# Unfortunately we cannot have NixVim with Neovim-reliant in
# packages such as Neovide or something similar. It has
# to be Neovim.
neovimPackages = metadata.neovimPackages pkgs;
mkNixvimConfig' = neovimPkg:
lib.nameValuePair lib.nameValuePair
"${name}-${nixpkgsBranch}-${neovimPkg.name}" "${name}-${component.nixpkgsBranch}-${neovimPackage.pname}"
(mkNixvimConfig { (mkNixvimConfig {
inherit system pkgs; inherit system pkgs;
inherit (metadata) nixvimBranch; inherit (component) nixvimBranch;
modules = modules =
cfg.sharedModules cfg.sharedModules
++ cfg.standaloneConfigModules ++ cfg.standaloneConfigModules
++ metadata.modules ++ metadata.modules
++ [{ package = neovimPkg; }]; ++ [{ package = neovimPackage; }];
}); });
in nixvimConfigs = builtins.map mkNixvimConfig' metadata.components;
builtins.map mkNixvimConfig' neovimPackages;
nixvimConfigs = lib.lists.flatten
(builtins.map iterateThruBranches metadata.nixpkgsBranches);
in in
lib.listToAttrs nixvimConfigs; lib.listToAttrs nixvimConfigs;
in in