Skip to content

Commit cc82dd8

Browse files
committed
Add full options search to docs
1 parent f23de31 commit cc82dd8

File tree

5 files changed

+145
-5
lines changed

5 files changed

+145
-5
lines changed

docs/build-options-doc.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
''
8383
# Configuration Options
8484
85+
To see all available resources options, use the [nixidy options search](search) powered by [NüschtOS](https://github.com/NuschtOS/search).
8586
''
8687
]
8788
++ (mapAttrsToList (n: opt:

docs/build-options-search.nix

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
pkgs,
3+
lib,
4+
kubenix,
5+
mkSearch,
6+
}: let
7+
nixidyPath = toString ./..;
8+
kubenixPath = toString kubenix;
9+
10+
# Borrowed from home-manager :)
11+
gitHubDeclaration = user: repo: subpath: {
12+
url = "https://github.com/${user}/${repo}/blob/main/${subpath}";
13+
name = "${repo}/${subpath}";
14+
};
15+
16+
options =
17+
(lib.evalModules {
18+
modules =
19+
import ../modules/modules.nix
20+
++ [
21+
{
22+
nixidy.resourceImports = [
23+
(kubenix + "/modules/generated/v1.30.nix")
24+
../modules/generated/argocd.nix
25+
];
26+
}
27+
];
28+
specialArgs = {
29+
inherit pkgs lib;
30+
};
31+
})
32+
.options;
33+
34+
optionsJSON =
35+
(pkgs.buildPackages.nixosOptionsDoc {
36+
options = removeAttrs options ["_module"];
37+
transformOptions = opt:
38+
opt
39+
// {
40+
declarations =
41+
map (
42+
decl:
43+
if lib.hasPrefix nixidyPath (toString decl)
44+
then gitHubDeclaration "arnarg" "nixidy" (lib.removePrefix "/" (lib.removePrefix nixidyPath (toString decl)))
45+
else if lib.hasPrefix kubenixPath (toString decl)
46+
then gitHubDeclaration "hall" "kubenix" (lib.removePrefix "/" (lib.removePrefix kubenixPath (toString decl)))
47+
else if decl == "lib/modules.nix"
48+
then gitHubDeclaration "NixOS" "nixpkgs" decl
49+
else decl
50+
)
51+
opt.declarations;
52+
}
53+
// (lib.optionalAttrs (opt.description == null) {
54+
description = "";
55+
});
56+
})
57+
.optionsJSON;
58+
in
59+
baseHref:
60+
mkSearch {
61+
inherit baseHref;
62+
optionsJSON = optionsJSON + "/share/doc/nixos/options.json";
63+
urlPrefix = "https://github.com/arnarg/nixidy/tree/main";
64+
title = "nixidy options search";
65+
}

docs/default.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
{
22
pkgs,
33
lib ? pkgs.lib,
4+
kubenix,
5+
mkSearch,
46
}: let
57
optionsMd = import ./build-options-doc.nix {inherit pkgs lib;};
68

9+
buildSearch = import ./build-options-search.nix {
10+
inherit pkgs lib kubenix mkSearch;
11+
};
12+
713
libraryMd = import ./build-library-doc.nix {inherit pkgs lib;};
814

915
docsHtml = pkgs.stdenv.mkDerivation {
@@ -83,8 +89,11 @@
8389
buildPhase = ''
8490
mkdir -p $out
8591
python -m mkdocs build
92+
93+
cp -r ${buildSearch "/nixidy/options/search/"} $out/options/search
8694
'';
8795
};
8896
in {
8997
html = docsHtml;
98+
search = buildSearch "/";
9099
}

flake.lock

Lines changed: 55 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
flake-utils.url = "github:numtide/flake-utils";
77
nix-kube-generators.url = "github:farcaller/nix-kube-generators";
88

9+
nuschtos = {
10+
url = "github:nuschtos/search";
11+
inputs = {
12+
nixpkgs.follows = "nixpkgs";
13+
flake-utils.follows = "flake-utils";
14+
};
15+
};
16+
917
kubenix = {
1018
url = "github:hall/kubenix";
1119
inputs.nixpkgs.follows = "nixpkgs";
@@ -18,6 +26,7 @@
1826
flake-utils,
1927
nix-kube-generators,
2028
kubenix,
29+
nuschtos,
2130
}:
2231
{
2332
lib = rec {
@@ -69,7 +78,12 @@
6978
inherit system;
7079
};
7180
docs = import ./docs {
72-
inherit pkgs;
81+
inherit pkgs kubenix;
82+
mkSearch = nuschtos.packages.${system}.mkSearch;
83+
lib = import ./lib {
84+
inherit pkgs;
85+
kubelib = nix-kube-generators;
86+
};
7387
};
7488
packages = import ./nixidy pkgs;
7589
in {

0 commit comments

Comments
 (0)