Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enforce boundaries by simulating pure eval #7

Merged
merged 2 commits into from
Aug 4, 2024
Merged

Conversation

nrdxp
Copy link
Contributor

@nrdxp nrdxp commented Aug 4, 2024

With this, we have essentially achieved NixOS/nix#6530 in pure nix. In fact, we are a bit "more pure" since we don't allow arbitrary imports (instead all code must be a module member somewhere) and we don't allow referencing arbitrary paths (modules can only access the (non-nix) files in their own directory through "${mod}"`. We also disable the builtin fetchers to encourage users to declare their dependencies statically in the manifest, and also because those fetchers block evaluation (and therefore builds).

The only remaining "impurity" in this sense would be the path passed to the composer function, but this impurity is actually a good thing, since it doesn't eagerly copy everything to the nix store like flakes, but instead only makes pure (/nix/store) copies of files when they are actually accessed.

If the path doesn't exist on the file-system we will immediately fail anyway, so it's "impurity" is irrelevant. With these added restrictions, there will be no way for the user to escape the module system, so that means that we basically have a totally pure nix evaluation without the high cost of having to copy the entire repo into the /nix/store eagerly.

With this, we have essentially achieved NixOS/nix#6530 in pure nix.

The only remaining "impurity" in this sense would be the path passed
to the composer function, but this is actually a good thing, since
it doesn't eagerly copy everything to the nix store like flakes, but
instead only makes pure copies of files when they are actually accessed.

If the path doesn't exist on the file-system we will immediately fail
anyway, so it's "impurity" is irrelevant. There will be no way for
the user to escape the module system with these new enforcements, so
that means that we basically have a totally pure nix evaluation without
the high cost of having to copy the entire repo into the /nix/store
eagerly.
While we don't want to encourage it, it would be helpful to ease
adoption if users could call this module function from inside their
flake.nix. The only thing preventing that was the path referencing
becoming a pure /nix/store path reference implicitly (via the flake)
and so failing because of the string context.

Fix this by simply removing the string context. This isn't actually
unsafe since if the absolute path literal refers to a store path and is
ever coerced back to a string, nix will readd the context automatically.
@nrdxp nrdxp merged commit 46bace4 into master Aug 4, 2024
2 checks passed
std/path/strToPath.nix Show resolved Hide resolved
@nrdxp nrdxp deleted the lazy-pure-eval branch August 5, 2024 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants