Skip to content

Commit

Permalink
Move docs generation out of main flake
Browse files Browse the repository at this point in the history
I do this to prevent every user to have to pull the nuschtos input
  • Loading branch information
arnarg committed Oct 28, 2024
1 parent 4b14062 commit 8384b84
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 184 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: cachix/install-nix-action@v23
- uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
extra-experimental-features = nix-command flakes
- uses: DeterminateSystems/magic-nix-cache-action@v7
- uses: DeterminateSystems/magic-nix-cache-action@v8

- run: |
nix build .#docs.html --out-link public
nix-build ./docs -A html --out-link public
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
Expand Down
141 changes: 43 additions & 98 deletions docs/default.nix
Original file line number Diff line number Diff line change
@@ -1,99 +1,44 @@
{
pkgs,
lib ? pkgs.lib,
kubenix,
mkSearch,
}: let
optionsMd = import ./build-options-doc.nix {inherit pkgs lib;};

buildSearch = import ./build-options-search.nix {
inherit pkgs lib kubenix mkSearch;
};

libraryMd = import ./build-library-doc.nix {inherit pkgs lib;};

docsHtml = pkgs.stdenv.mkDerivation {
inherit optionsMd;

passAsFile = ["optionsMd"];

name = "nixidy-html-docs";

src = lib.cleanSource ./..;

buildInputs = with pkgs.python3.pkgs; [mkdocs-material mkdocs-material-extensions];

phases = ["unpackPhase" "patchPhase" "buildPhase"];

patchPhase = ''
cat $optionsMdPath > docs/options.md
cp ${libraryMd}/lib.md docs/library.md
cp ${../README.md} docs/index.md
cat <<EOF > mkdocs.yml
site_name: nixidy
site_url: https://arnarg.github.io/nixidy/
site_dir: $out
repo_url: https://github.com/arnarg/nixidy/
exclude_docs: |
*.nix
theme:
name: material
palette:
- media: "(prefers-color-scheme: light)"
scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/brightness-4
name: Switch to light mode
features:
- navigation.footer
- content.tabs.link
markdown_extensions:
- def_list
- toc:
permalink: "#"
toc_depth: 3
- admonition
- pymdownx.highlight
- pymdownx.inlinehilite
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
nav:
- Home: index.md
- 'User Guide':
- 'Getting Started': user_guide/getting_started.md
- 'Using Helm Charts': user_guide/helm_charts.md
- 'Typed Resource Options': user_guide/typed_resources.md
- 'GitHub Actions': user_guide/github_actions.md
- 'Transformers': user_guide/transformers.md
- 'Using nixhelm': user_guide/using_nixhelm.md
- Reference:
- 'Library Functions': library.md
- 'Configuration Options': options.md
EOF
'';

buildPhase = ''
mkdir -p $out
python -m mkdocs build
cp -r ${buildSearch "/nixidy/options/search/"} $out/options/search
'';
let
# Get some sources from npins.
sources = import ./npins;
pkgs = import sources.nixpkgs {};

# Some inputs from the root flake need
# be available to the docs generation.
# To make sure they are the same version
# as is used by the flake I read the flake.lock
# and fetch them below.
flakeLock = builtins.fromJSON (builtins.readFile ../flake.lock);
kubenix = let
lock = flakeLock.nodes.kubenix.locked;
in
pkgs.fetchFromGitHub {
inherit (lock) owner repo rev;
hash = lock.narHash;
};
kubelib = let
lock = flakeLock.nodes.nix-kube-generators.locked;
in
pkgs.fetchFromGitHub {
inherit (lock) owner repo rev;
hash = lock.narHash;
};

# Setup nuschtos without using a flake.
nuschtos = sources.search;
ixx = sources.ixx;
ixxPkgs = {
ixx = pkgs.callPackage "${ixx}/ixx/derivation.nix" {};
fixx = pkgs.callPackage "${ixx}/fixx/derivation.nix" {};
libixx = pkgs.callPackage "${ixx}/libixx/derivation.nix" {};
};
in {
html = docsHtml;
search = buildSearch "/";
}
nuscht-search = pkgs.callPackage "${nuschtos}/nix/frontend.nix" {};
mkSearch = (pkgs.callPackage "${nuschtos}/nix/wrapper.nix" {inherit nuscht-search ixxPkgs;}).mkSearch;
in
# Build docs!
import ./docs.nix {
inherit pkgs kubenix mkSearch;
lib = import ../lib {
inherit pkgs kubelib;
};
}
100 changes: 100 additions & 0 deletions docs/docs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
pkgs,
lib ? pkgs.lib,
kubenix,
mkSearch,
}: let
optionsMd = import ./build-options-doc.nix {inherit pkgs lib;};

buildSearch = import ./build-options-search.nix {
inherit pkgs lib kubenix mkSearch;
};

libraryMd = import ./build-library-doc.nix {inherit pkgs lib;};

docsHtml = pkgs.stdenv.mkDerivation {
inherit optionsMd;

passAsFile = ["optionsMd"];

name = "nixidy-html-docs";

src = lib.cleanSource ./..;

buildInputs = with pkgs.python3.pkgs; [mkdocs-material mkdocs-material-extensions];

phases = ["unpackPhase" "patchPhase" "buildPhase"];

patchPhase = ''
cat $optionsMdPath > docs/options.md
cp ${libraryMd}/lib.md docs/library.md
cp ${../README.md} docs/index.md
cat <<EOF > mkdocs.yml
site_name: nixidy
site_url: https://arnarg.github.io/nixidy/
site_dir: $out
repo_url: https://github.com/arnarg/nixidy/
exclude_docs: |
*.nix
/npins/
theme:
name: material
palette:
- media: "(prefers-color-scheme: light)"
scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/brightness-4
name: Switch to light mode
features:
- navigation.footer
- content.tabs.link
markdown_extensions:
- def_list
- toc:
permalink: "#"
toc_depth: 3
- admonition
- pymdownx.highlight
- pymdownx.inlinehilite
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
nav:
- Home: index.md
- 'User Guide':
- 'Getting Started': user_guide/getting_started.md
- 'Using Helm Charts': user_guide/helm_charts.md
- 'Typed Resource Options': user_guide/typed_resources.md
- 'GitHub Actions': user_guide/github_actions.md
- 'Transformers': user_guide/transformers.md
- 'Using nixhelm': user_guide/using_nixhelm.md
- Reference:
- 'Library Functions': library.md
- 'Configuration Options': options.md
EOF
'';

buildPhase = ''
mkdir -p $out
python -m mkdocs build
cp -r ${buildSearch "/nixidy/options/search/"} $out/options/search
'';
};
in {
html = docsHtml;
search = buildSearch "/";
}
80 changes: 80 additions & 0 deletions docs/npins/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Generated by npins. Do not modify; will be overwritten regularly
let
data = builtins.fromJSON (builtins.readFile ./sources.json);
version = data.version;

mkSource =
spec:
assert spec ? type;
let
path =
if spec.type == "Git" then
mkGitSource spec
else if spec.type == "GitRelease" then
mkGitSource spec
else if spec.type == "PyPi" then
mkPyPiSource spec
else if spec.type == "Channel" then
mkChannelSource spec
else
builtins.throw "Unknown source type ${spec.type}";
in
spec // { outPath = path; };

mkGitSource =
{
repository,
revision,
url ? null,
hash,
branch ? null,
...
}:
assert repository ? type;
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
# In the latter case, there we will always be an url to the tarball
if url != null then
(builtins.fetchTarball {
inherit url;
sha256 = hash; # FIXME: check nix version & use SRI hashes
})
else
assert repository.type == "Git";
let
urlToName =
url: rev:
let
matched = builtins.match "^.*/([^/]*)(\\.git)?$" repository.url;

short = builtins.substring 0 7 rev;

appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
in
"${if matched == null then "source" else builtins.head matched}${appendShort}";
name = urlToName repository.url revision;
in
builtins.fetchGit {
url = repository.url;
rev = revision;
inherit name;
# hash = hash;
};

mkPyPiSource =
{ url, hash, ... }:
builtins.fetchurl {
inherit url;
sha256 = hash;
};

mkChannelSource =
{ url, hash, ... }:
builtins.fetchTarball {
inherit url;
sha256 = hash;
};
in
if version == 3 then
builtins.mapAttrs (_: mkSource) data.pins
else
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
38 changes: 38 additions & 0 deletions docs/npins/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"pins": {
"ixx": {
"type": "GitRelease",
"repository": {
"type": "GitHub",
"owner": "nuschtos",
"repo": "ixx"
},
"pre_releases": false,
"version_upper_bound": null,
"release_prefix": null,
"version": "v0.0.5",
"revision": "65c207c92befec93e22086da9456d3906a4e999c",
"url": "https://api.github.com/repos/nuschtos/ixx/tarball/v0.0.5",
"hash": "1sraly2kpi6jj0c4lcjpp6fj42rg1j5bv0hi225sndz6yhp8kk31"
},
"nixpkgs": {
"type": "Channel",
"name": "nixpkgs-unstable",
"url": "https://releases.nixos.org/nixpkgs/nixpkgs-24.11pre697431.86e78d3d2084/nixexprs.tar.xz",
"hash": "0wbmh3jc25xan6x6nndfidgkfigip49zqp0rivi6lsdv18sx9mvx"
},
"search": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "nuschtos",
"repo": "search"
},
"branch": "main",
"revision": "e373332c1f8237fc1263901745b0fe747228c8ba",
"url": "https://github.com/nuschtos/search/archive/e373332c1f8237fc1263901745b0fe747228c8ba.tar.gz",
"hash": "02vqpp8k3aisnv34301lrcb0129kgnklpy6xf2bb94p1bpv9bg0d"
}
},
"version": 3
}
Loading

0 comments on commit 8384b84

Please sign in to comment.