From 8384b84bca9ca3dea5ffbb4bf129feb1127fee33 Mon Sep 17 00:00:00 2001 From: Arnar Gauti Ingason Date: Mon, 28 Oct 2024 10:58:55 +0100 Subject: [PATCH] Move docs generation out of main flake I do this to prevent every user to have to pull the nuschtos input --- .github/workflows/docs.yaml | 6 +- docs/default.nix | 141 +++++++++++------------------------- docs/docs.nix | 100 +++++++++++++++++++++++++ docs/npins/default.nix | 80 ++++++++++++++++++++ docs/npins/sources.json | 38 ++++++++++ flake.lock | 53 +------------- flake.nix | 31 -------- 7 files changed, 265 insertions(+), 184 deletions(-) create mode 100644 docs/docs.nix create mode 100644 docs/npins/default.nix create mode 100644 docs/npins/sources.json diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index ef1d142..f95ceae 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -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 diff --git a/docs/default.nix b/docs/default.nix index 2a15ffe..4e0aec2 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -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 < 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; + }; + } diff --git a/docs/docs.nix b/docs/docs.nix new file mode 100644 index 0000000..3150b55 --- /dev/null +++ b/docs/docs.nix @@ -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 < 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 "/"; +} diff --git a/docs/npins/default.nix b/docs/npins/default.nix new file mode 100644 index 0000000..5e7d086 --- /dev/null +++ b/docs/npins/default.nix @@ -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`" diff --git a/docs/npins/sources.json b/docs/npins/sources.json new file mode 100644 index 0000000..8b68be4 --- /dev/null +++ b/docs/npins/sources.json @@ -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 +} \ No newline at end of file diff --git a/flake.lock b/flake.lock index ce1e0c7..1f6c8a9 100644 --- a/flake.lock +++ b/flake.lock @@ -34,32 +34,6 @@ "type": "github" } }, - "ixx": { - "inputs": { - "flake-utils": [ - "nuschtos", - "flake-utils" - ], - "nixpkgs": [ - "nuschtos", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1729544999, - "narHash": "sha256-YcyJLvTmN6uLEBGCvYoMLwsinblXMkoYkNLEO4WnKus=", - "owner": "NuschtOS", - "repo": "ixx", - "rev": "65c207c92befec93e22086da9456d3906a4e999c", - "type": "github" - }, - "original": { - "owner": "NuschtOS", - "ref": "v0.0.5", - "repo": "ixx", - "type": "github" - } - }, "kubenix": { "inputs": { "flake-compat": "flake-compat", @@ -114,37 +88,12 @@ "type": "github" } }, - "nuschtos": { - "inputs": { - "flake-utils": [ - "flake-utils" - ], - "ixx": "ixx", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1729992468, - "narHash": "sha256-zzGpWx64+/TfZdF5TjzUIV4ESFWCsscapK5Smx9bexk=", - "owner": "nuschtos", - "repo": "search", - "rev": "3c246cc08ffa8e61956e506dd6689bc6e9d5aa20", - "type": "github" - }, - "original": { - "owner": "nuschtos", - "repo": "search", - "type": "github" - } - }, "root": { "inputs": { "flake-utils": "flake-utils", "kubenix": "kubenix", "nix-kube-generators": "nix-kube-generators", - "nixpkgs": "nixpkgs", - "nuschtos": "nuschtos" + "nixpkgs": "nixpkgs" } }, "systems": { diff --git a/flake.nix b/flake.nix index 6ba8ece..939ca33 100644 --- a/flake.nix +++ b/flake.nix @@ -6,14 +6,6 @@ flake-utils.url = "github:numtide/flake-utils"; nix-kube-generators.url = "github:farcaller/nix-kube-generators"; - nuschtos = { - url = "github:nuschtos/search"; - inputs = { - nixpkgs.follows = "nixpkgs"; - flake-utils.follows = "flake-utils"; - }; - }; - kubenix = { url = "github:hall/kubenix"; inputs.nixpkgs.follows = "nixpkgs"; @@ -26,7 +18,6 @@ flake-utils, nix-kube-generators, kubenix, - nuschtos, }: { lib = rec { @@ -77,19 +68,9 @@ pkgs = import nixpkgs { inherit system; }; - docs = import ./docs { - inherit pkgs kubenix; - mkSearch = nuschtos.packages.${system}.mkSearch; - lib = import ./lib { - inherit pkgs; - kubelib = nix-kube-generators; - }; - }; packages = import ./nixidy pkgs; in { packages = { - inherit docs; - default = packages.nixidy; generators = import ./pkgs/generators {inherit pkgs;}; }; @@ -191,18 +172,6 @@ type = "app"; program = self.moduleTests.${system}.reportScript.outPath; }; - - # Run a docs server - docsServe = { - type = "app"; - program = - ( - pkgs.writeShellScript "serve-docs" '' - ${pkgs.python3}/bin/python -m http.server -d ${self.packages.${system}.docs.html} 8080 - '' - ) - .outPath; - }; }; })); }