2022-06-26 18:55:07 +00:00
|
|
|
{ pkgs
|
2020-06-06 20:08:02 +00:00
|
|
|
|
2022-06-26 18:55:07 +00:00
|
|
|
# Note, this should be "the standard library" + HM extensions.
|
2023-06-28 21:55:00 +00:00
|
|
|
, lib ? import ../modules/lib/stdlib-extended.nix pkgs.lib
|
|
|
|
|
|
|
|
, release, isReleaseBranch }:
|
2018-05-06 20:14:50 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2024-01-31 23:41:56 +00:00
|
|
|
# Recursively replace each derivation in the given attribute set
|
|
|
|
# with the same derivation but with the `outPath` attribute set to
|
|
|
|
# the string `"\${pkgs.attribute.path}"`. This allows the
|
|
|
|
# documentation to refer to derivations through their values without
|
|
|
|
# establishing an actual dependency on the derivation output.
|
|
|
|
#
|
|
|
|
# This is not perfect, but it seems to cover a vast majority of use
|
|
|
|
# cases.
|
|
|
|
#
|
|
|
|
# Caveat: even if the package is reached by a different means, the
|
|
|
|
# path above will be shown and not e.g.
|
|
|
|
# `${config.services.foo.package}`.
|
|
|
|
scrubDerivations = prefixPath: attrs:
|
|
|
|
let
|
|
|
|
scrubDerivation = name: value:
|
|
|
|
let pkgAttrName = prefixPath + "." + name;
|
|
|
|
in if lib.isAttrs value then
|
|
|
|
scrubDerivations pkgAttrName value
|
|
|
|
// lib.optionalAttrs (lib.isDerivation value) {
|
|
|
|
outPath = "\${${pkgAttrName}}";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value;
|
|
|
|
in lib.mapAttrs scrubDerivation attrs;
|
2018-12-18 17:09:56 +00:00
|
|
|
|
2019-08-27 21:40:52 +00:00
|
|
|
# Make sure the used package is scrubbed to avoid actually
|
|
|
|
# instantiating derivations.
|
|
|
|
scrubbedPkgsModule = {
|
2020-02-01 23:39:17 +00:00
|
|
|
imports = [{
|
|
|
|
_module.args = {
|
2024-01-31 23:41:56 +00:00
|
|
|
pkgs = lib.mkForce (scrubDerivations "pkgs" pkgs);
|
2020-02-01 23:39:17 +00:00
|
|
|
pkgs_i686 = lib.mkForce { };
|
|
|
|
};
|
|
|
|
}];
|
2019-08-27 21:40:52 +00:00
|
|
|
};
|
|
|
|
|
2022-06-07 21:23:04 +00:00
|
|
|
dontCheckDefinitions = { _module.check = false; };
|
|
|
|
|
2023-06-28 21:55:00 +00:00
|
|
|
gitHubDeclaration = user: repo: subpath:
|
|
|
|
let urlRef = if isReleaseBranch then "release-${release}" else "master";
|
|
|
|
in {
|
|
|
|
url = "https://github.com/${user}/${repo}/blob/${urlRef}/${subpath}";
|
|
|
|
name = "<${repo}/${subpath}>";
|
|
|
|
};
|
2021-01-18 22:21:32 +00:00
|
|
|
|
2023-06-28 21:55:00 +00:00
|
|
|
hmPath = toString ./..;
|
|
|
|
|
2023-07-19 20:38:38 +00:00
|
|
|
buildOptionsDocs = args@{ modules, includeModuleSystemOptions ? true, ... }:
|
2024-04-26 20:02:25 +00:00
|
|
|
let
|
|
|
|
options = (lib.evalModules {
|
|
|
|
inherit modules;
|
|
|
|
class = "homeManager";
|
|
|
|
}).options;
|
2023-07-19 20:38:38 +00:00
|
|
|
in pkgs.buildPackages.nixosOptionsDoc ({
|
|
|
|
options = if includeModuleSystemOptions then
|
|
|
|
options
|
|
|
|
else
|
|
|
|
builtins.removeAttrs options [ "_module" ];
|
2023-06-28 21:55:00 +00:00
|
|
|
transformOptions = opt:
|
|
|
|
opt // {
|
|
|
|
# Clean up declaration sites to not refer to the Home Manager
|
|
|
|
# source tree.
|
|
|
|
declarations = map (decl:
|
|
|
|
if lib.hasPrefix hmPath (toString decl) then
|
|
|
|
gitHubDeclaration "nix-community" "home-manager"
|
|
|
|
(lib.removePrefix "/" (lib.removePrefix hmPath (toString decl)))
|
|
|
|
else if decl == "lib/modules.nix" then
|
|
|
|
# TODO: handle this in a better way (may require upstream
|
|
|
|
# changes to nixpkgs)
|
|
|
|
gitHubDeclaration "NixOS" "nixpkgs" decl
|
|
|
|
else
|
|
|
|
decl) opt.declarations;
|
|
|
|
};
|
2023-07-19 20:38:38 +00:00
|
|
|
} // builtins.removeAttrs args [ "modules" "includeModuleSystemOptions" ]);
|
2023-06-28 21:55:00 +00:00
|
|
|
|
|
|
|
hmOptionsDocs = buildOptionsDocs {
|
2020-02-01 23:39:17 +00:00
|
|
|
modules = import ../modules/modules.nix {
|
|
|
|
inherit lib pkgs;
|
|
|
|
check = false;
|
|
|
|
} ++ [ scrubbedPkgsModule ];
|
2023-06-28 21:55:00 +00:00
|
|
|
variablelistId = "home-manager-options";
|
2018-12-18 17:09:56 +00:00
|
|
|
};
|
|
|
|
|
2023-06-28 21:55:00 +00:00
|
|
|
nixosOptionsDocs = buildOptionsDocs {
|
2022-06-07 21:23:04 +00:00
|
|
|
modules = [ ../nixos scrubbedPkgsModule dontCheckDefinitions ];
|
2023-07-19 20:38:38 +00:00
|
|
|
includeModuleSystemOptions = false;
|
2023-06-28 21:55:00 +00:00
|
|
|
variablelistId = "nixos-options";
|
|
|
|
optionIdPrefix = "nixos-opt-";
|
2021-01-18 22:21:32 +00:00
|
|
|
};
|
|
|
|
|
2023-06-28 21:55:00 +00:00
|
|
|
nixDarwinOptionsDocs = buildOptionsDocs {
|
2022-06-07 21:23:04 +00:00
|
|
|
modules = [ ../nix-darwin scrubbedPkgsModule dontCheckDefinitions ];
|
2023-07-19 20:38:38 +00:00
|
|
|
includeModuleSystemOptions = false;
|
2023-06-28 21:55:00 +00:00
|
|
|
variablelistId = "nix-darwin-options";
|
|
|
|
optionIdPrefix = "nix-darwin-opt-";
|
2021-01-18 22:21:32 +00:00
|
|
|
};
|
|
|
|
|
2023-11-19 07:20:58 +00:00
|
|
|
release-config = builtins.fromJSON (builtins.readFile ../release.json);
|
|
|
|
revision = "release-${release-config.release}";
|
|
|
|
# Generate the `man home-configuration.nix` package
|
|
|
|
home-configuration-manual =
|
|
|
|
pkgs.runCommand "home-configuration-reference-manpage" {
|
|
|
|
nativeBuildInputs =
|
2023-11-25 14:29:26 +00:00
|
|
|
[ pkgs.buildPackages.installShellFiles pkgs.nixos-render-docs ];
|
2023-11-19 07:20:58 +00:00
|
|
|
allowedReferences = [ "out" ];
|
|
|
|
} ''
|
|
|
|
# Generate manpages.
|
|
|
|
mkdir -p $out/share/man/man5
|
2023-11-20 16:40:49 +00:00
|
|
|
mkdir -p $out/share/man/man1
|
2023-11-25 14:29:26 +00:00
|
|
|
nixos-render-docs -j $NIX_BUILD_CORES options manpage \
|
2023-11-19 07:20:58 +00:00
|
|
|
--revision ${revision} \
|
2023-11-25 14:29:26 +00:00
|
|
|
--header ${./home-configuration-nix-header.5} \
|
|
|
|
--footer ${./home-configuration-nix-footer.5} \
|
2023-11-19 07:20:58 +00:00
|
|
|
${hmOptionsDocs.optionsJSON}/share/doc/nixos/options.json \
|
|
|
|
$out/share/man/man5/home-configuration.nix.5
|
2023-11-20 16:40:49 +00:00
|
|
|
cp ${./home-manager.1} $out/share/man/man1/home-manager.1
|
2023-11-19 07:20:58 +00:00
|
|
|
'';
|
|
|
|
# Generate the HTML manual pages
|
|
|
|
home-manager-manual = pkgs.callPackage ./home-manager-manual.nix {
|
|
|
|
home-manager-options = {
|
|
|
|
home-manager = hmOptionsDocs.optionsJSON;
|
|
|
|
nixos = nixosOptionsDocs.optionsJSON;
|
|
|
|
nix-darwin = nixDarwinOptionsDocs.optionsJSON;
|
|
|
|
};
|
2023-11-25 14:29:26 +00:00
|
|
|
inherit revision;
|
2023-11-19 07:20:58 +00:00
|
|
|
};
|
2023-11-23 14:16:41 +00:00
|
|
|
html = home-manager-manual;
|
|
|
|
htmlOpenTool = pkgs.callPackage ./html-open-tool.nix { } { inherit html; };
|
2020-02-01 23:39:17 +00:00
|
|
|
in {
|
2018-12-18 17:09:56 +00:00
|
|
|
options = {
|
2023-06-28 21:55:00 +00:00
|
|
|
# TODO: Use `hmOptionsDocs.optionsJSON` directly once upstream
|
|
|
|
# `nixosOptionsDoc` is more customizable.
|
|
|
|
json = pkgs.runCommand "options.json" {
|
|
|
|
meta.description = "List of Home Manager options in JSON format";
|
|
|
|
} ''
|
|
|
|
mkdir -p $out/{share/doc,nix-support}
|
|
|
|
cp -a ${hmOptionsDocs.optionsJSON}/share/doc/nixos $out/share/doc/home-manager
|
|
|
|
substitute \
|
|
|
|
${hmOptionsDocs.optionsJSON}/nix-support/hydra-build-products \
|
|
|
|
$out/nix-support/hydra-build-products \
|
|
|
|
--replace \
|
|
|
|
'${hmOptionsDocs.optionsJSON}/share/doc/nixos' \
|
|
|
|
"$out/share/doc/home-manager"
|
|
|
|
'';
|
2018-12-18 17:09:56 +00:00
|
|
|
};
|
2018-05-06 20:14:50 +00:00
|
|
|
|
2023-11-19 07:20:58 +00:00
|
|
|
manPages = home-configuration-manual;
|
2018-05-06 20:14:50 +00:00
|
|
|
|
2023-11-23 14:16:41 +00:00
|
|
|
manual = { inherit html htmlOpenTool; };
|
2021-12-29 09:15:39 +00:00
|
|
|
|
|
|
|
# Unstable, mainly for CI.
|
|
|
|
jsonModuleMaintainers = pkgs.writeText "hm-module-maintainers.json" (let
|
|
|
|
result = lib.evalModules {
|
|
|
|
modules = import ../modules/modules.nix {
|
|
|
|
inherit lib pkgs;
|
|
|
|
check = false;
|
|
|
|
} ++ [ scrubbedPkgsModule ];
|
2024-04-26 20:02:25 +00:00
|
|
|
class = "homeManager";
|
2021-12-29 09:15:39 +00:00
|
|
|
};
|
|
|
|
in builtins.toJSON result.config.meta.maintainers);
|
2018-05-06 20:14:50 +00:00
|
|
|
}
|