mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-12-19 10:59:49 +01:00
treewide: cleanup
This commit is contained in:
parent
84fc8eb860
commit
c1f449137f
9 changed files with 220 additions and 197 deletions
|
@ -4,4 +4,5 @@
|
||||||
types = import ./types {inherit lib;};
|
types = import ./types {inherit lib;};
|
||||||
languages = import ./languages.nix {inherit lib;};
|
languages = import ./languages.nix {inherit lib;};
|
||||||
lua = import ./lua.nix {inherit lib;};
|
lua = import ./lua.nix {inherit lib;};
|
||||||
|
vim = import ./vim.nix {inherit lib;};
|
||||||
}
|
}
|
||||||
|
|
51
lib/lua.nix
51
lib/lua.nix
|
@ -1,11 +1,8 @@
|
||||||
# Helpers for converting values to lua
|
# Helpers for converting values to lua
|
||||||
{lib}: rec {
|
{lib}: let
|
||||||
# yes? no.
|
inherit (lib) mapAttrsToList filterAttrs concatStringsSep concatMapStringsSep stringToCharacters boolToString;
|
||||||
yesNo = value:
|
inherit (builtins) hasAttr head;
|
||||||
if value
|
in rec {
|
||||||
then "yes"
|
|
||||||
else "no";
|
|
||||||
|
|
||||||
# Convert a null value to lua's nil
|
# Convert a null value to lua's nil
|
||||||
nullString = value:
|
nullString = value:
|
||||||
if value == null
|
if value == null
|
||||||
|
@ -46,4 +43,44 @@
|
||||||
+ " }";
|
+ " }";
|
||||||
# Convert a list of lua expressions to a lua table. The difference to listToLuaTable is that the elements here are expected to be lua expressions already, whereas listToLuaTable converts from nix types to lua first
|
# Convert a list of lua expressions to a lua table. The difference to listToLuaTable is that the elements here are expected to be lua expressions already, whereas listToLuaTable converts from nix types to lua first
|
||||||
luaTable = items: ''{${builtins.concatStringsSep "," items}}'';
|
luaTable = items: ''{${builtins.concatStringsSep "," items}}'';
|
||||||
|
|
||||||
|
toLuaObject = args:
|
||||||
|
if builtins.isAttrs args
|
||||||
|
then
|
||||||
|
if hasAttr "__raw" args
|
||||||
|
then args.__raw
|
||||||
|
else if hasAttr "__empty" args
|
||||||
|
then "{ }"
|
||||||
|
else
|
||||||
|
"{"
|
||||||
|
+ (concatStringsSep ","
|
||||||
|
(mapAttrsToList
|
||||||
|
(n: v:
|
||||||
|
if head (stringToCharacters n) == "@"
|
||||||
|
then toLuaObject v
|
||||||
|
else "[${toLuaObject n}] = " + (toLuaObject v))
|
||||||
|
(filterAttrs
|
||||||
|
(
|
||||||
|
_: v:
|
||||||
|
(v != null) && (toLuaObject v != "{}")
|
||||||
|
)
|
||||||
|
args)))
|
||||||
|
+ "}"
|
||||||
|
else if builtins.isList args
|
||||||
|
then "{" + concatMapStringsSep "," toLuaObject args + "}"
|
||||||
|
else if builtins.isString args
|
||||||
|
then
|
||||||
|
# This should be enough!
|
||||||
|
builtins.toJSON args
|
||||||
|
else if builtins.isPath args
|
||||||
|
then builtins.toJSON (toString args)
|
||||||
|
else if builtins.isBool args
|
||||||
|
then "${boolToString args}"
|
||||||
|
else if builtins.isFloat args
|
||||||
|
then "${toString args}"
|
||||||
|
else if builtins.isInt args
|
||||||
|
then "${toString args}"
|
||||||
|
else if (args != null)
|
||||||
|
then "nil"
|
||||||
|
else "";
|
||||||
}
|
}
|
||||||
|
|
26
lib/vim.nix
Normal file
26
lib/vim.nix
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{lib}: let
|
||||||
|
inherit (builtins) isInt isBool toJSON;
|
||||||
|
in rec {
|
||||||
|
# yes? no.
|
||||||
|
yesNo = value:
|
||||||
|
if value
|
||||||
|
then "yes"
|
||||||
|
else "no";
|
||||||
|
|
||||||
|
# convert a boolean to a vim compliant boolean string
|
||||||
|
mkVimBool = val:
|
||||||
|
if val
|
||||||
|
then "1"
|
||||||
|
else "0";
|
||||||
|
|
||||||
|
# convert a literal value to a vim compliant value
|
||||||
|
valToVim = val:
|
||||||
|
if (isInt val)
|
||||||
|
then (builtins.toString val)
|
||||||
|
else
|
||||||
|
(
|
||||||
|
if (isBool val)
|
||||||
|
then (mkVimBool val)
|
||||||
|
else (toJSON val)
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,27 +0,0 @@
|
||||||
{
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
with lib; let
|
|
||||||
cfg = config.vim;
|
|
||||||
in {
|
|
||||||
config = {
|
|
||||||
assertions = mkMerge [
|
|
||||||
{
|
|
||||||
assertion = cfg.kommentary.enable;
|
|
||||||
message = "Kommentary has been deprecated in favor of comments-nvim";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
assertion = cfg.utility.colorizer.enable;
|
|
||||||
message = "config.utility.colorizer has been renamed to config.utility.ccc";
|
|
||||||
}
|
|
||||||
mkIf
|
|
||||||
(config.programs.neovim-flake.enable)
|
|
||||||
{
|
|
||||||
assertion = !config.programs.neovim.enable;
|
|
||||||
message = "You cannot use `programs.neovim-flake.enable` with `programs.neovim.enable`";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -2,9 +2,9 @@
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
...
|
...
|
||||||
}:
|
}: let
|
||||||
with lib;
|
inherit (lib) optionalString mkIf nvim;
|
||||||
with builtins; let
|
|
||||||
cfg = config.vim;
|
cfg = config.vim;
|
||||||
in {
|
in {
|
||||||
config = {
|
config = {
|
||||||
|
@ -57,8 +57,8 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
vim.configRC.basic = nvim.dag.entryAfter ["globalsScript"] ''
|
vim.configRC.basic = nvim.dag.entryAfter ["globalsScript"] ''
|
||||||
" Debug mode settings
|
|
||||||
${optionalString cfg.debugMode.enable ''
|
${optionalString cfg.debugMode.enable ''
|
||||||
|
" Debug mode settings
|
||||||
set verbose=${toString cfg.debugMode.level}
|
set verbose=${toString cfg.debugMode.level}
|
||||||
set verbosefile=${cfg.debugMode.logFile}
|
set verbosefile=${cfg.debugMode.logFile}
|
||||||
''}
|
''}
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
}: let
|
||||||
with lib;
|
inherit (lib) mkEnableOption mkOption;
|
||||||
with builtins; {
|
inherit (lib.types) types;
|
||||||
|
in {
|
||||||
options.vim = {
|
options.vim = {
|
||||||
package = mkOption {
|
package = mkOption {
|
||||||
type = types.package;
|
type = types.package;
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
|
||||||
with builtins; let
|
with builtins; let
|
||||||
|
inherit (lib) mkOption types mapAttrsFlatten filterAttrs optionalString getAttrs;
|
||||||
|
inherit (lib) nvim;
|
||||||
|
inherit (nvim.lua) toLuaObject;
|
||||||
|
|
||||||
cfg = config.vim;
|
cfg = config.vim;
|
||||||
|
|
||||||
wrapLuaConfig = luaConfig: ''
|
wrapLuaConfig = luaConfig: ''
|
||||||
|
@ -20,7 +23,7 @@ with builtins; let
|
||||||
mkOption {
|
mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = value;
|
default = value;
|
||||||
description = description;
|
inherit description;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Most of the keybindings code is highly inspired by pta2002/nixvim. Thank you!
|
# Most of the keybindings code is highly inspired by pta2002/nixvim. Thank you!
|
||||||
|
@ -67,7 +70,7 @@ with builtins; let
|
||||||
normalizeAction = action: let
|
normalizeAction = action: let
|
||||||
# Extract the values of the config options that have been explicitly set by the user
|
# Extract the values of the config options that have been explicitly set by the user
|
||||||
config =
|
config =
|
||||||
filterAttrs (n: v: v != null)
|
filterAttrs (_: v: v != null)
|
||||||
(getAttrs (attrNames mapConfigOptions) action);
|
(getAttrs (attrNames mapConfigOptions) action);
|
||||||
in {
|
in {
|
||||||
config =
|
config =
|
||||||
|
@ -85,8 +88,8 @@ with builtins; let
|
||||||
normalizedAction = normalizeAction action;
|
normalizedAction = normalizeAction action;
|
||||||
in {
|
in {
|
||||||
inherit (normalizedAction) action config;
|
inherit (normalizedAction) action config;
|
||||||
key = key;
|
inherit key;
|
||||||
mode = mode;
|
inherit mode;
|
||||||
})
|
})
|
||||||
maps);
|
maps);
|
||||||
|
|
||||||
|
@ -117,7 +120,31 @@ with builtins; let
|
||||||
default = {};
|
default = {};
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
options.vim = {
|
options = {
|
||||||
|
assertions = lib.mkOption {
|
||||||
|
type = with types; listOf unspecified;
|
||||||
|
internal = true;
|
||||||
|
default = [];
|
||||||
|
example = lib.literalExpression [
|
||||||
|
{
|
||||||
|
assertion = false;
|
||||||
|
message = "you can't enable this for that reason";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
warnings = mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = [];
|
||||||
|
type = with types; listOf str;
|
||||||
|
example = ["The `foo' service is deprecated and will go away soon!"];
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
This option allows modules to show warnings to users during
|
||||||
|
the evaluation of the system configuration.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
vim = {
|
||||||
viAlias = mkOption {
|
viAlias = mkOption {
|
||||||
description = "Enable vi alias";
|
description = "Enable vi alias";
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
|
@ -219,67 +246,14 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
config = let
|
config = let
|
||||||
mkVimBool = val:
|
|
||||||
if val
|
|
||||||
then "1"
|
|
||||||
else "0";
|
|
||||||
valToVim = val:
|
|
||||||
if (isInt val)
|
|
||||||
then (builtins.toString val)
|
|
||||||
else
|
|
||||||
(
|
|
||||||
if (isBool val)
|
|
||||||
then (mkVimBool val)
|
|
||||||
else (toJSON val)
|
|
||||||
);
|
|
||||||
|
|
||||||
filterNonNull = mappings: filterAttrs (_name: value: value != null) mappings;
|
filterNonNull = mappings: filterAttrs (_name: value: value != null) mappings;
|
||||||
globalsScript =
|
globalsScript =
|
||||||
mapAttrsFlatten (name: value: "let g:${name}=${valToVim value}")
|
mapAttrsFlatten (name: value: "let g:${name}=${valToVim value}")
|
||||||
(filterNonNull cfg.globals);
|
(filterNonNull cfg.globals);
|
||||||
|
|
||||||
toLuaObject = args:
|
|
||||||
if builtins.isAttrs args
|
|
||||||
then
|
|
||||||
if hasAttr "__raw" args
|
|
||||||
then args.__raw
|
|
||||||
else if hasAttr "__empty" args
|
|
||||||
then "{ }"
|
|
||||||
else
|
|
||||||
"{"
|
|
||||||
+ (concatStringsSep ","
|
|
||||||
(mapAttrsToList
|
|
||||||
(n: v:
|
|
||||||
if head (stringToCharacters n) == "@"
|
|
||||||
then toLuaObject v
|
|
||||||
else "[${toLuaObject n}] = " + (toLuaObject v))
|
|
||||||
(filterAttrs
|
|
||||||
(
|
|
||||||
n: v:
|
|
||||||
!isNull v && (toLuaObject v != "{}")
|
|
||||||
)
|
|
||||||
args)))
|
|
||||||
+ "}"
|
|
||||||
else if builtins.isList args
|
|
||||||
then "{" + concatMapStringsSep "," toLuaObject args + "}"
|
|
||||||
else if builtins.isString args
|
|
||||||
then
|
|
||||||
# This should be enough!
|
|
||||||
builtins.toJSON args
|
|
||||||
else if builtins.isPath args
|
|
||||||
then builtins.toJSON (toString args)
|
|
||||||
else if builtins.isBool args
|
|
||||||
then "${boolToString args}"
|
|
||||||
else if builtins.isFloat args
|
|
||||||
then "${toString args}"
|
|
||||||
else if builtins.isInt args
|
|
||||||
then "${toString args}"
|
|
||||||
else if isNull args
|
|
||||||
then "nil"
|
|
||||||
else "";
|
|
||||||
|
|
||||||
toLuaBindings = mode: maps:
|
toLuaBindings = mode: maps:
|
||||||
builtins.map (value: ''
|
builtins.map (value: ''
|
||||||
vim.keymap.set(${toLuaObject mode}, ${toLuaObject value.key}, ${toLuaObject value.action}, ${toLuaObject value.config})
|
vim.keymap.set(${toLuaObject mode}, ${toLuaObject value.key}, ${toLuaObject value.action}, ${toLuaObject value.config})
|
||||||
|
@ -304,7 +278,7 @@ in {
|
||||||
mapResult,
|
mapResult,
|
||||||
}: let
|
}: let
|
||||||
# When the value is a string, default it to dag.entryAnywhere
|
# When the value is a string, default it to dag.entryAnywhere
|
||||||
finalDag = lib.mapAttrs (name: value:
|
finalDag = lib.mapAttrs (_: value:
|
||||||
if builtins.isString value
|
if builtins.isString value
|
||||||
then nvim.dag.entryAnywhere value
|
then nvim.dag.entryAnywhere value
|
||||||
else value)
|
else value)
|
||||||
|
@ -378,6 +352,13 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
builtConfigRC = let
|
builtConfigRC = let
|
||||||
|
failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions);
|
||||||
|
|
||||||
|
baseSystemAssertWarn =
|
||||||
|
if failedAssertions != []
|
||||||
|
then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
||||||
|
else lib.showWarnings config.warnings;
|
||||||
|
|
||||||
mkSection = r: ''
|
mkSection = r: ''
|
||||||
" SECTION: ${r.name}
|
" SECTION: ${r.name}
|
||||||
${r.data}
|
${r.data}
|
||||||
|
@ -389,7 +370,7 @@ in {
|
||||||
inherit mapResult;
|
inherit mapResult;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
vimConfig;
|
baseSystemAssertWarn vimConfig;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ inputs: {
|
||||||
check ? true,
|
check ? true,
|
||||||
extraSpecialArgs ? {},
|
extraSpecialArgs ? {},
|
||||||
}: let
|
}: let
|
||||||
inherit (pkgs) neovim-unwrapped wrapNeovim vimPlugins;
|
inherit (pkgs) wrapNeovim vimPlugins;
|
||||||
inherit (builtins) map filter isString toString getAttr;
|
inherit (builtins) map filter isString toString getAttr;
|
||||||
inherit (pkgs.vimUtils) buildVimPlugin;
|
inherit (pkgs.vimUtils) buildVimPlugin;
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ inputs: {
|
||||||
specialArgs = {modulesPath = toString ./.;} // extraSpecialArgs;
|
specialArgs = {modulesPath = toString ./.;} // extraSpecialArgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
vimOptions = module.config.vim;
|
||||||
|
|
||||||
buildPlug = {pname, ...} @ args:
|
buildPlug = {pname, ...} @ args:
|
||||||
assert lib.asserts.assertMsg (pname != "nvim-treesitter") "Use buildTreesitterPlug for building nvim-treesitter.";
|
assert lib.asserts.assertMsg (pname != "nvim-treesitter") "Use buildTreesitterPlug for building nvim-treesitter.";
|
||||||
buildVimPlugin (args
|
buildVimPlugin (args
|
||||||
|
@ -31,8 +33,6 @@ inputs: {
|
||||||
|
|
||||||
buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars);
|
buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars);
|
||||||
|
|
||||||
vimOptions = module.config.vim;
|
|
||||||
|
|
||||||
buildConfigPlugins = plugins:
|
buildConfigPlugins = plugins:
|
||||||
map
|
map
|
||||||
(plug: (
|
(plug: (
|
||||||
|
|
|
@ -34,10 +34,14 @@
|
||||||
|
|
||||||
pkgsModule = {config, ...}: {
|
pkgsModule = {config, ...}: {
|
||||||
config = {
|
config = {
|
||||||
_module.args.baseModules = modules;
|
_module = {
|
||||||
_module.args.pkgsPath = lib.mkDefault pkgs.path;
|
inherit check;
|
||||||
_module.args.pkgs = lib.mkDefault pkgs;
|
args = {
|
||||||
_module.check = check;
|
baseModules = modules;
|
||||||
|
pkgsPath = lib.mkDefault pkgs.path;
|
||||||
|
pkgs = lib.mkDefault pkgs;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|
Loading…
Reference in a new issue