1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00

version: default Git revision options to null

This allows for more uniform handling in the documentation generator,
and avoids lying about the Git reference being `master` internally.
This commit is contained in:
Emily 2023-07-07 09:02:38 +01:00
parent e25eeff158
commit 72b7e8668c
3 changed files with 22 additions and 27 deletions

View file

@ -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 = "<nix-darwin/${subpath}>";
}
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 = "<nixpkgs/${decl}>";
}
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 \

View file

@ -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 {

View file

@ -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.";
};
};