chore(modules): factor out option doc generation (#152)

* chore(modules): factor out option doc generation

* ci: only validate sources on pushes to main
This commit is contained in:
seth 2024-04-29 20:21:14 +00:00 committed by GitHub
parent 2983ec9796
commit 5b5648c10e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 40 additions and 44 deletions

View file

@ -14,9 +14,6 @@ jobs:
name: Check formatting name: Check formatting
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -34,9 +31,6 @@ jobs:
name: Test Modules name: Test Modules
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -48,4 +42,4 @@ jobs:
- name: Run VM - name: Run VM
run: | run: |
nix build -L --show-trace ./dev#checks.x86_64-linux.module-vm-test nix build --print-build-logs --show-trace ./dev#checks.x86_64-linux.module-vm-test

View file

@ -36,7 +36,7 @@ jobs:
- name: Build & update docs - name: Build & update docs
run: | run: |
for module in "nixos" "home-manager"; do for module in "nixos" "home-manager"; do
nix build -L --show-trace ./dev#"$module"-doc nix build --print-build-logs --show-trace ./dev#"$module"-doc
cat result > docs/"$module"-options.md cat result > docs/"$module"-options.md
rm result rm result
done done

View file

@ -7,6 +7,7 @@ on:
paths: paths:
- '_sources/**' - '_sources/**'
- 'nvfetcher.toml' - 'nvfetcher.toml'
branches: [main]
pull_request: pull_request:
paths: paths:
- '_sources/**' - '_sources/**'

View file

@ -10,7 +10,7 @@
}; };
}; };
outputs = { self, nixpkgs, ... }@inputs: outputs = { self, nixpkgs, home-manager }:
let let
systems = [ systems = [
"x86_64-linux" "x86_64-linux"
@ -19,43 +19,28 @@
"aarch64-darwin" "aarch64-darwin"
]; ];
inherit (nixpkgs) lib; forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
forAllSystems = fn: lib.genAttrs systems (s: fn nixpkgs.legacyPackages.${s});
in in
{ {
checks = forAllSystems (pkgs: lib.optionalAttrs pkgs.stdenv.isLinux { checks = forAllSystems ({ lib, pkgs, ... }: lib.optionalAttrs pkgs.stdenv.isLinux {
module-vm-test = pkgs.nixosTest (import ../test.nix inputs); module-vm-test = pkgs.callPackage ../test.nix { inherit home-manager; };
}); });
formatter = forAllSystems (pkgs: pkgs.nixpkgs-fmt); formatter = forAllSystems (pkgs: pkgs.nixpkgs-fmt);
packages = forAllSystems (pkgs: packages = forAllSystems (pkgs:
let let
eval = module: lib.evalModules { version = self.shortRev or self.dirtyShortRev or "unknown";
modules = [ mkOptionDoc = args: (pkgs.callPackage ./option-doc.nix { }) args // { inherit version; };
module
{
_module.check = false;
}
];
};
mkDoc = name: module:
let
doc = pkgs.nixosOptionsDoc {
options = lib.filterAttrs (n: _: n != "_module") (eval module).options;
documentType = "none";
revision = builtins.substring 0 8 self.rev or "dirty";
};
in
pkgs.runCommand "${name}-module-doc.md" { } ''
cat ${doc.optionsCommonMark} > $out
'';
in in
{ {
nixos-doc = mkDoc "nixos" ../modules/nixos; nixos-doc = mkOptionDoc {
home-manager-doc = mkDoc "home-manager" ../modules/home-manager; modules = [ ../modules/nixos ];
};
home-manager-doc = mkOptionDoc {
modules = [ ../modules/home-manager ];
};
default = self.packages.${pkgs.system}.home-manager-doc; default = self.packages.${pkgs.system}.home-manager-doc;
}); });

19
dev/option-doc.nix Normal file
View file

@ -0,0 +1,19 @@
{ lib
, nixosOptionsDoc
,
}: { version
, modules
,
}:
let
eval = lib.evalModules {
modules = modules ++ [{ _module.check = false; }];
};
doc = nixosOptionsDoc {
options = lib.filterAttrs (n: _: n != "_module") eval.options;
documentType = "none";
revision = version;
};
in
doc.optionsCommonMark

View file

@ -1,21 +1,18 @@
inputs: { testers, home-manager }:
let let
common = { common = {
catppuccin = { catppuccin.enable = true;
enable = true;
flavour = "mocha";
};
}; };
# shorthand enable # shorthand for enabling a module
enable = { enable = true; }; enable = { enable = true; };
in in
{ testers.runNixOSTest {
name = "module-test"; name = "module-test";
nodes.machine = { lib, ... }: { nodes.machine = { lib, ... }: {
imports = [ imports = [
inputs.home-manager.nixosModules.default home-manager.nixosModules.default
./modules/nixos ./modules/nixos
common common
]; ];