summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmily <vcs@emily.moe>2023-07-07 09:02:38 +0100
committerEmily <vcs@emily.moe>2023-07-09 07:26:00 +0100
commit72b7e8668c24950b8300ffe3d135dad1ae72a4f5 (patch)
treed2afd23e4d9a287018302065b56ecfaae998e71c
parente25eeff158ceb415079e38f6e78a470c5664fa2f (diff)
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.
-rw-r--r--doc/manual/default.nix30
-rw-r--r--modules/documentation/default.nix12
-rw-r--r--modules/system/version.nix7
3 files changed, 22 insertions, 27 deletions
diff --git a/doc/manual/default.nix b/doc/manual/default.nix
index 2225b51..5a0072a 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 = "<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 \
diff --git a/modules/documentation/default.nix b/modules/documentation/default.nix
index 25165c9..2f3bb9a 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 6801918..0824829 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.";
};
};