From 8d5f23035d43b1f79ef82d4bc02df3d63b01c5bf Mon Sep 17 00:00:00 2001 From: Gerg-L <88247690+Gerg-L@users.noreply.github.com> Date: Mon, 8 Jul 2024 21:57:58 +0000 Subject: [PATCH] treewide: cleanup (#324) * statix, deadnix, alejandra * _file * _module.args * concatStringsSep "\n" -> concatLines concatStringsSep "\n" map -> concatMapStringsSep "\n" * mkShell nativeBuildInputs -> packages --- flake.nix | 17 ++++++----------- flake/modules/home-manager.nix | 1 + flake/modules/nixos.nix | 1 + flake/packages.nix | 1 - lib/binds.nix | 2 +- lib/dag.nix | 3 +-- lib/lua.nix | 4 ++-- lib/types/plugins.nix | 2 +- modules/plugins/assistant/copilot/config.nix | 4 ++-- modules/plugins/dashboard/startify/startify.nix | 6 +----- modules/plugins/lsp/config.nix | 4 ++-- .../projects/project-nvim/project-nvim.nix | 6 +----- modules/plugins/statusline/lualine/config.nix | 6 +++--- modules/plugins/theme/supported_themes.nix | 10 ++-------- modules/plugins/ui/colorizer/colorizer.nix | 6 +----- modules/plugins/ui/smartcolumn/smartcolumn.nix | 2 +- .../utility/binds/cheatsheet/cheatsheet.nix | 6 +----- .../plugins/utility/binds/cheatsheet/config.nix | 2 +- .../plugins/utility/binds/which-key/config.nix | 4 ++-- .../utility/binds/which-key/which-key.nix | 6 +----- modules/plugins/utility/ccc/config.nix | 2 +- modules/plugins/utility/diffview/config.nix | 2 +- modules/plugins/utility/icon-picker/config.nix | 2 +- .../utility/images/image-nvim/config.nix | 1 - .../utility/images/image-nvim/image-nvim.nix | 6 +----- modules/plugins/utility/preview/glow/config.nix | 2 +- modules/plugins/utility/telescope/config.nix | 2 +- modules/plugins/utility/wakatime/config.nix | 2 +- modules/wrapper/rc/config.nix | 16 ++++++++-------- 29 files changed, 46 insertions(+), 82 deletions(-) diff --git a/flake.nix b/flake.nix index e333241..a10cd43 100644 --- a/flake.nix +++ b/flake.nix @@ -10,16 +10,15 @@ # provide overridable systems # https://github.com/nix-systems/nix-systems systems = import inputs.systems; - imports = [ - # add lib to module args - {_module.args = {inherit (nixpkgs) lib;};} ./flake/apps.nix ./flake/legacyPackages.nix ./flake/overlays.nix ./flake/packages.nix ]; + _module.args = {inherit (nixpkgs) lib;}; + flake = { lib = { inherit (import ./lib/stdlib-extended.nix nixpkgs.lib inputs) nvim; @@ -34,9 +33,7 @@ '' self.homeManagerModules.nvf; - nvf = { - imports = [(import ./flake/modules/home-manager.nix self.packages inputs)]; - }; + nvf = import ./flake/modules/home-manager.nix self.packages inputs; default = self.homeManagerModules.nvf; }; @@ -49,9 +46,7 @@ '' self.nixosModules.nvf; - nvf = { - imports = [(import ./flake/modules/nixos.nix self.packages inputs)]; - }; + nvf = import ./flake/modules/nixos.nix self.packages inputs; default = self.nixosModules.nvf; }; @@ -66,9 +61,9 @@ formatter = pkgs.alejandra; devShells = { default = self'.devShells.lsp; - nvim-nix = pkgs.mkShell {nativeBuildInputs = [config.packages.nix];}; + nvim-nix = pkgs.mkShell {packages = [config.packages.nix];}; lsp = pkgs.mkShell { - nativeBuildInputs = with pkgs; [nil statix deadnix alejandra]; + packages = with pkgs; [nil statix deadnix alejandra]; }; }; }; diff --git a/flake/modules/home-manager.nix b/flake/modules/home-manager.nix index 585f3ce..81662ed 100644 --- a/flake/modules/home-manager.nix +++ b/flake/modules/home-manager.nix @@ -88,4 +88,5 @@ in { ++ optional cfg.enableManpages packages.${pkgs.stdenv.system}.docs-manpages; }; }; + _file = ./home-manager.nix; } diff --git a/flake/modules/nixos.nix b/flake/modules/nixos.nix index 3a1bf76..2b1f6d7 100644 --- a/flake/modules/nixos.nix +++ b/flake/modules/nixos.nix @@ -88,4 +88,5 @@ in { ++ optional cfg.enableManpages packages.${pkgs.stdenv.system}.docs-manpages; }; }; + _file = ./nixos.nix; } diff --git a/flake/packages.nix b/flake/packages.nix index 3724905..36f660a 100644 --- a/flake/packages.nix +++ b/flake/packages.nix @@ -1,6 +1,5 @@ {inputs, ...}: { perSystem = { - system, config, pkgs, ... diff --git a/lib/binds.nix b/lib/binds.nix index d42a414..8c9e9a6 100644 --- a/lib/binds.nix +++ b/lib/binds.nix @@ -66,7 +66,7 @@ mkSetLuaBinding = binding: action: mkLuaBinding binding.value action binding.description; - pushDownDefault = attr: mapAttrs (_: value: mkDefault value) attr; + pushDownDefault = attr: mapAttrs (_: mkDefault) attr; }; in binds diff --git a/lib/dag.nix b/lib/dag.nix index ccb2a61..d740f6a 100644 --- a/lib/dag.nix +++ b/lib/dag.nix @@ -84,7 +84,7 @@ in { normalizedDag = mapAttrs (n: v: { name = n; - data = v.data; + inherit (v) data; after = v.after ++ dagBefore dag n; }) dag; @@ -117,7 +117,6 @@ in { entriesBetween = tag: let go = i: before: after: entries: let name = "${tag}-${toString i}"; - i' = i + 1; in if entries == [] then empty diff --git a/lib/lua.nix b/lib/lua.nix index 749e9a3..167839e 100644 --- a/lib/lua.nix +++ b/lib/lua.nix @@ -2,7 +2,7 @@ {lib}: let inherit (builtins) hasAttr head throw typeOf isList isAttrs isBool isInt isString isPath isFloat toJSON; inherit (lib.attrsets) mapAttrsToList filterAttrs; - inherit (lib.strings) concatStringsSep concatMapStringsSep stringToCharacters; + inherit (lib.strings) concatStringsSep concatMapStringsSep stringToCharacters concatLines; inherit (lib.trivial) boolToString warn; in rec { wrapLuaConfig = { @@ -11,7 +11,7 @@ in rec { luaAfter ? "", }: '' lua << EOF - ${concatStringsSep "\n" [luaBefore luaConfig luaAfter]} + ${concatLines [luaBefore luaConfig luaAfter]} EOF ''; diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index d9cc5f2..e10547f 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -5,7 +5,7 @@ }: let inherit (lib.options) mkOption; 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; # Get the names of all flake inputs that start with the given prefix. diff --git a/modules/plugins/assistant/copilot/config.nix b/modules/plugins/assistant/copilot/config.nix index 0d3ee28..b7adc82 100644 --- a/modules/plugins/assistant/copilot/config.nix +++ b/modules/plugins/assistant/copilot/config.nix @@ -30,14 +30,14 @@ in { "copilot-lua" # cfg.copilotNodePackage ] - ++ optionals (cfg.cmp.enable) [ + ++ optionals cfg.cmp.enable [ "copilot-cmp" ]; vim.luaConfigRC.copilot = entryAnywhere '' require("copilot").setup(${toLuaObject cfg.setupOpts}) - ${lib.optionalString (cfg.cmp.enable) '' + ${lib.optionalString cfg.cmp.enable '' require("copilot_cmp").setup() ''} ''; diff --git a/modules/plugins/dashboard/startify/startify.nix b/modules/plugins/dashboard/startify/startify.nix index fa70a4d..02ee916 100644 --- a/modules/plugins/dashboard/startify/startify.nix +++ b/modules/plugins/dashboard/startify/startify.nix @@ -1,8 +1,4 @@ -{ - config, - lib, - ... -}: let +{lib, ...}: let inherit (lib.options) mkEnableOption mkOption; inherit (lib.types) listOf attrs bool enum str oneOf int; in { diff --git a/modules/plugins/lsp/config.nix b/modules/plugins/lsp/config.nix index d91a4fb..93e3da6 100644 --- a/modules/plugins/lsp/config.nix +++ b/modules/plugins/lsp/config.nix @@ -103,11 +103,11 @@ in { 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) attach_keymaps(client, bufnr) format_callback(client, bufnr) - ${optionalString (config.vim.ui.breadcrumbs.enable) '' + ${optionalString config.vim.ui.breadcrumbs.enable '' -- let navic attach to buffers if client.server_capabilities.documentSymbolProvider then navic.attach(client, bufnr) diff --git a/modules/plugins/projects/project-nvim/project-nvim.nix b/modules/plugins/projects/project-nvim/project-nvim.nix index b9a9eff..91128da 100644 --- a/modules/plugins/projects/project-nvim/project-nvim.nix +++ b/modules/plugins/projects/project-nvim/project-nvim.nix @@ -1,8 +1,4 @@ -{ - config, - lib, - ... -}: let +{lib, ...}: let inherit (lib.options) mkEnableOption mkOption; inherit (lib.modules) mkRenamedOptionModule; inherit (lib.types) bool listOf str enum; diff --git a/modules/plugins/statusline/lualine/config.nix b/modules/plugins/statusline/lualine/config.nix index 5479595..08b1e08 100644 --- a/modules/plugins/statusline/lualine/config.nix +++ b/modules/plugins/statusline/lualine/config.nix @@ -15,7 +15,7 @@ in { config = mkMerge [ # TODO: move into nvim-tree file - (mkIf (config.vim.filetree.nvimTree.enable) { + (mkIf config.vim.filetree.nvimTree.enable { vim.statusline.lualine.setupOpts = { extensions = ["nvim-tree"]; }; @@ -44,11 +44,11 @@ in { statusline.lualine.setupOpts = { options = { icons_enabled = cfg.icons.enable; - theme = cfg.theme; + inherit (cfg) theme; component_separators = [cfg.componentSeparator.left cfg.componentSeparator.right]; section_separators = [cfg.sectionSeparator.left cfg.sectionSeparator.right]; globalstatus = cfg.globalStatus; - refresh = cfg.refresh; + inherit (cfg) refresh; }; sections = { diff --git a/modules/plugins/theme/supported_themes.nix b/modules/plugins/theme/supported_themes.nix index f28905d..6d992c4 100644 --- a/modules/plugins/theme/supported_themes.nix +++ b/modules/plugins/theme/supported_themes.nix @@ -6,10 +6,7 @@ inherit (lib.trivial) boolToString warnIf; in { onedark = { - setup = { - style ? "dark", - transparent, - }: '' + setup = {style ? "dark"}: '' -- OneDark theme require('onedark').setup { style = "${style}" @@ -33,10 +30,7 @@ in { }; dracula = { - setup = { - style ? null, - transparent, - }: '' + setup = {transparent}: '' require('dracula').setup({ transparent_bg = ${boolToString transparent}, }); diff --git a/modules/plugins/ui/colorizer/colorizer.nix b/modules/plugins/ui/colorizer/colorizer.nix index 02ab967..313097e 100644 --- a/modules/plugins/ui/colorizer/colorizer.nix +++ b/modules/plugins/ui/colorizer/colorizer.nix @@ -1,8 +1,4 @@ -{ - config, - lib, - ... -}: let +{lib, ...}: let inherit (lib.options) mkOption mkEnableOption; inherit (lib.types) attrsOf enum nullOr submodule bool str; inherit (lib.modules) mkRenamedOptionModule; diff --git a/modules/plugins/ui/smartcolumn/smartcolumn.nix b/modules/plugins/ui/smartcolumn/smartcolumn.nix index 48bf549..8e73a1f 100644 --- a/modules/plugins/ui/smartcolumn/smartcolumn.nix +++ b/modules/plugins/ui/smartcolumn/smartcolumn.nix @@ -1,6 +1,6 @@ {lib, ...}: let 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.nvim.types) mkPluginSetupOption; in { diff --git a/modules/plugins/utility/binds/cheatsheet/cheatsheet.nix b/modules/plugins/utility/binds/cheatsheet/cheatsheet.nix index cddc6a5..d410fbc 100644 --- a/modules/plugins/utility/binds/cheatsheet/cheatsheet.nix +++ b/modules/plugins/utility/binds/cheatsheet/cheatsheet.nix @@ -1,8 +1,4 @@ -{ - config, - lib, - ... -}: let +{lib, ...}: let inherit (lib.options) mkEnableOption; in { options.vim.binds.cheatsheet = { diff --git a/modules/plugins/utility/binds/cheatsheet/config.nix b/modules/plugins/utility/binds/cheatsheet/config.nix index d0edf10..05b7887 100644 --- a/modules/plugins/utility/binds/cheatsheet/config.nix +++ b/modules/plugins/utility/binds/cheatsheet/config.nix @@ -8,7 +8,7 @@ cfg = config.vim.binds.cheatsheet; in { - config = mkIf (cfg.enable) { + config = mkIf cfg.enable { vim.startPlugins = ["cheatsheet-nvim"]; vim.luaConfigRC.cheaetsheet-nvim = entryAnywhere '' diff --git a/modules/plugins/utility/binds/which-key/config.nix b/modules/plugins/utility/binds/which-key/config.nix index 238d888..e6aa2d9 100644 --- a/modules/plugins/utility/binds/which-key/config.nix +++ b/modules/plugins/utility/binds/which-key/config.nix @@ -10,7 +10,7 @@ cfg = config.vim.binds.whichKey; in { - config = mkIf (cfg.enable) { + config = mkIf cfg.enable { vim.startPlugins = ["which-key"]; vim.luaConfigRC.whichkey = entryAnywhere '' @@ -23,7 +23,7 @@ in { [""] = "TAB", }, - ${optionalString (config.vim.ui.borders.plugins.which-key.enable) '' + ${optionalString config.vim.ui.borders.plugins.which-key.enable '' window = { border = "${config.vim.ui.borders.plugins.which-key.style}", }, diff --git a/modules/plugins/utility/binds/which-key/which-key.nix b/modules/plugins/utility/binds/which-key/which-key.nix index feb8d76..3851cd9 100644 --- a/modules/plugins/utility/binds/which-key/which-key.nix +++ b/modules/plugins/utility/binds/which-key/which-key.nix @@ -1,8 +1,4 @@ -{ - config, - lib, - ... -}: let +{lib, ...}: let inherit (lib.options) mkEnableOption mkOption; inherit (lib.types) attrsOf nullOr str; in { diff --git a/modules/plugins/utility/ccc/config.nix b/modules/plugins/utility/ccc/config.nix index a9589bb..b8c4315 100644 --- a/modules/plugins/utility/ccc/config.nix +++ b/modules/plugins/utility/ccc/config.nix @@ -8,7 +8,7 @@ cfg = config.vim.utility.ccc; in { - config = mkIf (cfg.enable) { + config = mkIf cfg.enable { vim.startPlugins = [ "ccc" ]; diff --git a/modules/plugins/utility/diffview/config.nix b/modules/plugins/utility/diffview/config.nix index ffe8a58..681a305 100644 --- a/modules/plugins/utility/diffview/config.nix +++ b/modules/plugins/utility/diffview/config.nix @@ -7,7 +7,7 @@ cfg = config.vim.utility.diffview-nvim; in { - config = mkIf (cfg.enable) { + config = mkIf cfg.enable { vim.startPlugins = [ "diffview-nvim" "plenary-nvim" diff --git a/modules/plugins/utility/icon-picker/config.nix b/modules/plugins/utility/icon-picker/config.nix index 79cd376..aa61d04 100644 --- a/modules/plugins/utility/icon-picker/config.nix +++ b/modules/plugins/utility/icon-picker/config.nix @@ -8,7 +8,7 @@ cfg = config.vim.utility.icon-picker; in { - config = mkIf (cfg.enable) { + config = mkIf cfg.enable { vim.startPlugins = [ "icon-picker-nvim" "dressing-nvim" diff --git a/modules/plugins/utility/images/image-nvim/config.nix b/modules/plugins/utility/images/image-nvim/config.nix index cd188ac..52666d3 100644 --- a/modules/plugins/utility/images/image-nvim/config.nix +++ b/modules/plugins/utility/images/image-nvim/config.nix @@ -1,7 +1,6 @@ { config, lib, - pkgs, ... }: let inherit (lib.modules) mkIf; diff --git a/modules/plugins/utility/images/image-nvim/image-nvim.nix b/modules/plugins/utility/images/image-nvim/image-nvim.nix index 6433e50..5fa7fdb 100644 --- a/modules/plugins/utility/images/image-nvim/image-nvim.nix +++ b/modules/plugins/utility/images/image-nvim/image-nvim.nix @@ -1,8 +1,4 @@ -{ - config, - lib, - ... -}: let +{lib, ...}: let inherit (lib.options) mkEnableOption mkOption; inherit (lib.types) enum listOf str nullOr int; diff --git a/modules/plugins/utility/preview/glow/config.nix b/modules/plugins/utility/preview/glow/config.nix index 1f95f89..04e8aa0 100644 --- a/modules/plugins/utility/preview/glow/config.nix +++ b/modules/plugins/utility/preview/glow/config.nix @@ -12,7 +12,7 @@ self = import ./glow.nix { inherit lib config pkgs; }; - mappings = self.options.vim.utility.preview.glow.mappings; + inherit (self.options.vim.utility.preview.glow) mappings; in { config = mkIf cfg.enable { vim.startPlugins = ["glow-nvim"]; diff --git a/modules/plugins/utility/telescope/config.nix b/modules/plugins/utility/telescope/config.nix index 0ed553a..f59f816 100644 --- a/modules/plugins/utility/telescope/config.nix +++ b/modules/plugins/utility/telescope/config.nix @@ -16,7 +16,7 @@ mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; in { - config = mkIf (cfg.enable) { + config = mkIf cfg.enable { vim.startPlugins = [ "telescope" "plenary-nvim" diff --git a/modules/plugins/utility/wakatime/config.nix b/modules/plugins/utility/wakatime/config.nix index e6332d5..1185db5 100644 --- a/modules/plugins/utility/wakatime/config.nix +++ b/modules/plugins/utility/wakatime/config.nix @@ -9,7 +9,7 @@ cfg = config.vim.utility.vim-wakatime; in { - config = mkIf (cfg.enable) { + config = mkIf cfg.enable { vim.startPlugins = [ pkgs.vimPlugins.vim-wakatime ]; diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index c278562..c35b3e7 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -6,7 +6,7 @@ inherit (builtins) map mapAttrs toJSON filter; inherit (lib.options) mkOption; inherit (lib.attrsets) filterAttrs getAttrs attrValues attrNames; - inherit (lib.strings) isString concatStringsSep; + inherit (lib.strings) isString concatLines concatMapStringsSep; inherit (lib.misc) mapAttrsFlatten; inherit (lib.trivial) showWarnings; inherit (lib.types) str nullOr; @@ -126,7 +126,7 @@ in { in { vim = { configRC = { - globalsScript = entryAnywhere (concatStringsSep "\n" globalsScript); + globalsScript = entryAnywhere (concatLines globalsScript); # Call additional lua files with :luafile in Vimscript # section of the configuration, only after @@ -134,14 +134,14 @@ in { extraLuaFiles = let callLuaFiles = map (file: "luafile ${file}") cfg.extraLuaFiles; in - entryAfter ["globalScript"] (concatStringsSep "\n" callLuaFiles); + entryAfter ["globalScript"] (concatLines callLuaFiles); # wrap the lua config in a lua block # using the wrapLuaConfic function from the lib luaScript = let mapResult = result: (wrapLuaConfig { luaBefore = "${cfg.luaConfigPre}"; - luaConfig = concatStringsSep "\n" (map mkLuarcSection result); + luaConfig = concatLines (map mkLuarcSection result); luaAfter = "${cfg.luaConfigPost}"; }); @@ -155,7 +155,7 @@ in { extraPluginConfigs = let mapResult = result: (wrapLuaConfig { - luaConfig = concatStringsSep "\n" (map mkLuarcSection result); + luaConfig = concatLines (map mkLuarcSection result); }); extraPluginsDag = mapAttrs (_: { @@ -189,7 +189,7 @@ in { icmap allmap ]; - mapConfig = wrapLuaConfig {luaConfig = concatStringsSep "\n" (map (v: concatStringsSep "\n" v) maps);}; + mapConfig = wrapLuaConfig {luaConfig = concatLines (map concatLines maps);}; in entryAfter ["globalsScript"] mapConfig; }; @@ -200,10 +200,10 @@ in { 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)}" + then throw "\nFailed assertions:\n${concatMapStringsSep "\n" (x: "- ${x}") failedAssertions}" else showWarnings config.warnings; - mapResult = result: (concatStringsSep "\n" (map mkVimrcSection result)); + mapResult = result: concatMapStringsSep "\n" mkVimrcSection result; vimConfig = resolveDag { name = "vim config script"; dag = cfg.configRC;