treewide: cleanup (#324)

* statix, deadnix, alejandra

* _file

* _module.args

* concatStringsSep "\n" -> concatLines
concatStringsSep "\n" map -> concatMapStringsSep "\n"

* mkShell nativeBuildInputs -> packages
This commit is contained in:
Gerg-L 2024-07-08 21:57:58 +00:00 committed by GitHub
parent f1849c0ce5
commit 8d5f23035d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 46 additions and 82 deletions

View File

@ -10,16 +10,15 @@
# provide overridable systems # provide overridable systems
# https://github.com/nix-systems/nix-systems # https://github.com/nix-systems/nix-systems
systems = import inputs.systems; systems = import inputs.systems;
imports = [ imports = [
# add lib to module args
{_module.args = {inherit (nixpkgs) lib;};}
./flake/apps.nix ./flake/apps.nix
./flake/legacyPackages.nix ./flake/legacyPackages.nix
./flake/overlays.nix ./flake/overlays.nix
./flake/packages.nix ./flake/packages.nix
]; ];
_module.args = {inherit (nixpkgs) lib;};
flake = { flake = {
lib = { lib = {
inherit (import ./lib/stdlib-extended.nix nixpkgs.lib inputs) nvim; inherit (import ./lib/stdlib-extended.nix nixpkgs.lib inputs) nvim;
@ -34,9 +33,7 @@
'' ''
self.homeManagerModules.nvf; self.homeManagerModules.nvf;
nvf = { nvf = import ./flake/modules/home-manager.nix self.packages inputs;
imports = [(import ./flake/modules/home-manager.nix self.packages inputs)];
};
default = self.homeManagerModules.nvf; default = self.homeManagerModules.nvf;
}; };
@ -49,9 +46,7 @@
'' ''
self.nixosModules.nvf; self.nixosModules.nvf;
nvf = { nvf = import ./flake/modules/nixos.nix self.packages inputs;
imports = [(import ./flake/modules/nixos.nix self.packages inputs)];
};
default = self.nixosModules.nvf; default = self.nixosModules.nvf;
}; };
@ -66,9 +61,9 @@
formatter = pkgs.alejandra; formatter = pkgs.alejandra;
devShells = { devShells = {
default = self'.devShells.lsp; default = self'.devShells.lsp;
nvim-nix = pkgs.mkShell {nativeBuildInputs = [config.packages.nix];}; nvim-nix = pkgs.mkShell {packages = [config.packages.nix];};
lsp = pkgs.mkShell { lsp = pkgs.mkShell {
nativeBuildInputs = with pkgs; [nil statix deadnix alejandra]; packages = with pkgs; [nil statix deadnix alejandra];
}; };
}; };
}; };

View File

@ -88,4 +88,5 @@ in {
++ optional cfg.enableManpages packages.${pkgs.stdenv.system}.docs-manpages; ++ optional cfg.enableManpages packages.${pkgs.stdenv.system}.docs-manpages;
}; };
}; };
_file = ./home-manager.nix;
} }

View File

@ -88,4 +88,5 @@ in {
++ optional cfg.enableManpages packages.${pkgs.stdenv.system}.docs-manpages; ++ optional cfg.enableManpages packages.${pkgs.stdenv.system}.docs-manpages;
}; };
}; };
_file = ./nixos.nix;
} }

View File

@ -1,6 +1,5 @@
{inputs, ...}: { {inputs, ...}: {
perSystem = { perSystem = {
system,
config, config,
pkgs, pkgs,
... ...

View File

@ -66,7 +66,7 @@
mkSetLuaBinding = binding: action: mkSetLuaBinding = binding: action:
mkLuaBinding binding.value action binding.description; mkLuaBinding binding.value action binding.description;
pushDownDefault = attr: mapAttrs (_: value: mkDefault value) attr; pushDownDefault = attr: mapAttrs (_: mkDefault) attr;
}; };
in in
binds binds

View File

@ -84,7 +84,7 @@ in {
normalizedDag = normalizedDag =
mapAttrs (n: v: { mapAttrs (n: v: {
name = n; name = n;
data = v.data; inherit (v) data;
after = v.after ++ dagBefore dag n; after = v.after ++ dagBefore dag n;
}) })
dag; dag;
@ -117,7 +117,6 @@ in {
entriesBetween = tag: let entriesBetween = tag: let
go = i: before: after: entries: let go = i: before: after: entries: let
name = "${tag}-${toString i}"; name = "${tag}-${toString i}";
i' = i + 1;
in in
if entries == [] if entries == []
then empty then empty

View File

@ -2,7 +2,7 @@
{lib}: let {lib}: let
inherit (builtins) hasAttr head throw typeOf isList isAttrs isBool isInt isString isPath isFloat toJSON; inherit (builtins) hasAttr head throw typeOf isList isAttrs isBool isInt isString isPath isFloat toJSON;
inherit (lib.attrsets) mapAttrsToList filterAttrs; inherit (lib.attrsets) mapAttrsToList filterAttrs;
inherit (lib.strings) concatStringsSep concatMapStringsSep stringToCharacters; inherit (lib.strings) concatStringsSep concatMapStringsSep stringToCharacters concatLines;
inherit (lib.trivial) boolToString warn; inherit (lib.trivial) boolToString warn;
in rec { in rec {
wrapLuaConfig = { wrapLuaConfig = {
@ -11,7 +11,7 @@ in rec {
luaAfter ? "", luaAfter ? "",
}: '' }: ''
lua << EOF lua << EOF
${concatStringsSep "\n" [luaBefore luaConfig luaAfter]} ${concatLines [luaBefore luaConfig luaAfter]}
EOF EOF
''; '';

View File

@ -5,7 +5,7 @@
}: let }: let
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair; inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair;
inherit (lib.strings) hasPrefix removePrefix isString; inherit (lib.strings) hasPrefix removePrefix;
inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr; inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr;
# Get the names of all flake inputs that start with the given prefix. # Get the names of all flake inputs that start with the given prefix.

View File

@ -30,14 +30,14 @@ in {
"copilot-lua" "copilot-lua"
# cfg.copilotNodePackage # cfg.copilotNodePackage
] ]
++ optionals (cfg.cmp.enable) [ ++ optionals cfg.cmp.enable [
"copilot-cmp" "copilot-cmp"
]; ];
vim.luaConfigRC.copilot = entryAnywhere '' vim.luaConfigRC.copilot = entryAnywhere ''
require("copilot").setup(${toLuaObject cfg.setupOpts}) require("copilot").setup(${toLuaObject cfg.setupOpts})
${lib.optionalString (cfg.cmp.enable) '' ${lib.optionalString cfg.cmp.enable ''
require("copilot_cmp").setup() require("copilot_cmp").setup()
''} ''}
''; '';

View File

@ -1,8 +1,4 @@
{ {lib, ...}: let
config,
lib,
...
}: let
inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) listOf attrs bool enum str oneOf int; inherit (lib.types) listOf attrs bool enum str oneOf int;
in { in {

View File

@ -103,11 +103,11 @@ in {
end end
end end
${optionalString (config.vim.ui.breadcrumbs.enable) ''local navic = require("nvim-navic")''} ${optionalString config.vim.ui.breadcrumbs.enable ''local navic = require("nvim-navic")''}
default_on_attach = function(client, bufnr) default_on_attach = function(client, bufnr)
attach_keymaps(client, bufnr) attach_keymaps(client, bufnr)
format_callback(client, bufnr) format_callback(client, bufnr)
${optionalString (config.vim.ui.breadcrumbs.enable) '' ${optionalString config.vim.ui.breadcrumbs.enable ''
-- let navic attach to buffers -- let navic attach to buffers
if client.server_capabilities.documentSymbolProvider then if client.server_capabilities.documentSymbolProvider then
navic.attach(client, bufnr) navic.attach(client, bufnr)

View File

@ -1,8 +1,4 @@
{ {lib, ...}: let
config,
lib,
...
}: let
inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkRenamedOptionModule; inherit (lib.modules) mkRenamedOptionModule;
inherit (lib.types) bool listOf str enum; inherit (lib.types) bool listOf str enum;

View File

@ -15,7 +15,7 @@
in { in {
config = mkMerge [ config = mkMerge [
# TODO: move into nvim-tree file # TODO: move into nvim-tree file
(mkIf (config.vim.filetree.nvimTree.enable) { (mkIf config.vim.filetree.nvimTree.enable {
vim.statusline.lualine.setupOpts = { vim.statusline.lualine.setupOpts = {
extensions = ["nvim-tree"]; extensions = ["nvim-tree"];
}; };
@ -44,11 +44,11 @@ in {
statusline.lualine.setupOpts = { statusline.lualine.setupOpts = {
options = { options = {
icons_enabled = cfg.icons.enable; icons_enabled = cfg.icons.enable;
theme = cfg.theme; inherit (cfg) theme;
component_separators = [cfg.componentSeparator.left cfg.componentSeparator.right]; component_separators = [cfg.componentSeparator.left cfg.componentSeparator.right];
section_separators = [cfg.sectionSeparator.left cfg.sectionSeparator.right]; section_separators = [cfg.sectionSeparator.left cfg.sectionSeparator.right];
globalstatus = cfg.globalStatus; globalstatus = cfg.globalStatus;
refresh = cfg.refresh; inherit (cfg) refresh;
}; };
sections = { sections = {

View File

@ -6,10 +6,7 @@
inherit (lib.trivial) boolToString warnIf; inherit (lib.trivial) boolToString warnIf;
in { in {
onedark = { onedark = {
setup = { setup = {style ? "dark"}: ''
style ? "dark",
transparent,
}: ''
-- OneDark theme -- OneDark theme
require('onedark').setup { require('onedark').setup {
style = "${style}" style = "${style}"
@ -33,10 +30,7 @@ in {
}; };
dracula = { dracula = {
setup = { setup = {transparent}: ''
style ? null,
transparent,
}: ''
require('dracula').setup({ require('dracula').setup({
transparent_bg = ${boolToString transparent}, transparent_bg = ${boolToString transparent},
}); });

View File

@ -1,8 +1,4 @@
{ {lib, ...}: let
config,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) attrsOf enum nullOr submodule bool str; inherit (lib.types) attrsOf enum nullOr submodule bool str;
inherit (lib.modules) mkRenamedOptionModule; inherit (lib.modules) mkRenamedOptionModule;

View File

@ -1,6 +1,6 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkOption mkEnableOption literalExpression; inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) nullOr int str attrsOf either listOf; inherit (lib.types) nullOr str attrsOf either listOf;
inherit (lib.modules) mkRenamedOptionModule; inherit (lib.modules) mkRenamedOptionModule;
inherit (lib.nvim.types) mkPluginSetupOption; inherit (lib.nvim.types) mkPluginSetupOption;
in { in {

View File

@ -1,8 +1,4 @@
{ {lib, ...}: let
config,
lib,
...
}: let
inherit (lib.options) mkEnableOption; inherit (lib.options) mkEnableOption;
in { in {
options.vim.binds.cheatsheet = { options.vim.binds.cheatsheet = {

View File

@ -8,7 +8,7 @@
cfg = config.vim.binds.cheatsheet; cfg = config.vim.binds.cheatsheet;
in { in {
config = mkIf (cfg.enable) { config = mkIf cfg.enable {
vim.startPlugins = ["cheatsheet-nvim"]; vim.startPlugins = ["cheatsheet-nvim"];
vim.luaConfigRC.cheaetsheet-nvim = entryAnywhere '' vim.luaConfigRC.cheaetsheet-nvim = entryAnywhere ''

View File

@ -10,7 +10,7 @@
cfg = config.vim.binds.whichKey; cfg = config.vim.binds.whichKey;
in { in {
config = mkIf (cfg.enable) { config = mkIf cfg.enable {
vim.startPlugins = ["which-key"]; vim.startPlugins = ["which-key"];
vim.luaConfigRC.whichkey = entryAnywhere '' vim.luaConfigRC.whichkey = entryAnywhere ''
@ -23,7 +23,7 @@ in {
["<tab>"] = "TAB", ["<tab>"] = "TAB",
}, },
${optionalString (config.vim.ui.borders.plugins.which-key.enable) '' ${optionalString config.vim.ui.borders.plugins.which-key.enable ''
window = { window = {
border = "${config.vim.ui.borders.plugins.which-key.style}", border = "${config.vim.ui.borders.plugins.which-key.style}",
}, },

View File

@ -1,8 +1,4 @@
{ {lib, ...}: let
config,
lib,
...
}: let
inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) attrsOf nullOr str; inherit (lib.types) attrsOf nullOr str;
in { in {

View File

@ -8,7 +8,7 @@
cfg = config.vim.utility.ccc; cfg = config.vim.utility.ccc;
in { in {
config = mkIf (cfg.enable) { config = mkIf cfg.enable {
vim.startPlugins = [ vim.startPlugins = [
"ccc" "ccc"
]; ];

View File

@ -7,7 +7,7 @@
cfg = config.vim.utility.diffview-nvim; cfg = config.vim.utility.diffview-nvim;
in { in {
config = mkIf (cfg.enable) { config = mkIf cfg.enable {
vim.startPlugins = [ vim.startPlugins = [
"diffview-nvim" "diffview-nvim"
"plenary-nvim" "plenary-nvim"

View File

@ -8,7 +8,7 @@
cfg = config.vim.utility.icon-picker; cfg = config.vim.utility.icon-picker;
in { in {
config = mkIf (cfg.enable) { config = mkIf cfg.enable {
vim.startPlugins = [ vim.startPlugins = [
"icon-picker-nvim" "icon-picker-nvim"
"dressing-nvim" "dressing-nvim"

View File

@ -1,7 +1,6 @@
{ {
config, config,
lib, lib,
pkgs,
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;

View File

@ -1,8 +1,4 @@
{ {lib, ...}: let
config,
lib,
...
}: let
inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) enum listOf str nullOr int; inherit (lib.types) enum listOf str nullOr int;

View File

@ -12,7 +12,7 @@
self = import ./glow.nix { self = import ./glow.nix {
inherit lib config pkgs; inherit lib config pkgs;
}; };
mappings = self.options.vim.utility.preview.glow.mappings; inherit (self.options.vim.utility.preview.glow) mappings;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = ["glow-nvim"]; vim.startPlugins = ["glow-nvim"];

View File

@ -16,7 +16,7 @@
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
in { in {
config = mkIf (cfg.enable) { config = mkIf cfg.enable {
vim.startPlugins = [ vim.startPlugins = [
"telescope" "telescope"
"plenary-nvim" "plenary-nvim"

View File

@ -9,7 +9,7 @@
cfg = config.vim.utility.vim-wakatime; cfg = config.vim.utility.vim-wakatime;
in { in {
config = mkIf (cfg.enable) { config = mkIf cfg.enable {
vim.startPlugins = [ vim.startPlugins = [
pkgs.vimPlugins.vim-wakatime pkgs.vimPlugins.vim-wakatime
]; ];

View File

@ -6,7 +6,7 @@
inherit (builtins) map mapAttrs toJSON filter; inherit (builtins) map mapAttrs toJSON filter;
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.attrsets) filterAttrs getAttrs attrValues attrNames; inherit (lib.attrsets) filterAttrs getAttrs attrValues attrNames;
inherit (lib.strings) isString concatStringsSep; inherit (lib.strings) isString concatLines concatMapStringsSep;
inherit (lib.misc) mapAttrsFlatten; inherit (lib.misc) mapAttrsFlatten;
inherit (lib.trivial) showWarnings; inherit (lib.trivial) showWarnings;
inherit (lib.types) str nullOr; inherit (lib.types) str nullOr;
@ -126,7 +126,7 @@ in {
in { in {
vim = { vim = {
configRC = { configRC = {
globalsScript = entryAnywhere (concatStringsSep "\n" globalsScript); globalsScript = entryAnywhere (concatLines globalsScript);
# Call additional lua files with :luafile in Vimscript # Call additional lua files with :luafile in Vimscript
# section of the configuration, only after # section of the configuration, only after
@ -134,14 +134,14 @@ in {
extraLuaFiles = let extraLuaFiles = let
callLuaFiles = map (file: "luafile ${file}") cfg.extraLuaFiles; callLuaFiles = map (file: "luafile ${file}") cfg.extraLuaFiles;
in in
entryAfter ["globalScript"] (concatStringsSep "\n" callLuaFiles); entryAfter ["globalScript"] (concatLines callLuaFiles);
# wrap the lua config in a lua block # wrap the lua config in a lua block
# using the wrapLuaConfic function from the lib # using the wrapLuaConfic function from the lib
luaScript = let luaScript = let
mapResult = result: (wrapLuaConfig { mapResult = result: (wrapLuaConfig {
luaBefore = "${cfg.luaConfigPre}"; luaBefore = "${cfg.luaConfigPre}";
luaConfig = concatStringsSep "\n" (map mkLuarcSection result); luaConfig = concatLines (map mkLuarcSection result);
luaAfter = "${cfg.luaConfigPost}"; luaAfter = "${cfg.luaConfigPost}";
}); });
@ -155,7 +155,7 @@ in {
extraPluginConfigs = let extraPluginConfigs = let
mapResult = result: (wrapLuaConfig { mapResult = result: (wrapLuaConfig {
luaConfig = concatStringsSep "\n" (map mkLuarcSection result); luaConfig = concatLines (map mkLuarcSection result);
}); });
extraPluginsDag = mapAttrs (_: { extraPluginsDag = mapAttrs (_: {
@ -189,7 +189,7 @@ in {
icmap icmap
allmap allmap
]; ];
mapConfig = wrapLuaConfig {luaConfig = concatStringsSep "\n" (map (v: concatStringsSep "\n" v) maps);}; mapConfig = wrapLuaConfig {luaConfig = concatLines (map concatLines maps);};
in in
entryAfter ["globalsScript"] mapConfig; entryAfter ["globalsScript"] mapConfig;
}; };
@ -200,10 +200,10 @@ in {
failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions); failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions);
baseSystemAssertWarn = baseSystemAssertWarn =
if failedAssertions != [] if failedAssertions != []
then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}" then throw "\nFailed assertions:\n${concatMapStringsSep "\n" (x: "- ${x}") failedAssertions}"
else showWarnings config.warnings; else showWarnings config.warnings;
mapResult = result: (concatStringsSep "\n" (map mkVimrcSection result)); mapResult = result: concatMapStringsSep "\n" mkVimrcSection result;
vimConfig = resolveDag { vimConfig = resolveDag {
name = "vim config script"; name = "vim config script";
dag = cfg.configRC; dag = cfg.configRC;