Module-level assertions #8

Merged
jakehamilton merged 7 commits from austreelis/feat/modules-assertions into main 2025-10-18 22:21:51 +00:00 AGit
Member

I had a usecase for assertions in the module system for my trivial builders PR in tidepool, so I added a pretty basic way of defining them.

It's somewhat quick and dirty I feel like, and given lib has hit 1.0 I precautiously added a warning "module assertions are experimental" if a module defines them, which is traced just before checking them. Assertions are not checked if __module__.check = false.

I also took the liberty to fixup little things in tests and the module lib (the 3 commits with fix:).

Each commit is rather tiny, but I split them up for review. re-formatting is in the last one.

I had a usecase for assertions in the module system for my [trivial builders PR in tidepool](https://git.auxolotl.org/auxolotl/labs/pulls/24), so I added a pretty basic way of defining them. It's somewhat quick and dirty I feel like, and given lib has hit 1.0 I precautiously added a warning "module assertions are experimental" if a module defines them, which is traced just before checking them. Assertions are not checked if `__module__.check = false`. I also took the liberty to fixup little things in tests and the module lib (the 3 commits with `fix:`). Each commit is rather tiny, but I split them up for review. re-formatting is in the last one.
austreelis added 6 commits 2025-10-02 15:46:31 +00:00
austreelis added 1 commit 2025-10-02 15:56:22 +00:00
austreelis added the
Kind/Feature
label 2025-10-04 10:51:49 +00:00
jakehamilton reviewed 2025-10-04 19:59:23 +00:00
@ -706,2 +745,4 @@
else
builtins.throw message
else if config.__module__.check && merged.assertions != [ ] then
builtins.trace "[ WARN]: module assertions are experimental" builtins.foldl' (
Owner

Seems like there is an extra space after the [.

Seems like there is an extra space after the `[`.
austreelis marked this conversation as resolved
Owner

I think this makes a good amount of sense to support as a part of the module system since they are so useful. The code here looks good, just have a few conflicts after the recent PR merges.

I think this makes a good amount of sense to support as a part of the module system since they are so useful. The code here looks good, just have a few conflicts after the recent PR merges.
Author
Member

I'll rebase and fix the space tomorrow :3

I'll rebase and fix the space tomorrow :3
austreelis force-pushed austreelis/feat/modules-assertions from adef04e281 to 6cc1802d06 2025-10-05 16:17:34 +00:00 Compare
Author
Member

Painfully but successfully rebased :) Should be good to merge

Painfully but successfully rebased :) Should be good to merge
Owner

I am strongly in favor of making assertions be a top-level thingy in modules, as this PR does. I recently had to deal with assertion in nixpkgs and was really annoyed that they live in config over there.

I would like to merge this now so we can start relying on it, including in foundation#11, and then I would like to see a followup PR which documents it :)

I am strongly in favor of making `assertions` be a top-level thingy in modules, as this PR does. I recently had to deal with assertion in nixpkgs and was really annoyed that they live in `config` over there. I would like to merge this now so we can start relying on it, including in foundation#11, and then I would like to see a followup PR which documents it :)
Owner

also I can confirm that test.sh passes on my end

also I can confirm that `test.sh` passes on my end
Owner

Excellent, awesome work @austreelis!

Excellent, awesome work @austreelis!
jakehamilton approved these changes 2025-10-18 22:21:44 +00:00
jakehamilton merged commit 0f5182ff0d into main 2025-10-18 22:21:51 +00:00
jakehamilton referenced this pull request from a commit 2025-10-18 22:21:52 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: auxolotl/lib#8
No description provided.