diff --git a/docs/default.nix b/docs/default.nix index c94b6f9b..0e7958a6 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -1,42 +1,13 @@ { - pkgs ? import { config.allowUnfree = true; }, + system, + nixpkgs, nuschtosSearch, }: let - # Extend nixpkg's lib, so that we can handle recursive leaf types such as `either` - lib = pkgs.lib.extend ( - final: prev: { - types = prev.types // { - either = - t1: t2: - (prev.types.either t1 t2) - // { - getSubOptions = prefix: (t1.getSubOptions prefix) // (t2.getSubOptions prefix); - }; - }; - } - ); - - # Extended nixpkgs instance, with patches to nixos-render-docs - pkgsDoc = pkgs.extend ( - final: prev: { - inherit lib; - - nixos-render-docs = prev.nixos-render-docs.overrideAttrs (old: { - patches = old.patches or [ ] ++ [ - # Adds support for GFM-style admonitions in rendered commonmark - ./0001-Output-GFM-admonition.patch - # TODO:add support for _parsing_ GFM admonitions too - # https://github.com/nix-community/nixvim/issues/2217 - ]; - }); - } - ); - - helpers = import ../lib/helpers.nix { - inherit lib; - pkgs = pkgsDoc; - }; + # We overlay a few tweaks into pkgs, for use in the docs + pkgs = import ./pkgs.nix { inherit system nixpkgs; }; + inherit (pkgs) lib; + helpers = import ../lib/helpers.nix { inherit lib pkgs; }; nixvimPath = toString ./..; @@ -74,7 +45,7 @@ let .options [ "_module" ]; options-json = - (pkgsDoc.nixosOptionsDoc { + (pkgs.nixosOptionsDoc { inherit (evaledModules) options; inherit transformOptions; warningsAreErrors = false; @@ -84,9 +55,9 @@ in { inherit options-json; - man-docs = pkgsDoc.callPackage ./man { inherit options-json; }; + man-docs = pkgs.callPackage ./man { inherit options-json; }; } -// lib.optionalAttrs (!pkgsDoc.stdenv.isDarwin) ( +// lib.optionalAttrs (!pkgs.stdenv.isDarwin) ( let mkSearch = baseHref: @@ -102,7 +73,7 @@ in # Do not check if documentation builds fine on darwin as it fails: # > sandbox-exec: pattern serialization length 69298 exceeds maximum (65535) - docs = pkgsDoc.callPackage ./mdbook { + docs = pkgs.callPackage ./mdbook { inherit evaledModules hmOptions transformOptions; # TODO: Find how to handle stable when 24.11 lands search = mkSearch "/nixvim/search/"; diff --git a/docs/pkgs.nix b/docs/pkgs.nix new file mode 100644 index 00000000..e644dc9e --- /dev/null +++ b/docs/pkgs.nix @@ -0,0 +1,44 @@ +{ + system, + nixpkgs, +}: +let + # FIXME: + # Building the docs evaluates many package-option defaults, some of which are unfree. + # This usually happens when we include the package option value in another option's default without + # using a literalExpression defaultText. + config = { + allowUnfree = true; + }; + + # Extend nixpkg's lib, so that we can handle recursive leaf types such as `either` + libOverlay = final: prev: { + types = prev.types // { + either = + t1: t2: + prev.types.either t1 t2 + // { + getSubOptions = prefix: t1.getSubOptions prefix // t2.getSubOptions prefix; + }; + }; + }; + + # Extended nixpkgs instance, with patches to nixos-render-docs + overlay = final: prev: { + lib = prev.lib.extend libOverlay; + + nixos-render-docs = prev.nixos-render-docs.overrideAttrs (old: { + patches = old.patches or [ ] ++ [ + # Adds support for GFM-style admonitions in rendered commonmark + ./0001-Output-GFM-admonition.patch + # TODO:add support for _parsing_ GFM admonitions too + # https://github.com/nix-community/nixvim/issues/2217 + ]; + }); + }; + +in +import nixpkgs { + inherit config system; + overlays = [ overlay ]; +} diff --git a/flake-modules/packages.nix b/flake-modules/packages.nix index 873efc71..76e5ca3e 100644 --- a/flake-modules/packages.nix +++ b/flake-modules/packages.nix @@ -1,15 +1,16 @@ +{ inputs, ... }: { perSystem = { - pkgsUnfree, config, inputs', + system, ... }: { packages = import ../docs { - # Building the docs evaluates each plugin's default package, some of which are unfree - pkgs = pkgsUnfree; + inherit system; + inherit (inputs) nixpkgs; inherit (inputs') nuschtosSearch; };