Skip to content

Commit

Permalink
chore(modules): factor out option doc generation
Browse files Browse the repository at this point in the history
  • Loading branch information
getchoo committed Apr 29, 2024
1 parent 28d41bc commit b88fd06
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
41 changes: 13 additions & 28 deletions dev/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
};
};

outputs = { self, nixpkgs, ... }@inputs:
outputs = { self, nixpkgs, home-manager }:
let
systems = [
"x86_64-linux"
Expand All @@ -19,43 +19,28 @@
"aarch64-darwin"
];

inherit (nixpkgs) lib;

forAllSystems = fn: lib.genAttrs systems (s: fn nixpkgs.legacyPackages.${s});
forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
in
{
checks = forAllSystems (pkgs: lib.optionalAttrs pkgs.stdenv.isLinux {
module-vm-test = pkgs.nixosTest (import ../test.nix inputs);
checks = forAllSystems ({ lib, pkgs, ... }: lib.optionalAttrs pkgs.stdenv.isLinux {
module-vm-test = pkgs.callPackage ../test.nix { inherit home-manager; };
});

formatter = forAllSystems (pkgs: pkgs.nixpkgs-fmt);

packages = forAllSystems (pkgs:
let
eval = module: lib.evalModules {
modules = [
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
'';
version = self.shortRev or self.dirtyShortRev or "unknown";
mkOptionDoc = args: (pkgs.callPackage ./option-doc.nix { }) args // { inherit version; };
in
{
nixos-doc = mkDoc "nixos" ../modules/nixos;
home-manager-doc = mkDoc "home-manager" ../modules/home-manager;
nixos-doc = mkOptionDoc {
modules = [ ../modules/nixos ];
};

home-manager-doc = mkOptionDoc {
modules = [ ../modules/home-manager ];
};

default = self.packages.${pkgs.system}.home-manager-doc;
});
Expand Down
19 changes: 19 additions & 0 deletions dev/option-doc.nix
Original file line number Diff line number Diff line change
@@ -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
13 changes: 5 additions & 8 deletions test.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
inputs:
{ testers, home-manager }:
let
common = {
catppuccin = {
enable = true;
flavour = "mocha";
};
catppuccin.enable = true;
};

# shorthand enable
# shorthand for enabling a module
enable = { enable = true; };
in
{
testers.runNixOSTest {
name = "module-test";

nodes.machine = { lib, ... }: {
imports = [
inputs.home-manager.nixosModules.default
home-manager.nixosModules.default
./modules/nixos
common
];
Expand Down

0 comments on commit b88fd06

Please sign in to comment.