mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-02-07 12:19:07 +00:00
flake-parts/setups/nixvim: init
This commit is contained in:
parent
b7d75f4c9d
commit
356bbdc14e
@ -1,6 +1,7 @@
|
||||
{
|
||||
imports = [
|
||||
./nixos.nix
|
||||
./nixvim.nix
|
||||
./home-manager.nix
|
||||
];
|
||||
}
|
||||
|
144
modules/flake-parts/setups/nixvim.nix
Normal file
144
modules/flake-parts/setups/nixvim.nix
Normal file
@ -0,0 +1,144 @@
|
||||
{ inputs
|
||||
, lib
|
||||
, config
|
||||
|
||||
, defaultOverlays
|
||||
|
||||
, ... }:
|
||||
|
||||
let
|
||||
cfg = config.setups.nixvim;
|
||||
partsConfig = config;
|
||||
|
||||
mkNixvimConfig = { system, nixpkgsBranch, modules ? [] }:
|
||||
let
|
||||
pkgs = import inputs.${nixpkgsBranch} {
|
||||
inherit system;
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
in
|
||||
inputs.nixvim.legacyPackages.${system}.makeNixvimWithModule {
|
||||
inherit pkgs;
|
||||
module = {
|
||||
imports = modules;
|
||||
};
|
||||
};
|
||||
|
||||
modulesOption = lib.mkOption {
|
||||
type = with lib.types; listOf raw;
|
||||
default = [];
|
||||
};
|
||||
modulesOption' = configEnv: modulesOption // {
|
||||
description = ''
|
||||
A list of NixVim modules to be applied across all NixVim configurations
|
||||
when imported as part of ${configEnv}.
|
||||
'';
|
||||
};
|
||||
|
||||
configType = { name, lib, config, ... }: {
|
||||
options = {
|
||||
systems = lib.mkOption {
|
||||
type = with lib.types; listOf str;
|
||||
default = partsConfig.systems;
|
||||
defaultText = "config.systems";
|
||||
example = [ "x86_64-linux" "aarch64-linux" ];
|
||||
description = ''
|
||||
A list of systems the NixVim configuration will be built against.
|
||||
'';
|
||||
};
|
||||
|
||||
nixpkgsBranches = lib.mkOption {
|
||||
type = with lib.types; listOf str;
|
||||
description = ''
|
||||
A list of nixpkgs branches for the NixVim configuration to be built
|
||||
against.
|
||||
'';
|
||||
example = [
|
||||
"nixos-unstable"
|
||||
"nixos-stable"
|
||||
];
|
||||
};
|
||||
|
||||
modules = lib.mkOption {
|
||||
type = with lib.types; listOf raw;
|
||||
default = [];
|
||||
description = ''
|
||||
Additional NixVim modules to use.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
modules = [
|
||||
../../../configs/nixvim/${name}
|
||||
];
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.setups.nixvim = {
|
||||
configs = lib.mkOption {
|
||||
type = with lib.types; attrsOf (submodule configType);
|
||||
default = {};
|
||||
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
|
||||
configurations.
|
||||
'';
|
||||
};
|
||||
standaloneConfigModules = modulesOption' "standalone configuration";
|
||||
};
|
||||
|
||||
config = lib.mkIf (cfg.configs != {}) {
|
||||
perSystem = { system, config, lib, ... }:
|
||||
(
|
||||
let
|
||||
validConfigs = lib.filterAttrs
|
||||
(_: metadata: lib.elem system metadata.systems) cfg.configs;
|
||||
|
||||
nixvimConfigurations =
|
||||
let
|
||||
generateNixvimConfigs = name: metadata:
|
||||
let
|
||||
mkNixvim = nixpkgsBranch:
|
||||
lib.nameValuePair
|
||||
"${name}-${nixpkgsBranch}"
|
||||
(mkNixvimConfig {
|
||||
inherit system nixpkgsBranch;
|
||||
modules =
|
||||
cfg.sharedModules
|
||||
++ cfg.standaloneConfigModules
|
||||
++ metadata.modules;
|
||||
});
|
||||
|
||||
nixvimConfigs = builtins.map mkNixvim metadata.nixpkgsBranches;
|
||||
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 {
|
||||
inherit nvim;
|
||||
name = "${name} configuration";
|
||||
}))
|
||||
nixvimConfigurations;
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user