mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-11-09 14:45:58 +01:00
treewide: refactor custom lib, merge lists in hm/nixos module (#323)
* treewide: refactor custom lib, merge lists in hm/nixos module * lib/types(custom): clarify anythingConcatLists code --------- Co-authored-by: raf <raf@notashelf.dev>
This commit is contained in:
parent
0c444830f6
commit
901363d1ac
13 changed files with 307 additions and 256 deletions
|
@ -1,21 +1,4 @@
|
|||
inputs: let
|
||||
modulesWithInputs = import ./modules inputs;
|
||||
|
||||
neovimConfiguration = {
|
||||
modules ? [],
|
||||
pkgs,
|
||||
lib ? pkgs.lib,
|
||||
check ? true,
|
||||
extraSpecialArgs ? {},
|
||||
extraModules ? [],
|
||||
...
|
||||
}:
|
||||
modulesWithInputs {
|
||||
inherit pkgs lib check extraSpecialArgs extraModules;
|
||||
configuration.imports = modules;
|
||||
};
|
||||
|
||||
mainConfig = isMaximal: {
|
||||
isMaximal: {
|
||||
config.vim = {
|
||||
viAlias = true;
|
||||
vimAlias = true;
|
||||
|
@ -254,7 +237,4 @@ inputs: let
|
|||
neocord.enable = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
inherit neovimConfiguration mainConfig;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
inputs,
|
||||
pkgs,
|
||||
lib ? import ../lib/stdlib-extended.nix pkgs.lib inputs,
|
||||
lib,
|
||||
manpageUrls ? pkgs.path + "/doc/manpage-urls.json",
|
||||
...
|
||||
}: let
|
||||
|
|
25
flake.nix
25
flake.nix
|
@ -1,12 +1,18 @@
|
|||
{
|
||||
description = "A neovim flake with a modular configuration";
|
||||
outputs = {
|
||||
nixpkgs,
|
||||
flake-parts,
|
||||
self,
|
||||
...
|
||||
} @ inputs:
|
||||
flake-parts.lib.mkFlake {inherit inputs;} {
|
||||
} @ inputs: let
|
||||
# call the extedended library with `inputs`
|
||||
# inputs is used to get the original standard library, and to pass inputs to the plugin autodiscovery function
|
||||
lib = import ./lib/stdlib-extended.nix inputs;
|
||||
in
|
||||
flake-parts.lib.mkFlake {
|
||||
inherit inputs;
|
||||
specialArgs = {inherit lib;};
|
||||
} {
|
||||
# provide overridable systems
|
||||
# https://github.com/nix-systems/nix-systems
|
||||
systems = import inputs.systems;
|
||||
|
@ -17,36 +23,33 @@
|
|||
./flake/packages.nix
|
||||
];
|
||||
|
||||
_module.args = {inherit (nixpkgs) lib;};
|
||||
|
||||
flake = {
|
||||
lib = {
|
||||
inherit (import ./lib/stdlib-extended.nix nixpkgs.lib inputs) nvim;
|
||||
inherit (import ./configuration.nix inputs) neovimConfiguration;
|
||||
inherit (lib) nvim neovimConfiguration;
|
||||
};
|
||||
|
||||
homeManagerModules = {
|
||||
neovim-flake =
|
||||
nixpkgs.lib.warn ''
|
||||
lib.warn ''
|
||||
homeManagerModules.neovim-flake has been deprecated.
|
||||
Plese use the homeManagerModules.nvf instead
|
||||
''
|
||||
self.homeManagerModules.nvf;
|
||||
|
||||
nvf = import ./flake/modules/home-manager.nix self.packages inputs;
|
||||
nvf = import ./flake/modules/home-manager.nix self.packages lib;
|
||||
|
||||
default = self.homeManagerModules.nvf;
|
||||
};
|
||||
|
||||
nixosModules = {
|
||||
neovim-flake =
|
||||
nixpkgs.lib.warn ''
|
||||
lib.warn ''
|
||||
nixosModules.neovim-flake has been deprecated.
|
||||
Please use the nixosModules.nvf instead
|
||||
''
|
||||
self.nixosModules.nvf;
|
||||
|
||||
nvf = import ./flake/modules/nixos.nix self.packages inputs;
|
||||
nvf = import ./flake/modules/nixos.nix self.packages lib;
|
||||
|
||||
default = self.nixosModules.nvf;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
# Home Manager module
|
||||
packages: inputs: {
|
||||
packages: lib: {
|
||||
config,
|
||||
pkgs,
|
||||
lib ? pkgs.lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) maintainers;
|
||||
|
@ -10,9 +9,10 @@ packages: inputs: {
|
|||
inherit (lib.lists) optional;
|
||||
inherit (lib.options) mkOption mkEnableOption literalExpression;
|
||||
inherit (lib.types) attrsOf anything bool;
|
||||
inherit (lib.nvim) neovimConfiguration;
|
||||
inherit (lib.nvim.types) anythingConcatLists;
|
||||
|
||||
cfg = config.programs.nvf;
|
||||
inherit (import ../../configuration.nix inputs) neovimConfiguration;
|
||||
|
||||
neovimConfigured = neovimConfiguration {
|
||||
inherit pkgs;
|
||||
|
@ -55,7 +55,7 @@ in {
|
|||
};
|
||||
|
||||
settings = mkOption {
|
||||
type = attrsOf anything;
|
||||
type = attrsOf anythingConcatLists;
|
||||
default = {};
|
||||
description = "Attribute set of nvf preferences.";
|
||||
example = literalExpression ''
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
# NixOS module
|
||||
packages: inputs: {
|
||||
packages: lib: {
|
||||
config,
|
||||
pkgs,
|
||||
lib ? pkgs.lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) maintainers;
|
||||
|
@ -10,9 +9,10 @@ packages: inputs: {
|
|||
inherit (lib.lists) optional;
|
||||
inherit (lib.options) mkOption mkEnableOption literalExpression;
|
||||
inherit (lib.types) attrsOf anything bool;
|
||||
inherit (lib.nvim) neovimConfiguration;
|
||||
inherit (lib.nvim.types) anythingConcatLists;
|
||||
|
||||
cfg = config.programs.nvf;
|
||||
inherit (import ../../configuration.nix inputs) neovimConfiguration;
|
||||
|
||||
neovimConfigured = neovimConfiguration {
|
||||
inherit pkgs;
|
||||
|
@ -55,7 +55,7 @@ in {
|
|||
};
|
||||
|
||||
settings = mkOption {
|
||||
type = attrsOf anything;
|
||||
type = attrsOf anythingConcatLists;
|
||||
default = {};
|
||||
description = "Attribute set of nvf preferences.";
|
||||
example = literalExpression ''
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
{
|
||||
inputs,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (import ../configuration.nix inputs) neovimConfiguration mainConfig;
|
||||
inherit (lib.nvim) neovimConfiguration;
|
||||
|
||||
buildPkg = pkgs: modules: (neovimConfiguration {inherit pkgs modules;}).neovim;
|
||||
|
||||
nixConfig = mainConfig false;
|
||||
maximalConfig = mainConfig true;
|
||||
nixConfig = import ../configuration.nix false;
|
||||
maximalConfig = import ../configuration.nix true;
|
||||
in {
|
||||
flake.overlays.default = _final: prev: {
|
||||
inherit neovimConfiguration;
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
perSystem = {
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
docs = import ../docs {inherit pkgs inputs;};
|
||||
docs = import ../docs {inherit pkgs inputs lib;};
|
||||
in {
|
||||
packages = {
|
||||
# Documentation
|
||||
|
|
18
lib/configuration.nix
Normal file
18
lib/configuration.nix
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
inputs,
|
||||
lib,
|
||||
}: let
|
||||
modulesWithInputs = import ../modules inputs;
|
||||
in
|
||||
{
|
||||
modules ? [],
|
||||
pkgs,
|
||||
check ? true,
|
||||
extraSpecialArgs ? {},
|
||||
extraModules ? [],
|
||||
...
|
||||
}:
|
||||
modulesWithInputs {
|
||||
inherit pkgs lib check extraSpecialArgs extraModules;
|
||||
configuration.imports = modules;
|
||||
}
|
|
@ -12,4 +12,5 @@
|
|||
lists = import ./lists.nix {inherit lib;};
|
||||
lua = import ./lua.nix {inherit lib;};
|
||||
vim = import ./vim.nix;
|
||||
neovimConfiguration = import ./configuration.nix {inherit inputs lib;};
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Convenience function that returns the given Nixpkgs standard library
|
||||
# extended with our functions using `lib.extend`.
|
||||
nixpkgsLib: inputs:
|
||||
nixpkgsLib.extend (self: super: {
|
||||
inputs:
|
||||
inputs.nixpkgs.lib.extend (self: super: {
|
||||
# WARNING: New functions should not be added here, but to files
|
||||
# imported by `./default.nix` under their own categories. If your
|
||||
# function does not fit to any of the existing categories, create
|
||||
|
|
53
lib/types/custom.nix
Normal file
53
lib/types/custom.nix
Normal file
|
@ -0,0 +1,53 @@
|
|||
{lib}: let
|
||||
inherit (lib) isStringLike showOption showFiles getFiles mergeOneOption mergeEqualOption;
|
||||
inherit (lib.types) anything attrsOf;
|
||||
inherit (lib.nvim.types) anythingConcatLists;
|
||||
inherit (builtins) typeOf isAttrs any head concatLists;
|
||||
in {
|
||||
# HACK: Does this break anything in our case?
|
||||
# A modified version of the nixpkgs anything type that concatenates lists
|
||||
# This isn't the default because the order in which the lists are concatenated depends on the order in which the modules are imported,
|
||||
# which makes it non-deterministic
|
||||
anythingConcatLists =
|
||||
anything
|
||||
// {
|
||||
merge = loc: defs: let
|
||||
getType = value:
|
||||
if isAttrs value && isStringLike value
|
||||
then "stringCoercibleSet"
|
||||
else typeOf value;
|
||||
|
||||
# Throw an error if not all defs have the same type
|
||||
checkType = getType (head defs).value;
|
||||
commonType =
|
||||
if any (def: getType def.value != checkType) defs
|
||||
then throw "The option `${showOption loc}' has conflicting option types in ${showFiles (getFiles defs)}"
|
||||
else checkType;
|
||||
|
||||
mergeFunctions = {
|
||||
# Recursively merge attribute sets
|
||||
set = (attrsOf anythingConcatLists).merge;
|
||||
|
||||
# Overridden behavior for lists, that concatenates lists
|
||||
list = _: defs: concatLists (map (e: e.value) defs);
|
||||
|
||||
# This means it's a package, only accept a single definition
|
||||
stringCoercibleSet = mergeOneOption;
|
||||
|
||||
# This works by passing the argument to the functions,
|
||||
# and merging their returns values instead
|
||||
lambda = loc: defs: arg:
|
||||
anythingConcatLists.merge
|
||||
(loc ++ ["<function body>"])
|
||||
(map (def: {
|
||||
inherit (def) file;
|
||||
value = def.value arg;
|
||||
})
|
||||
defs);
|
||||
};
|
||||
in
|
||||
# Merge the defs with the correct function from above, if available
|
||||
# otherwise only allow equal values
|
||||
(mergeFunctions.${commonType} or mergeEqualOption) loc defs;
|
||||
};
|
||||
}
|
|
@ -6,8 +6,10 @@
|
|||
typesDag = import ./dag.nix {inherit lib;};
|
||||
typesPlugin = import ./plugins.nix {inherit inputs lib;};
|
||||
typesLanguage = import ./languages.nix {inherit lib;};
|
||||
typesCustom = import ./custom.nix {inherit lib;};
|
||||
in {
|
||||
inherit (typesDag) dagOf;
|
||||
inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType;
|
||||
inherit (typesLanguage) diagnostics mkGrammarOption;
|
||||
inherit (typesCustom) anythingConcatLists;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
inputs: {
|
||||
configuration,
|
||||
pkgs,
|
||||
lib ? pkgs.lib,
|
||||
lib,
|
||||
check ? true,
|
||||
extraSpecialArgs ? {},
|
||||
extraModules ? [],
|
||||
|
@ -15,23 +15,16 @@ inputs: {
|
|||
inherit (lib.attrsets) recursiveUpdate;
|
||||
inherit (lib.asserts) assertMsg;
|
||||
|
||||
# call the extedended library with `lib` and `inputs` as arguments
|
||||
# lib is used to provide the standard library functions to the extended library
|
||||
# but it can be overridden while this file is being called
|
||||
# inputs is used to pass inputs to the plugin autodiscovery function
|
||||
extendedLib = import ../lib/stdlib-extended.nix lib inputs;
|
||||
|
||||
# import modules.nix with `check`, `pkgs` and `lib` as arguments
|
||||
# check can be disabled while calling this file is called
|
||||
# to avoid checking in all modules
|
||||
nvimModules = import ./modules.nix {
|
||||
inherit pkgs check;
|
||||
lib = extendedLib;
|
||||
inherit pkgs check lib;
|
||||
};
|
||||
|
||||
# evaluate the extended library with the modules
|
||||
# optionally with any additional modules passed by the user
|
||||
module = extendedLib.evalModules {
|
||||
module = lib.evalModules {
|
||||
specialArgs = recursiveUpdate {modulesPath = toString ./.;} extraSpecialArgs;
|
||||
modules = concatLists [[configuration] nvimModules extraModules];
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue