Consider module-system -> typed-functions #745
Labels
No labels
dependencies
difficulty::high
difficulty::low
difficulty::medium
good first issue
help wanted
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
justin/makes#745
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I was very excited when I originally discovered we can use the NixOS module system for other things beyond configuring NixOS. I found quite simple for being able to configure things with a meere
enable = true;and further customize generated code by just giving values to the optionsI really think it works great and allows us to achieve modularity, declarative programming, easy to read code.
Its problems are more the following:
Instead, I propose to replace the module system with typed functions:
So we would write
makes.nixas follows:this will also make easier to organize code to prepare for future releases of nix, a.k.a. https://github.com/fluidattacks/makes/milestone/2
another option could be not having a makes.nix at all, and configuring everything under /makes, this way users don't have to write the full path, just create a directory structure. Maybe some things like the cache configuration can be implemented in
/makes/config.nixIn general after solving this issue Makes will be a more welcoming place for adoption
what exactly do you mean by "type-functions" seeing as Nix has no builtin type system. Do you mean a system similar to what the Nix module system employs, i.e. runtime type checks?
typed-functions, function with types
Yes, exactly this, I don't know how that would be implemented but nixpkgs.lib.types expose function that perform the validation logic and return a boolean. Maybe we can leverage that or build our own. It should be simple anyway as we use basic types most of the times
That was just a typo, I know what you intended to say 😅
Thanks for clarification.
There is
lib.types.functionTowhich will verify the type that a function evaluates to, but, depending on the function, it can be an expensive check since it actually calls the function to verify this.Yeah, we would not use that then, that one is expensive because it verifies the function return value, we don't need to verify the return value in this case as we are the ones who specify it, just the function arguments are user-supplied data subject to type verification
That might be a tricky problem to solve then 🤔
It might be useful upstream too if we find a solution though
we could improve the error message using
builtins.abortinstead of assert