diff --git a/default.nix b/default.nix index 2b625713d6..1d976a3576 100644 --- a/default.nix +++ b/default.nix @@ -1,14 +1,11 @@ -( - import - ( - let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in - fetchTarball { - url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } - ) - {src = ./.;} -) -.defaultNix +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = + lock.nodes.flake-compat.locked.url + or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } +) { src = ./.; }).defaultNix diff --git a/docs/default.nix b/docs/default.nix index 12164fbcc9..f149fe3976 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -2,18 +2,19 @@ rawModules, helpers, pkgs, -}: let +}: +let pkgsDoc = - import (pkgs.applyPatches { - name = "nixpkgs-nixvim-doc"; - src = pkgs.path; - patches = [ - ./either_recursive.patch - ]; - }) { - inherit (pkgs) system; - config.allowUnfree = true; - }; + import + (pkgs.applyPatches { + name = "nixpkgs-nixvim-doc"; + src = pkgs.path; + patches = [ ./either_recursive.patch ]; + }) + { + inherit (pkgs) system; + config.allowUnfree = true; + }; inherit (pkgsDoc) lib; @@ -24,21 +25,21 @@ name = "<${repo}/${subpath}>"; }; - transformOptions = opt: + transformOptions = + opt: opt // { - declarations = - map ( - decl: - if lib.hasPrefix nixvimPath (toString decl) - then - gitHubDeclaration "nix-community" "nixvim" "main" - (lib.removePrefix "/" (lib.removePrefix nixvimPath (toString decl))) - else if decl == "lib/modules.nix" - then gitHubDeclaration "NixOS" "nixpkgs" "master" decl - else decl - ) - opt.declarations; + declarations = map ( + decl: + if lib.hasPrefix nixvimPath (toString decl) then + gitHubDeclaration "nix-community" "nixvim" "main" ( + lib.removePrefix "/" (lib.removePrefix nixvimPath (toString decl)) + ) + else if decl == "lib/modules.nix" then + gitHubDeclaration "NixOS" "nixpkgs" "master" decl + else + decl + ) opt.declarations; }; nixvmConfigType = lib.mkOptionType { @@ -48,61 +49,51 @@ # Evaluation is irrelevant, only used for documentation. }; - topLevelModules = - [ - ../wrappers/modules/output.nix - # Fake module to avoid a duplicated documentation - (lib.setDefaultModuleLocation "${nixvimPath}/wrappers/modules/files.nix" { - options.files = lib.mkOption { - type = lib.types.attrsOf nixvmConfigType; - description = "Extra files to add to the runtimepath"; - example = { - "ftplugin/nix.lua" = { - options = { - tabstop = 2; - shiftwidth = 2; - expandtab = true; - }; + topLevelModules = [ + ../wrappers/modules/output.nix + # Fake module to avoid a duplicated documentation + (lib.setDefaultModuleLocation "${nixvimPath}/wrappers/modules/files.nix" { + options.files = lib.mkOption { + type = lib.types.attrsOf nixvmConfigType; + description = "Extra files to add to the runtimepath"; + example = { + "ftplugin/nix.lua" = { + options = { + tabstop = 2; + shiftwidth = 2; + expandtab = true; }; }; }; - }) - ] - ++ (rawModules pkgsDoc); - - hmOptions = - builtins.removeAttrs - (lib.evalModules { - modules = [ - (import ../wrappers/modules/hm.nix {inherit lib;}) - ]; + }; }) - .options - ["_module"]; + ] ++ (rawModules pkgsDoc); + + hmOptions = builtins.removeAttrs (lib.evalModules { + modules = [ (import ../wrappers/modules/hm.nix { inherit lib; }) ]; + }).options [ "_module" ]; in - rec { - options-json = - (pkgsDoc.nixosOptionsDoc - { - inherit - (lib.evalModules { - modules = topLevelModules; - specialArgs.helpers = helpers; - }) - options - ; - inherit transformOptions; - warningsAreErrors = false; +rec { + options-json = + (pkgsDoc.nixosOptionsDoc { + inherit + (lib.evalModules { + modules = topLevelModules; + specialArgs.helpers = helpers; }) - .optionsJSON; - man-docs = pkgsDoc.callPackage ./man {inherit options-json;}; - } - # Do not check if documentation builds fine on darwin as it fails: - # > sandbox-exec: pattern serialization length 69298 exceeds maximum (65535) - // lib.optionalAttrs (!pkgsDoc.stdenv.isDarwin) { - docs = pkgsDoc.callPackage ./mdbook { + options + ; inherit transformOptions; - modules = topLevelModules; - inherit helpers hmOptions; - }; - } + warningsAreErrors = false; + }).optionsJSON; + man-docs = pkgsDoc.callPackage ./man { inherit options-json; }; +} +# Do not check if documentation builds fine on darwin as it fails: +# > sandbox-exec: pattern serialization length 69298 exceeds maximum (65535) +// lib.optionalAttrs (!pkgsDoc.stdenv.isDarwin) { + docs = pkgsDoc.callPackage ./mdbook { + inherit transformOptions; + modules = topLevelModules; + inherit helpers hmOptions; + }; +} diff --git a/docs/man/default.nix b/docs/man/default.nix index 25b996b4ff..38eafbcf17 100644 --- a/docs/man/default.nix +++ b/docs/man/default.nix @@ -4,7 +4,8 @@ installShellFiles, nixos-render-docs, pandoc, -}: let +}: +let manualFilter = '' local text = pandoc.text @@ -23,26 +24,34 @@ end ''; - manHeader = let - mkMDSection = file: "<(pandoc --lua-filter <(echo \"$manualFilter\") -f gfm -t man ${file})"; - in - runCommand "nixvim-general-doc-manpage" { - nativeBuildInputs = [pandoc]; - inherit manualFilter; - } '' - mkdir -p $out - cat \ - ${./nixvim-header-start.5} \ - ${mkMDSection ../user-guide/helpers.md} \ - ${mkMDSection ../user-guide/faq.md} \ - ${./nixvim-header-end.5} \ - >$out/nixvim-header.5 - ''; - # FIXME add platform specific docs to manpage + manHeader = + let + mkMDSection = file: "<(pandoc --lua-filter <(echo \"$manualFilter\") -f gfm -t man ${file})"; + in + runCommand "nixvim-general-doc-manpage" + { + nativeBuildInputs = [ pandoc ]; + inherit manualFilter; + } + '' + mkdir -p $out + cat \ + ${./nixvim-header-start.5} \ + ${mkMDSection ../user-guide/helpers.md} \ + ${mkMDSection ../user-guide/faq.md} \ + ${./nixvim-header-end.5} \ + >$out/nixvim-header.5 + ''; in - runCommand "nixvim-configuration-reference-manpage" { - nativeBuildInputs = [installShellFiles nixos-render-docs]; - } '' +# FIXME add platform specific docs to manpage +runCommand "nixvim-configuration-reference-manpage" + { + nativeBuildInputs = [ + installShellFiles + nixos-render-docs + ]; + } + '' # Generate man-pages mkdir -p $out/share/man/man5 nixos-render-docs -j $NIX_BUILD_CORES options manpage \ diff --git a/docs/mdbook/default.nix b/docs/mdbook/default.nix index 81615c124a..b92df25b81 100644 --- a/docs/mdbook/default.nix +++ b/docs/mdbook/default.nix @@ -7,22 +7,26 @@ transformOptions, hmOptions, }: -with lib; let +with lib; +let options = lib.evalModules { inherit modules; - specialArgs = {inherit pkgs lib helpers;}; + specialArgs = { + inherit pkgs lib helpers; + }; }; inherit (options.config.meta) nixvimInfo; - mkMDDoc = options: + mkMDDoc = + options: (nixosOptionsDoc { inherit options transformOptions; warningsAreErrors = false; - }) - .optionsCommonMark; + }).optionsCommonMark; - removeUnwanted = attrs: + removeUnwanted = + attrs: builtins.removeAttrs attrs [ "_module" "_freeformOptions" @@ -31,215 +35,199 @@ with lib; let "content" ]; - removeWhitespace = builtins.replaceStrings [" "] [""]; + removeWhitespace = builtins.replaceStrings [ " " ] [ "" ]; getSubOptions = opts: path: removeUnwanted (opts.type.getSubOptions path); - isVisible = opts: - if isOption opts - then attrByPath ["visible"] true opts - else if opts.isOption - then attrByPath ["index" "options" "visible"] true opts - else let - filterFunc = - filterAttrs - ( - _: v: - if isAttrs v - then isVisible v - else true - ); + isVisible = + opts: + if isOption opts then + attrByPath [ "visible" ] true opts + else if opts.isOption then + attrByPath [ + "index" + "options" + "visible" + ] true opts + else + let + filterFunc = filterAttrs (_: v: if isAttrs v then isVisible v else true); - hasEmptyIndex = (filterFunc opts.index.options) == {}; - hasEmptyComponents = (filterFunc opts.components) == {}; - in + hasEmptyIndex = (filterFunc opts.index.options) == { }; + hasEmptyComponents = (filterFunc opts.components) == { }; + in !hasEmptyIndex || !hasEmptyComponents; wrapModule = path: opts: isOpt: rec { index = { options = - if isOpt - then opts - else filterAttrs (_: component: component.isOption && (isVisible component)) opts; + if isOpt then + opts + else + filterAttrs (_: component: component.isOption && (isVisible component)) opts; path = removeWhitespace (concatStringsSep "/" path); moduleDoc = - if builtins.length path >= 2 && lib.hasAttrByPath path nixvimInfo - then let - info = lib.getAttrFromPath path nixvimInfo; - maintainers = lib.unique (options.config.meta.maintainers.${info.file} or []); - maintainersNames = builtins.map (m: m.name) maintainers; - in + if builtins.length path >= 2 && lib.hasAttrByPath path nixvimInfo then + let + info = lib.getAttrFromPath path nixvimInfo; + maintainers = lib.unique (options.config.meta.maintainers.${info.file} or [ ]); + maintainersNames = builtins.map (m: m.name) maintainers; + in "# ${lib.last path}\n\n" + (lib.optionalString (info.description != null) "${info.description}\n\n") + (lib.optionalString (info.url != null) "**Url:** [${info.url}](${info.url})\n\n") - + (lib.optionalString (builtins.length maintainers > 0) - "**Maintainers:** ${lib.concatStringsSep ", " maintainersNames}\n\n") - else null; + + (lib.optionalString ( + builtins.length maintainers > 0 + ) "**Maintainers:** ${lib.concatStringsSep ", " maintainersNames}\n\n") + else + null; }; components = - if isOpt - then {} - else filterAttrs (_: component: !component.isOption && (isVisible component)) opts; + if isOpt then + { } + else + filterAttrs (_: component: !component.isOption && (isVisible component)) opts; - hasComponents = components != {}; + hasComponents = components != { }; isOption = isOpt; }; - processModulesRec = modules: let - recurse = path: mods: let - g = name: opts: - if !isOption opts - then wrapModule (path ++ [name]) (recurse (path ++ [name]) opts) false - else let - subOpts = getSubOptions opts (path ++ [name]); + processModulesRec = + modules: + let + recurse = + path: mods: + let + g = + name: opts: + if !isOption opts then + wrapModule (path ++ [ name ]) (recurse (path ++ [ name ]) opts) false + else + let + subOpts = getSubOptions opts (path ++ [ name ]); + in + if subOpts != { } then + wrapModule (path ++ [ name ]) ( + (recurse (path ++ [ name ]) subOpts) + // { + # This is necessary to include the submodule option's definition in the docs (description, type, etc.) + # For instance, this helps submodules like "autoCmd" to include their base definitions and examples in the docs + # Though there might be a better, less "hacky" solution than this. + ${name} = recursiveUpdate opts { + isOption = true; + type.getSubOptions = _: _: { }; # Used to exclude suboptions from the submodule definition itself + }; + } + ) false + else + wrapModule (path ++ [ name ]) opts true; in - if subOpts != {} - then - wrapModule - (path ++ [name]) - ( - (recurse (path ++ [name]) subOpts) - // { - # This is necessary to include the submodule option's definition in the docs (description, type, etc.) - # For instance, this helps submodules like "autoCmd" to include their base definitions and examples in the docs - # Though there might be a better, less "hacky" solution than this. - ${name} = recursiveUpdate opts { - isOption = true; - type.getSubOptions = _: _: {}; # Used to exclude suboptions from the submodule definition itself - }; - } - ) - false - else wrapModule (path ++ [name]) opts true; + mapAttrs g mods; in - mapAttrs g mods; - in - foldlAttrs - ( - acc: name: opts: let - group = - if !opts.hasComponents - then "Neovim Options" - else "none"; + foldlAttrs ( + acc: name: opts: + let + group = if !opts.hasComponents then "Neovim Options" else "none"; last = - acc.${group} - or { + acc.${group} or { index = { - options = {}; + options = { }; path = removeWhitespace "${group}"; moduleDoc = null; }; - components = {}; + components = { }; isGroup = true; hasComponents = false; }; isOpt = !opts.hasComponents && (isOption opts.index.options); in - acc - // { - ${group} = recursiveUpdate last { - index.options = optionalAttrs isOpt { - ${name} = opts.index.options; - }; + acc + // { + ${group} = recursiveUpdate last { + index.options = optionalAttrs isOpt { ${name} = opts.index.options; }; - components = optionalAttrs (!isOpt) { - ${name} = recursiveUpdate opts { - index.path = - removeWhitespace - ( - concatStringsSep "/" - ( - (optional (group != "none") group) ++ [opts.index.path] - ) - ); - hasComponents = true; - }; + components = optionalAttrs (!isOpt) { + ${name} = recursiveUpdate opts { + index.path = removeWhitespace ( + concatStringsSep "/" ((optional (group != "none") group) ++ [ opts.index.path ]) + ); + hasComponents = true; }; - - hasComponents = last.components != {}; }; - } - ) - {} - (recurse [] modules); - mapModulesToString = f: modules: let - recurse = mods: let - g = name: opts: - if (opts ? "isGroup") - then - if name != "none" - then (f name opts) + ("\n" + recurse opts.components) - else recurse opts.components - else if opts.hasComponents - then (f name opts) + ("\n" + recurse opts.components) - else f name opts; + hasComponents = last.components != { }; + }; + } + ) { } (recurse [ ] modules); + + mapModulesToString = + f: modules: + let + recurse = + mods: + let + g = + name: opts: + if (opts ? "isGroup") then + if name != "none" then (f name opts) + ("\n" + recurse opts.components) else recurse opts.components + else if opts.hasComponents then + (f name opts) + ("\n" + recurse opts.components) + else + f name opts; + in + concatStringsSep "\n" (mapAttrsToList g mods); in - concatStringsSep "\n" (mapAttrsToList g mods); - in recurse modules; docs = rec { modules = processModulesRec (removeUnwanted options.options); - commands = - mapModulesToString - ( - name: opts: let - isBranch = - if (hasSuffix "index" opts.index.path) - then true - else opts.hasComponents; - path = - if isBranch - then "${opts.index.path}/index.md" - else "${opts.index.path}.md"; - in - (optionalString isBranch - "mkdir -p ${opts.index.path}\n") - + ( - if opts.index.moduleDoc == null - then "cp ${mkMDDoc opts.index.options} ${path}" - else - # Including moduleDoc's text directly will result in bash interpreting special chars, - # write it to the nix store and `cat` the file instead. - '' - { - cat ${pkgs.writeText "module-doc" opts.index.moduleDoc} - cat ${mkMDDoc opts.index.options} - } > ${path} - '' - ) + commands = mapModulesToString ( + name: opts: + let + isBranch = if (hasSuffix "index" opts.index.path) then true else opts.hasComponents; + path = if isBranch then "${opts.index.path}/index.md" else "${opts.index.path}.md"; + in + (optionalString isBranch "mkdir -p ${opts.index.path}\n") + + ( + if opts.index.moduleDoc == null then + "cp ${mkMDDoc opts.index.options} ${path}" + else + # Including moduleDoc's text directly will result in bash interpreting special chars, + # write it to the nix store and `cat` the file instead. + '' + { + cat ${pkgs.writeText "module-doc" opts.index.moduleDoc} + cat ${mkMDDoc opts.index.options} + } > ${path} + '' ) - modules; + ) modules; }; mdbook = { - nixvimOptions = - mapModulesToString - ( - name: opts: let - isBranch = - if name == "index" - then true - else opts.hasComponents && opts.index.options != {}; + nixvimOptions = mapModulesToString ( + name: opts: + let + isBranch = if name == "index" then true else opts.hasComponents && opts.index.options != { }; - path = - if isBranch - then "${opts.index.path}/index.md" - else if !opts.hasComponents - then "${opts.index.path}.md" - else ""; + path = + if isBranch then + "${opts.index.path}/index.md" + else if !opts.hasComponents then + "${opts.index.path}.md" + else + ""; - indentLevel = with builtins; length (filter isString (split "/" opts.index.path)) - 1; + indentLevel = with builtins; length (filter isString (split "/" opts.index.path)) - 1; - padding = concatStrings (builtins.genList (_: "\t") indentLevel); - in "${padding}- [${name}](${path})" - ) - docs.modules; + padding = concatStrings (builtins.genList (_: "\t") indentLevel); + in + "${padding}- [${name}](${path})" + ) docs.modules; }; prepareMD = '' @@ -262,19 +250,23 @@ with lib; let --replace-fail "@HM_OPTIONS@" "$(cat ${mkMDDoc hmOptions})" ''; in - pkgs.stdenv.mkDerivation { - name = "nixvim-docs"; +pkgs.stdenv.mkDerivation { + name = "nixvim-docs"; - phases = ["buildPhase"]; + phases = [ "buildPhase" ]; - buildInputs = [pkgs.mdbook]; - inputs = sourceFilesBySuffices ./. [".md" ".toml" ".js"]; + buildInputs = [ pkgs.mdbook ]; + inputs = sourceFilesBySuffices ./. [ + ".md" + ".toml" + ".js" + ]; - buildPhase = '' - dest=$out/share/doc - mkdir -p $dest - ${prepareMD} - mdbook build - cp -r ./book/* $dest - ''; - } + buildPhase = '' + dest=$out/share/doc + mkdir -p $dest + ${prepareMD} + mdbook build + cp -r ./book/* $dest + ''; +} diff --git a/example.nix b/example.nix index 94039be05e..de83620e54 100644 --- a/example.nix +++ b/example.nix @@ -1,4 +1,5 @@ -{pkgs, ...}: { +{ pkgs, ... }: +{ programs.nixvim = { # This just enables NixVim. # If all you have is this, then there will be little visible difference @@ -60,8 +61,16 @@ # This is one of lightline's example configurations active = { left = [ - ["mode" "paste"] - ["readonly" "filename" "modified" "helloworld"] + [ + "mode" + "paste" + ] + [ + "readonly" + "filename" + "modified" + "helloworld" + ] ]; }; @@ -80,6 +89,6 @@ # What about plugins not available as a module? # Use extraPlugins: - extraPlugins = with pkgs.vimPlugins; [vim-toml]; + extraPlugins = with pkgs.vimPlugins; [ vim-toml ]; }; } diff --git a/flake-modules/default.nix b/flake-modules/default.nix index 78ef1d56a9..788aec62a2 100644 --- a/flake-modules/default.nix +++ b/flake-modules/default.nix @@ -1,4 +1,5 @@ -{inputs, ...}: { +{ inputs, ... }: +{ imports = [ ./dev ./helpers.nix @@ -12,16 +13,14 @@ ./wrappers.nix ]; - perSystem = { - pkgs, - system, - ... - }: { - _module.args = { - pkgsUnfree = import inputs.nixpkgs { - inherit system; - config.allowUnfree = true; + perSystem = + { pkgs, system, ... }: + { + _module.args = { + pkgsUnfree = import inputs.nixpkgs { + inherit system; + config.allowUnfree = true; + }; }; }; - }; } diff --git a/flake-modules/dev/default.nix b/flake-modules/dev/default.nix index 760021dfee..bfb5b64787 100644 --- a/flake-modules/dev/default.nix +++ b/flake-modules/dev/default.nix @@ -1,22 +1,27 @@ -{ inputs, ... }: { - imports = [ inputs.pre-commit-hooks.flakeModule ./devshell.nix ]; +{ inputs, ... }: +{ + imports = [ + inputs.pre-commit-hooks.flakeModule + ./devshell.nix + ]; - perSystem = { pkgs, ... }: { - formatter = pkgs.nixfmt-rfc-style; + perSystem = + { pkgs, ... }: + { + formatter = pkgs.nixfmt-rfc-style; - pre-commit = { - settings.hooks = { - nixfmt = { - package = pkgs.nixfmt-rfc-style; - enable = true; + pre-commit = { + settings.hooks = { + nixfmt = { + package = pkgs.nixfmt-rfc-style; + enable = true; + }; + statix = { + enable = true; + excludes = [ "plugins/lsp/language-servers/rust-analyzer-config.nix" ]; + }; + typos.enable = true; }; - statix = { - enable = true; - excludes = - [ "plugins/lsp/language-servers/rust-analyzer-config.nix" ]; - }; - typos.enable = true; }; }; - }; } diff --git a/flake-modules/dev/devshell.nix b/flake-modules/dev/devshell.nix index 1f13316768..67d987fcba 100644 --- a/flake-modules/dev/devshell.nix +++ b/flake-modules/dev/devshell.nix @@ -1,66 +1,69 @@ -{inputs, ...}: { - imports = [ - inputs.devshell.flakeModule - ]; +{ inputs, ... }: +{ + imports = [ inputs.devshell.flakeModule ]; - perSystem = { - pkgs, - config, - system, - ... - }: { - devshells.default = { - devshell.startup.pre-commit.text = config.pre-commit.installationScript; + perSystem = + { + pkgs, + config, + system, + ... + }: + { + devshells.default = { + devshell.startup.pre-commit.text = config.pre-commit.installationScript; - commands = let - # Thanks to this, the user can choose to use `nix-output-monitor` (`nom`) instead of plain `nix` - nix = "$([ '$\{NIXVIM_NOM:-0}' = '1' ] && echo ${pkgs.lib.getExe pkgs.nom} || echo nix)"; - in [ - { - name = "checks"; - help = "Run all nixvim checks"; - command = "nix flake check"; - } - { - name = "tests"; - help = "Run nixvim tests"; - command = '' - echo "=> Running nixvim tests for the '${system}' architecture..." + commands = + let + # Thanks to this, the user can choose to use `nix-output-monitor` (`nom`) instead of plain `nix` + nix = "$([ '$\{NIXVIM_NOM:-0}' = '1' ] && echo ${pkgs.lib.getExe pkgs.nom} || echo nix)"; + in + [ + { + name = "checks"; + help = "Run all nixvim checks"; + command = "nix flake check"; + } + { + name = "tests"; + help = "Run nixvim tests"; + command = '' + echo "=> Running nixvim tests for the '${system}' architecture..." - ${nix} build .#checks.${system}.tests "$@" - ''; - } - { - name = "format"; - help = "Format the entire codebase"; - command = "nix fmt"; - } - { - name = "docs"; - help = "Build nixvim documentation"; - command = '' - echo "=> Building nixvim documentation..." + ${nix} build .#checks.${system}.tests "$@" + ''; + } + { + name = "format"; + help = "Format the entire codebase"; + command = "nix fmt"; + } + { + name = "docs"; + help = "Build nixvim documentation"; + command = '' + echo "=> Building nixvim documentation..." - ${nix} build .#docs "$@" - ''; - } - { - name = "serve-docs"; - help = "Build and serve documentation locally"; - command = '' - echo -e "=> Building nixvim documentation...\n" + ${nix} build .#docs "$@" + ''; + } + { + name = "serve-docs"; + help = "Build and serve documentation locally"; + command = '' + echo -e "=> Building nixvim documentation...\n" - doc_derivation=$(${nix} build .#docs --no-link --print-out-paths) + doc_derivation=$(${nix} build .#docs --no-link --print-out-paths) - echo -e "\n=> Documentation successfully built ('$doc_derivation')" + echo -e "\n=> Documentation successfully built ('$doc_derivation')" - port=8000 - echo -e "\n=> Now open your browser and navigate to 'localhost:$port'\n" + port=8000 + echo -e "\n=> Now open your browser and navigate to 'localhost:$port'\n" - ${pkgs.lib.getExe pkgs.python3} -m http.server -d "$doc_derivation"/share/doc - ''; - } - ]; + ${pkgs.lib.getExe pkgs.python3} -m http.server -d "$doc_derivation"/share/doc + ''; + } + ]; + }; }; - }; } diff --git a/flake-modules/helpers.nix b/flake-modules/helpers.nix index f49afa645a..69c70ff103 100644 --- a/flake-modules/helpers.nix +++ b/flake-modules/helpers.nix @@ -1,15 +1,15 @@ -{getHelpers, ...}: { - _module.args.getHelpers = pkgs: _nixvimTests: +{ getHelpers, ... }: +{ + _module.args.getHelpers = + pkgs: _nixvimTests: import ../lib/helpers.nix { inherit pkgs _nixvimTests; inherit (pkgs) lib; }; - perSystem = { - pkgs, - config, - ... - }: { - _module.args.helpers = getHelpers pkgs false; - }; + perSystem = + { pkgs, config, ... }: + { + _module.args.helpers = getHelpers pkgs false; + }; } diff --git a/flake-modules/legacy-packages.nix b/flake-modules/legacy-packages.nix index dca631c3b3..749a2f13c7 100644 --- a/flake-modules/legacy-packages.nix +++ b/flake-modules/legacy-packages.nix @@ -1,18 +1,21 @@ { - perSystem = { - pkgs, - config, - makeNixvimWithModule, - ... - }: { - legacyPackages = rec { - inherit makeNixvimWithModule; - makeNixvim = configuration: - makeNixvimWithModule { - module = { - config = configuration; + perSystem = + { + pkgs, + config, + makeNixvimWithModule, + ... + }: + { + legacyPackages = rec { + inherit makeNixvimWithModule; + makeNixvim = + configuration: + makeNixvimWithModule { + module = { + config = configuration; + }; }; - }; + }; }; - }; } diff --git a/flake-modules/lib.nix b/flake-modules/lib.nix index 6bf8592500..4deda79795 100644 --- a/flake-modules/lib.nix +++ b/flake-modules/lib.nix @@ -3,18 +3,15 @@ lib, withSystem, ... -}: { +}: +{ flake.lib = lib.genAttrs config.systems ( lib.flip withSystem ( - { - pkgs, - config, - ... - }: - import ../lib { - inherit pkgs lib; - inherit (config.legacyPackages) makeNixvim makeNixvimWithModule; - } + { pkgs, config, ... }: + import ../lib { + inherit pkgs lib; + inherit (config.legacyPackages) makeNixvim makeNixvimWithModule; + } ) ); } diff --git a/flake-modules/modules.nix b/flake-modules/modules.nix index 77465b1405..81eb473f69 100644 --- a/flake-modules/modules.nix +++ b/flake-modules/modules.nix @@ -1,37 +1,41 @@ -{modules, ...}: { +{ modules, ... }: +{ _module.args = { - modules = pkgs: let - nixpkgsMaintainersList = pkgs.path + "/nixos/modules/misc/meta.nix"; + modules = + pkgs: + let + nixpkgsMaintainersList = pkgs.path + "/nixos/modules/misc/meta.nix"; - nixvimExtraArgsModule = rec { - _file = ./flake.nix; - key = _file; - config = { - _module.args = { - pkgs = pkgs.lib.mkForce pkgs; - inherit (pkgs) lib; + nixvimExtraArgsModule = rec { + _file = ./flake.nix; + key = _file; + config = { + _module.args = { + pkgs = pkgs.lib.mkForce pkgs; + inherit (pkgs) lib; + }; }; }; - }; - in [ - ../modules - nixpkgsMaintainersList - nixvimExtraArgsModule - ({lib, ...}: - with lib; { - # Attribute may contain the following fields: - # - name: Name of the module - # - kind: Either colorschemes or plugins - # - description: A short description of the plugin - # - url: Url for the plugin - # - # [kind name] will identify the plugin - # - # We need to use an attrs instead of a submodule to handle the merge. - options.meta.nixvimInfo = mkOption { - type = - (types.nullOr types.attrs) - // { + in + [ + ../modules + nixpkgsMaintainersList + nixvimExtraArgsModule + ( + { lib, ... }: + with lib; + { + # Attribute may contain the following fields: + # - name: Name of the module + # - kind: Either colorschemes or plugins + # - description: A short description of the plugin + # - url: Url for the plugin + # + # [kind name] will identify the plugin + # + # We need to use an attrs instead of a submodule to handle the merge. + options.meta.nixvimInfo = mkOption { + type = (types.nullOr types.attrs) // { # This will create an attrset of the form: # { # "path"."to"."plugin" = { "" = ; }; @@ -43,37 +47,41 @@ # description = null or ""; # url = null or ""; # } - merge = _: defs: - lib.foldl' (acc: def: - lib.recursiveUpdate acc { - "${def.value.kind}"."${def.value.name}" = { - inherit (def.value) url description; - inherit (def) file; - }; - }) { - plugins = {}; - colorschemes = {}; - } - defs; + merge = + _: defs: + lib.foldl' + ( + acc: def: + lib.recursiveUpdate acc { + "${def.value.kind}"."${def.value.name}" = { + inherit (def.value) url description; + inherit (def) file; + }; + } + ) + { + plugins = { }; + colorschemes = { }; + } + defs; }; - internal = true; - default = null; - description = '' - Nixvim related information on the module - ''; - }; - }) - ]; + internal = true; + default = null; + description = '' + Nixvim related information on the module + ''; + }; + } + ) + ]; }; - perSystem = { - pkgs, - config, - ... - }: { - _module.args = { - modules = modules pkgs; - rawModules = modules; + perSystem = + { pkgs, config, ... }: + { + _module.args = { + modules = modules pkgs; + rawModules = modules; + }; }; - }; } diff --git a/flake-modules/overlays.nix b/flake-modules/overlays.nix index 17ca24696b..0ad88df0c7 100644 --- a/flake-modules/overlays.nix +++ b/flake-modules/overlays.nix @@ -1,21 +1,18 @@ -{inputs, ...}: { - imports = [ - inputs.flake-parts.flakeModules.easyOverlay - ]; - perSystem = { - config, - pkgs, - final, - ... - }: { - overlayAttrs = { - nixvim = { - inherit - (config.legacyPackages) - makeNixvim - makeNixvimWithModule - ; +{ inputs, ... }: +{ + imports = [ inputs.flake-parts.flakeModules.easyOverlay ]; + perSystem = + { + config, + pkgs, + final, + ... + }: + { + overlayAttrs = { + nixvim = { + inherit (config.legacyPackages) makeNixvim makeNixvimWithModule; + }; }; }; - }; } diff --git a/flake-modules/packages.nix b/flake-modules/packages.nix index 1319b003ea..bff7b46baa 100644 --- a/flake-modules/packages.nix +++ b/flake-modules/packages.nix @@ -1,16 +1,16 @@ { - perSystem = { - pkgs, - config, - rawModules, - helpers, - ... - }: { - packages = import ../docs { - inherit rawModules pkgs helpers; - }; + perSystem = + { + pkgs, + config, + rawModules, + helpers, + ... + }: + { + packages = import ../docs { inherit rawModules pkgs helpers; }; - # Test that all packages build fine when running `nix flake check`. - checks = config.packages; - }; + # Test that all packages build fine when running `nix flake check`. + checks = config.packages; + }; } diff --git a/flake-modules/templates.nix b/flake-modules/templates.nix index 1756585d96..c8338d6cb7 100644 --- a/flake-modules/templates.nix +++ b/flake-modules/templates.nix @@ -1,8 +1,5 @@ +{ self, inputs, ... }: { - self, - inputs, - ... -}: { flake.templates = { default = { path = ../templates/simple; @@ -12,49 +9,48 @@ # The following adds the template flake's checks to the main (current) flake's checks. # It ensures that the template's own checks are successful. - perSystem = { - pkgs, - system, - lib, - ... - }: { - checks = let - # Approximates https://github.com/NixOS/nix/blob/7cd08ae379746749506f2e33c3baeb49b58299b8/src/libexpr/flake/call-flake.nix#L46 - # s/flake.outputs/args.outputs/ - callFlake = args @ { - inputs, - outputs, - sourceInfo, - }: let - outputs = args.outputs (inputs // {self = result;}); - result = - outputs - // sourceInfo - // { - inherit inputs outputs sourceInfo; - _type = "flake"; - }; - in - result; + perSystem = + { + pkgs, + system, + lib, + ... + }: + { + checks = + let + # Approximates https://github.com/NixOS/nix/blob/7cd08ae379746749506f2e33c3baeb49b58299b8/src/libexpr/flake/call-flake.nix#L46 + # s/flake.outputs/args.outputs/ + callFlake = + args@{ + inputs, + outputs, + sourceInfo, + }: + let + outputs = args.outputs (inputs // { self = result; }); + result = + outputs + // sourceInfo + // { + inherit inputs outputs sourceInfo; + _type = "flake"; + }; + in + result; - templateFlakeOutputs = callFlake { - inputs = { - inherit (inputs) flake-parts nixpkgs; - nixvim = self; - }; - # Import and read the `outputs` field of the template flake. - inherit (import ../templates/simple/flake.nix) outputs; - sourceInfo = {}; - }; + templateFlakeOutputs = callFlake { + inputs = { + inherit (inputs) flake-parts nixpkgs; + nixvim = self; + }; + # Import and read the `outputs` field of the template flake. + inherit (import ../templates/simple/flake.nix) outputs; + sourceInfo = { }; + }; - templateChecks = templateFlakeOutputs.checks.${system}; - in - lib.concatMapAttrs - ( - checkName: check: { - "template-${checkName}" = check; - } - ) - templateChecks; - }; + templateChecks = templateFlakeOutputs.checks.${system}; + in + lib.concatMapAttrs (checkName: check: { "template-${checkName}" = check; }) templateChecks; + }; } diff --git a/flake-modules/tests.nix b/flake-modules/tests.nix index ab255f0814..2d6a9f5d53 100644 --- a/flake-modules/tests.nix +++ b/flake-modules/tests.nix @@ -1,49 +1,51 @@ -{self, ...}: { - perSystem = { - pkgs, - config, - system, - helpers, - makeNixvimWithModuleUnfree, - makeNixvimWithModule, - ... - }: { - checks = { - tests = import ../tests { - inherit pkgs helpers makeNixvimWithModule; - inherit (pkgs) lib; - makeNixvim = configuration: - makeNixvimWithModuleUnfree { - module = { - config = configuration; +{ self, ... }: +{ + perSystem = + { + pkgs, + config, + system, + helpers, + makeNixvimWithModuleUnfree, + makeNixvimWithModule, + ... + }: + { + checks = { + tests = import ../tests { + inherit pkgs helpers makeNixvimWithModule; + inherit (pkgs) lib; + makeNixvim = + configuration: + makeNixvimWithModuleUnfree { + module = { + config = configuration; + }; }; - }; - }; + }; - extra-args-tests = import ../tests/extra-args.nix { - inherit pkgs; - inherit makeNixvimWithModule; - }; + extra-args-tests = import ../tests/extra-args.nix { + inherit pkgs; + inherit makeNixvimWithModule; + }; - extend = import ../tests/extend.nix { - inherit pkgs makeNixvimWithModule; - }; + extend = import ../tests/extend.nix { inherit pkgs makeNixvimWithModule; }; - enable-except-in-tests = import ../tests/enable-except-in-tests.nix { - inherit pkgs makeNixvimWithModule; - inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule; - }; + enable-except-in-tests = import ../tests/enable-except-in-tests.nix { + inherit pkgs makeNixvimWithModule; + inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule; + }; - no-flake = import ../tests/no-flake.nix { - inherit system; - inherit (self.lib.${system}.check) mkTestDerivationFromNvim; - nixvim = "${self}"; - }; + no-flake = import ../tests/no-flake.nix { + inherit system; + inherit (self.lib.${system}.check) mkTestDerivationFromNvim; + nixvim = "${self}"; + }; - lib-tests = import ../tests/lib-tests.nix { - inherit pkgs helpers; - inherit (pkgs) lib; + lib-tests = import ../tests/lib-tests.nix { + inherit pkgs helpers; + inherit (pkgs) lib; + }; }; }; - }; } diff --git a/flake-modules/wrappers.nix b/flake-modules/wrappers.nix index 5802a7ccc2..c4ca27d168 100644 --- a/flake-modules/wrappers.nix +++ b/flake-modules/wrappers.nix @@ -4,64 +4,56 @@ getHelpers, self, ... -}: let +}: +let wrapperArgs = { inherit modules; inherit self; inherit getHelpers; }; -in { - perSystem = { - system, - pkgs, - pkgsUnfree, - config, - ... - }: { - _module.args = { - makeNixvimWithModule = - import ../wrappers/standalone.nix - pkgs - wrapperArgs; - - makeNixvimWithModuleUnfree = - import ../wrappers/standalone.nix - pkgsUnfree - wrapperArgs; - }; +in +{ + perSystem = + { + system, + pkgs, + pkgsUnfree, + config, + ... + }: + { + _module.args = { + makeNixvimWithModule = import ../wrappers/standalone.nix pkgs wrapperArgs; - checks = - { - home-manager-module = - (import ../tests/modules/hm.nix { - inherit pkgs; - inherit (inputs) home-manager; - nixvim = self; - }) - .activationPackage; - } - // pkgs.lib.optionalAttrs (!pkgs.stdenv.isDarwin) { - nixos-module = - (import ../tests/modules/nixos.nix { - inherit system; - inherit (inputs) nixpkgs; - nixvim = self; - }) - .config - .system - .build - .toplevel; - } - // pkgs.lib.optionalAttrs pkgs.stdenv.isDarwin { - darwin-module = - (import ../tests/modules/darwin.nix { - inherit system; - inherit (inputs) nix-darwin; - nixvim = self; - }) - .system; + makeNixvimWithModuleUnfree = import ../wrappers/standalone.nix pkgsUnfree wrapperArgs; }; - }; + + checks = + { + home-manager-module = + (import ../tests/modules/hm.nix { + inherit pkgs; + inherit (inputs) home-manager; + nixvim = self; + }).activationPackage; + } + // pkgs.lib.optionalAttrs (!pkgs.stdenv.isDarwin) { + nixos-module = + (import ../tests/modules/nixos.nix { + inherit system; + inherit (inputs) nixpkgs; + nixvim = self; + }).config.system.build.toplevel; + } + // pkgs.lib.optionalAttrs pkgs.stdenv.isDarwin { + darwin-module = + (import ../tests/modules/darwin.nix { + inherit system; + inherit (inputs) nix-darwin; + nixvim = self; + }).system; + }; + }; flake = { nixosModules.nixvim = import ../wrappers/nixos.nix wrapperArgs; diff --git a/flake.nix b/flake.nix index 98a8dc2f04..a37338ffcf 100644 --- a/flake.nix +++ b/flake.nix @@ -30,8 +30,9 @@ }; }; - outputs = inputs: - inputs.flake-parts.lib.mkFlake {inherit inputs;} { + outputs = + inputs: + inputs.flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" "aarch64-linux" @@ -39,6 +40,6 @@ "aarch64-darwin" ]; - imports = [./flake-modules]; + imports = [ ./flake-modules ]; }; } diff --git a/lib/autocmd-helpers.nix b/lib/autocmd-helpers.nix index 9879180284..d93bec42bd 100644 --- a/lib/autocmd-helpers.nix +++ b/lib/autocmd-helpers.nix @@ -3,7 +3,8 @@ nixvimOptions, nixvimTypes, }: -with lib; rec { +with lib; +rec { autoGroupOption = types.submodule { options = { clear = mkOption { @@ -75,7 +76,5 @@ with lib; rec { nested = nixvimOptions.defaultNullOpts.mkBool false "Run nested autocommands."; }; - autoCmdOption = types.submodule { - options = autoCmdOptions; - }; + autoCmdOption = types.submodule { options = autoCmdOptions; }; } diff --git a/lib/builders.nix b/lib/builders.nix index c19d1bd9c4..dcd2713d1d 100644 --- a/lib/builders.nix +++ b/lib/builders.nix @@ -1,23 +1,22 @@ +{ lib, pkgs }: { - lib, - pkgs, -}: { /* - Write a lua file to the nix store, formatted using stylua. + Write a lua file to the nix store, formatted using stylua. - # Type + # Type - ``` - writeLua :: String -> String -> Derivation - ``` + ``` + writeLua :: String -> String -> Derivation + ``` - # Arguments + # Arguments - - [name] The name of the derivation - - [text] The content of the lua file + - [name] The name of the derivation + - [text] The content of the lua file */ - writeLua = name: text: - pkgs.runCommand name {inherit text;} '' + writeLua = + name: text: + pkgs.runCommand name { inherit text; } '' echo -n "$text" > "$out" ${lib.getExe pkgs.stylua} \ diff --git a/lib/default.nix b/lib/default.nix index 07ac594af5..df86273027 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -5,10 +5,9 @@ pkgs, _nixvimTests ? false, ... -} @ args: { +}@args: +{ # Add all exported modules here - check = import ../tests/test-derivation.nix { - inherit makeNixvim makeNixvimWithModule pkgs; - }; - helpers = import ./helpers.nix (args // {inherit _nixvimTests;}); + check = import ../tests/test-derivation.nix { inherit makeNixvim makeNixvimWithModule pkgs; }; + helpers = import ./helpers.nix (args // { inherit _nixvimTests; }); } diff --git a/lib/helpers.nix b/lib/helpers.nix index 5b8e5f7089..ad5a3db359 100644 --- a/lib/helpers.nix +++ b/lib/helpers.nix @@ -3,22 +3,30 @@ pkgs, _nixvimTests, ... -}: let - nixvimBuilders = import ./builders.nix {inherit lib pkgs;}; - nixvimTypes = import ./types.nix {inherit lib nixvimOptions;}; - nixvimUtils = import ./utils.nix {inherit lib _nixvimTests;}; - nixvimOptions = import ./options.nix {inherit lib nixvimTypes nixvimUtils;}; - inherit (import ./to-lua.nix {inherit lib;}) toLuaObject; +}: +let + nixvimBuilders = import ./builders.nix { inherit lib pkgs; }; + nixvimTypes = import ./types.nix { inherit lib nixvimOptions; }; + nixvimUtils = import ./utils.nix { inherit lib _nixvimTests; }; + nixvimOptions = import ./options.nix { inherit lib nixvimTypes nixvimUtils; }; + inherit (import ./to-lua.nix { inherit lib; }) toLuaObject; in - { - maintainers = import ./maintainers.nix; - keymaps = import ./keymap-helpers.nix {inherit lib nixvimOptions nixvimTypes;}; - autocmd = import ./autocmd-helpers.nix {inherit lib nixvimOptions nixvimTypes;}; - neovim-plugin = import ./neovim-plugin.nix {inherit lib nixvimOptions nixvimUtils toLuaObject;}; - vim-plugin = import ./vim-plugin.nix {inherit lib nixvimOptions nixvimUtils;}; - inherit nixvimTypes; - inherit toLuaObject; - } - // nixvimUtils - // nixvimOptions - // nixvimBuilders +{ + maintainers = import ./maintainers.nix; + keymaps = import ./keymap-helpers.nix { inherit lib nixvimOptions nixvimTypes; }; + autocmd = import ./autocmd-helpers.nix { inherit lib nixvimOptions nixvimTypes; }; + neovim-plugin = import ./neovim-plugin.nix { + inherit + lib + nixvimOptions + nixvimUtils + toLuaObject + ; + }; + vim-plugin = import ./vim-plugin.nix { inherit lib nixvimOptions nixvimUtils; }; + inherit nixvimTypes; + inherit toLuaObject; +} +// nixvimUtils +// nixvimOptions +// nixvimBuilders diff --git a/lib/keymap-helpers.nix b/lib/keymap-helpers.nix index 7de7dc67e8..a7d0451ce8 100644 --- a/lib/keymap-helpers.nix +++ b/lib/keymap-helpers.nix @@ -3,40 +3,25 @@ nixvimOptions, nixvimTypes, }: -with lib; rec { +with lib; +rec { # These are the configuration options that change the behavior of each mapping. mapConfigOptions = { - silent = - nixvimOptions.defaultNullOpts.mkBool false - "Whether this mapping should be silent. Equivalent to adding to a map."; + silent = nixvimOptions.defaultNullOpts.mkBool false "Whether this mapping should be silent. Equivalent to adding to a map."; - nowait = - nixvimOptions.defaultNullOpts.mkBool false - "Whether to wait for extra input on ambiguous mappings. Equivalent to adding to a map."; + nowait = nixvimOptions.defaultNullOpts.mkBool false "Whether to wait for extra input on ambiguous mappings. Equivalent to adding to a map."; - script = - nixvimOptions.defaultNullOpts.mkBool false - "Equivalent to adding