From d9f3169ac33728bfd6a9e06d7bc0ca495761efb5 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sun, 30 Mar 2025 15:28:51 +0200 Subject: [PATCH] docs(lib): init readme with folder and testing conventions --- lib/README.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lib/README.md diff --git a/lib/README.md b/lib/README.md new file mode 100644 index 000000000..fb987247a --- /dev/null +++ b/lib/README.md @@ -0,0 +1,72 @@ +# ClanLib + +This folder is supposed to contain clan specific nix functions. + +Such as: + +- build-clan function +- select +- build-inventory function +- json-schema-converter + +## Structure + +Similar to `nixpkgs/lib` this produces a recursive attribute set in a fixed-point. +Functions within lib can depend on each other to create new abstractions. + +### Conventions + +Note: This is not consistently enforced yet. +If you start a new feature, or refactoring/touching existing ones, please help us to move towards the below illustrated. + +A single feature-set/module may be organized like this: + +```nix +# ↓ The final clanLib +{lib, clanLib, ...}: +# ↓ portion to add to clanLib +{ + inventory.resolveTags = tags: inventory.machines; # implementation + inventory.buildMachines = x: clanLib.inventory.resolveTags x; # implementation +} +``` + +Every bigger feature should live in a subfolder with the feature name. +It should contain two files: + +- `impl.nix` +- `test.nix` +- Everything else may be adopted as needed. + +``` +Example filetree +``` +```sh +. +├── default.nix +├── feature_foo +│ ├── impl.nix +│ └── test.nix +└── feature_bar + ├── impl.nix + ├── complex-subfeature + │ ├── impl.nix + │ └── test.nix + ├── testless-subfeature # <- We immediately see that this feature is not tested on itself. + │ └── impl.nix + └── test.nix +``` + +```nix +# default.nix +{lib, clanLib, ...}: +{ + inventory.resolveTags = import ./resolveTags { inherit lib clanLib; }; +} +``` + +## Testing + +For testing we use [nix-unit](https://github.com/nix-community/nix-unit) + +TODO: define a helper that automatically hooks up `tests` in `flake.legacyPackages` and a corresponding buildable `checks` attribute