Files
clan-core/lib
lassulus d93e58218d Refactor select with new maybe selector
This is a great refactor of the select functionality in the flake class.
This now uses the same parser as the nix code, but runs it in python for
nice stacktraces.

Also we now have a maybe selector which can be used by prepending the
selector with a ?

Tests have been expanded to make sure the code is more stable and easier
to understand
2025-04-25 16:26:45 +10:00
..
2024-07-09 15:23:26 +02:00

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:

#     ↓ 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
.
├── default.nix
├── build-clan
│   ├── default.nix
│   └── test.nix
└── inventory
    ├── default.nix
    ├── services-subfeature
    │   ├── default.nix
    │   └── test.nix
    ├── instances-subfeature # <- We immediately see that this feature is not tested on itself.
    │   └── default.nix
    └── test.nix
# default.nix
{lib, clanLib, ...}:
{
    inventory.resolveTags = import ./resolveTags { inherit lib clanLib; };
}

Testing

For testing we use nix-unit

TODO: define a helper that automatically hooks up tests in flake.legacyPackages and a corresponding buildable checks attribute