feat(gen-docs): write nix code outside script
All checks were successful
Discord / discord commits (push) Has been skipped

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 |
| --------- | ------------- | ------------------------------------------------------------------------------------------------ |

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 |
| --------- | ------------- | ------------------------------------------------------------------------------------------------ |
@ -14,6 +14,6 @@ unique to them.
| `live-image` | USB key | Basic configuration that serves as my custom ISO target |
| `nos` | NVIDIA 3060 with i5-3600 | Custom built NAS and seedbox for Linux ISOs ;) |
| `servivi` | Headless Ryzen 5 3600 | Gaming PC in a previous life, it is now used as a build farm and hosts game servers |
| `thingone` | Lenovo ThinkCentre M900 | Mini PC that makes use of [NixOS-pcsd](https://github.com/matt1432/nixos-pcsd) to form a cluster with its twin |
| `thingtwo` | Lenovo ThinkCentre M900 | Mini PC that makes use of [NixOS-pcsd](https://github.com/matt1432/nixos-pcsd) to form a cluster with its twin |
| `thingone` | Lenovo ThinkCentre M900 | Mini PC that makes use of [NixOS-pcsd](https://github.com/matt1432/nixos-pcsd) to form a cluster with its twin. Files located in `cluster` |
| `thingtwo` | Lenovo ThinkCentre M900 | Mini PC that makes use of [NixOS-pcsd](https://github.com/matt1432/nixos-pcsd) to form a cluster with its twin. Files located in `cluster` |
| `wim` | ThinkPad L13 Yoga Gen 3 (Ryzen 7 PRO 5875U) | 2-1 Lenovo Laptop that I use for university |