feat(gen-docs): write nix code outside script

This commit is contained in:
matt1432 2025-01-20 20:37:52 -05:00
parent 5194199d25
commit 20e5b7dac4
5 changed files with 34 additions and 22 deletions

View file

@ -0,0 +1,12 @@
configs: let
inherit (builtins) mapAttrs replaceStrings;
trimNewlines = s: replaceStrings ["\n"] [" "] s;
in {
attrs =
mapAttrs (_: v: {
roleDesc = trimNewlines (v.config.meta.roleDescription or "");
hwDesc = trimNewlines (v.config.meta.hardwareDescription or "");
})
configs;
}

View file

@ -0,0 +1,13 @@
x: let
inherit (builtins) currentSystem mapAttrs removeAttrs replaceStrings;
trimNewlines = s: replaceStrings ["\n"] [" "] s;
packages = removeAttrs x.${currentSystem} ["default"];
in {
attrs =
mapAttrs (_: v: {
desc = trimNewlines (v.meta.description or "");
homepage = v.meta.homepage or "";
})
packages;
}

View file

@ -1,29 +1,16 @@
getMetaFunc=$(cat << EOF
(x: {
attrs = builtins.mapAttrs (_: v: {
desc = builtins.replaceStrings ["\n"] [" "] (v.meta.description or "");
homepage = v.meta.homepage or "";
roleDesc = builtins.replaceStrings ["\n"] [" "] (v.config.meta.roleDescription or "");
hwDesc = builtins.replaceStrings ["\n"] [" "] (v.config.meta.hardwareDescription or "");
}) (builtins.removeAttrs (x.\${builtins.currentSystem} or x) ["default"]);
})
EOF
)
substitute() {
echo '' | pandoc --metadata-file <(
nix eval \
--impure \
--json \
"$FLAKE"#"$1" \
--apply "$getMetaFunc" |
--apply "import \"$FLAKE/apps/gen-docs/$3.nix\"" |
jq -r
) -t markdown --template "$FLAKE/apps/gen-docs/templates/$2.md" -o "$FLAKE/$2/README.md"
}
# TODO: add homeManagerModules, lib, modules, nixFastChecks, overlays, scopedPackages
substitute "appsPackages" "apps"
substitute "nixosConfigurations" "configurations"
substitute "devShells" "devShells"
substitute "packages" "packages"
substitute "appsPackages" "apps" "getPackageMeta"
substitute "nixosConfigurations" "configurations" "getConfigMeta"
substitute "devShells" "devShells" "getPackageMeta"
substitute "packages" "packages" "getPackageMeta"

View file

@ -3,7 +3,7 @@
This directory contains every device's main configuration file, their `hardware-configuration.nix` and some custom modules
unique to them.
## List of my Devices
## List of my devices
| Name | Model / Specs | Description |
| --------- | ------------- | ------------------------------------------------------------------------------------------------ |