diff --git a/doc/manual/default.nix b/doc/manual/default.nix index 2225b515..5a0072a9 100644 --- a/doc/manual/default.nix +++ b/doc/manual/default.nix @@ -13,28 +13,30 @@ with pkgs; let lib = pkgs.lib; + gitHubDeclaration = user: repo: ref: subpath: + # Default to `master` if we don't know what revision the system + # configuration is using (custom nixpkgs, etc.). + let urlRef = if ref != null then ref else "master"; + in { + url = "https://github.com/${user}/${repo}/blob/${urlRef}/${subpath}"; + name = "<${repo}/${subpath}>"; + }; + optionsDoc = buildPackages.nixosOptionsDoc { - inherit options revision; + inherit options; transformOptions = opt: opt // { # Clean up declaration sites to not refer to the nix-darwin source tree. # TODO: handle `extraSources`? (it's not set anywhere) declarations = map (decl: if lib.hasPrefix (toString prefix) (toString decl) then - let - subpath = lib.removePrefix "/" - (lib.removePrefix (toString prefix) (toString decl)); - in { - url = "https://github.com/LnL7/nix-darwin/blob/${revision}/${subpath}"; - name = ""; - } + gitHubDeclaration "LnL7" "nix-darwin" revision + (lib.removePrefix "/" + (lib.removePrefix (toString prefix) (toString decl))) # TODO: handle this in a better way (may require upstream # changes to nixpkgs) else if decl == "lib/modules.nix" then - { - url = "https://github.com/NixOS/nixpkgs/blob/${nixpkgsRevision}/${decl}"; - name = ""; - } + gitHubDeclaration "NixOS" "nixpkgs" nixpkgsRevision decl else decl) opt.declarations; }; @@ -73,7 +75,7 @@ in rec { cp -r ${pkgs.documentation-highlighter} $dst/highlightjs substitute ${./manual.md} manual.md \ - --replace '@DARWIN_VERSION@' "${version}"\ + --replace '@DARWIN_VERSION@' "${version}" \ --replace \ '@DARWIN_OPTIONS_JSON@' \ ${optionsJSON}/share/doc/darwin/options.json @@ -82,7 +84,7 @@ in rec { nixos-render-docs -j $NIX_BUILD_CORES manual html \ --manpage-urls ${pkgs.writeText "manpage-urls.json" "{}"} \ --revision ${lib.escapeShellArg revision} \ - --generator "nixos-render-docs ${pkgs.lib.version}" \ + --generator "nixos-render-docs ${lib.version}" \ --stylesheet style.css \ --stylesheet overrides.css \ --stylesheet highlightjs/mono-blue.css \ diff --git a/modules/documentation/default.nix b/modules/documentation/default.nix index 25165c94..2f3bb9a4 100644 --- a/modules/documentation/default.nix +++ b/modules/documentation/default.nix @@ -1,4 +1,4 @@ -toplevel@{ config, lib, pkgs, baseModules, modules, ... }: +{ config, lib, pkgs, baseModules, modules, ... }: with lib; @@ -25,15 +25,7 @@ let inherit pkgs config; version = config.system.darwinVersion; revision = config.system.darwinRevision; - nixpkgsRevision = - if toplevel.options.system.nixpkgsRevision.isDefined - then config.system.nixpkgsRevision - - # If user does not use flakes and does not add rev to nixpkgs, we don't - # know which revision or even branch they're on. In this case we still want - # to link somewhere, so we hope that master hasn't changed too much. - else "master"; - + inherit (config.system) nixpkgsRevision; options = let scrubbedEval = evalModules { diff --git a/modules/system/version.nix b/modules/system/version.nix index 68019188..0824829c 100644 --- a/modules/system/version.nix +++ b/modules/system/version.nix @@ -67,8 +67,8 @@ in system.darwinRevision = mkOption { internal = true; - type = types.str; - default = "master"; + type = types.nullOr types.str; + default = null; description = lib.mdDoc "The darwin git revision from which this configuration was built."; }; @@ -92,7 +92,8 @@ in system.nixpkgsRevision = mkOption { internal = true; - type = types.str; + type = types.nullOr types.str; + default = null; description = lib.mdDoc "The nixpkgs git revision from which this configuration was built."; }; };