Skip to content

nix-instantiate: Respect NIX_NO_READONLY_DEFAULT - #203

Closed
shlevy wants to merge 3 commits into
NixOS:masterfrom
shlevy:eval-only-no-readonly
Closed

shlevy wants to merge 3 commits into
NixOS:masterfrom
shlevy:eval-only-no-readonly

Conversation

@shlevy

@shlevy shlevy commented Feb 4, 2014

Copy link
Copy Markdown
Member

This allows running nix-instantiate --eval-only without performing the
evaluation in readonly mode, letting features like import from
derivation and automatic substitution of builtins.storePath paths work.

This is an env var for two reasons:

  • For projects that make regular use of these non-readonly features, it
    will be simpler to just set the env var once
  • Tools that wrap nix-instantiate (like nixops) can set the env var
    without breaking backwards compatability.

@edolstra

edolstra commented Feb 4, 2014

Copy link
Copy Markdown
Member

Having an environment variable for this, while everything else is a command line flag or an option, seems very hackish to me...

Also, if a script explicitly is asking for read/write mode, it shouldn't be silently ignored if the Nix version is too old.

This allows running nix-instantiate --eval-only without performing the
evaluation in readonly mode, letting features like import from
derivation and automatic substitution of builtins.storePath paths work.

Signed-off-by: Shea Levy <[email protected]>
@shlevy

shlevy commented Feb 4, 2014

Copy link
Copy Markdown
Member Author

@edolstra OK, force-pushed it to use a flag instead.

@edolstra

edolstra commented Feb 4, 2014

Copy link
Copy Markdown
Member

Slight remark: this means that the order is important, right? I.e. "--no-readonly-mode --eval-only" won't work.

Also, "--no-readonly-mode" seems a bit of a double negation: readonly-mode turns off write access, and no-readonly-mode turns it back on. Maybe --read-write-mode or something like would be better.

@shlevy

shlevy commented Feb 4, 2014

Copy link
Copy Markdown
Member Author

@edolstra OK, renamed to --read-write-mode and ordering is no longer important.

@shlevy

shlevy commented Feb 7, 2014

Copy link
Copy Markdown
Member Author

@edolstra Any problems now?

@edolstra

edolstra commented Feb 7, 2014

Copy link
Copy Markdown
Member

Applied, thanks.

@edolstra edolstra closed this Feb 7, 2014
@shlevy
shlevy deleted the eval-only-no-readonly branch February 7, 2014 18:47
zolodev pushed a commit to zolodev/nix that referenced this pull request Jan 1, 2024
zolodev pushed a commit to zolodev/nix that referenced this pull request Jan 1, 2024
P-E-Meunier pushed a commit to P-E-Meunier/nix that referenced this pull request Feb 26, 2025
Filter platform-specific dependencies according to *local* info
usertam pushed a commit to usertam/nix that referenced this pull request Sep 25, 2025
…721c61ad-d7dd-4e3b-b398-baf8388dccfb

Release v3.11.2
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 24, 2026
Landed 18 commits across 6 shards covering 20 candidates:
- libstore +8 (NixOS#1+NixOS#3, NixOS#7, NixOS#11, NixOS#55, NixOS#59, NixOS#101, NixOS#153, NixOS#185)
- libexpr +3 covering 4 (NixOS#192, NixOS#202+NixOS#203 folded, NixOS#204)
- libutil +4 (NixOS#97, NixOS#124, NixOS#167, NixOS#224)
- libfetchers +1 (NixOS#53)
- libflake +1 (NixOS#133, rename only — deviation documented)
- libmain +1 (NixOS#223; NixOS#222 already on branch)

Skipped: NixOS#76 (libc++ in dev shell lacks <generator>) and several
RED-bucket items.

4-pass review chain: Pass A (parallel adversarial) caught 2
BLOCKERS — libstore NixOS#153 over-broad rename corrupted the
external-builders JSON wire-key, and libutil NixOS#97 dropped the
inline allowed-name list breaking eval-fail-hashString-2.err.exp.
Both fixed via amend; parseEnumOrThrow extended to render
'a', 'b', or 'c' with Oxford comma + suggestions. Pass B
(/code-review) found no blockers; substantive amends include
libexpr's callFunction hot-path now reading a ctor-frozen
profilerHooks snapshot, libstore's tryUpperFallLower returning
std::pair<R, bool>, libutil completing three migration gaps.
Pass C found one real clang-tidy error (parse-enum.hh missing
configuration.hh include); other shards only show the 5 known
pre-existing master errors. Pass D nix build -L . green on all
six shards.

New catalog candidates surfaced by review: NixOS#225 (libfetchers
getUserRegistry/getSystemRegistry/getGlobalRegistry share NixOS#53's
first-call-wins shape on the hot path), NixOS#226 (showCompressionAlgo
vs printHashAlgo enum-rendering inconsistency).

Catalog total: 226 + 44.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 24, 2026
…xOS#203)

Drops the entire cached-eval-failure path — `AttrDb::setFailed`,
`AttrType::Failed`, the `failed_t` variant alternative, the
`CachedEvalError` exception class, and the
`try { run } catch (CachedEvalError & e) { e.force() }` outer block in
`nix::main`.

The cached `Failed` rows weren't load-bearing. On a cache hit,
`CachedEvalError::force()` re-ran `forceValue()` on the parent cursor,
producing the same diagnostic the original eval would have produced.
The on-disk row was just a marker that let the second-read path skip
the success-path serialize-to-cache code. Without it, every read
re-evaluates failed attributes — same diagnostic, same path. ~80 lines
of `failed_t`/`CachedEvalError` machinery gone; ~5 lines of type-dispatch
saved on the second-read path were the only thing the marker bought.

While here, fix NixOS#203's read/write asymmetry by wrapping
`AttrDb::getAttr` in `doSQLite` so the read path matches every writer.
Generalises `doSQLite` to deduce its return type from the lambda
(`AttrId` for setters, `std::optional<...>` for the reader); on
`SQLiteError` it returns the value-initialised default (`0` /
`std::nullopt`) and sets the `failed` flag. A read-side `SQLiteError`
no longer escapes to the caller.

Bump the on-disk cache version `eval-cache-v6` -> `eval-cache-v7` so
existing caches with `Failed` rows are not consulted by the new code:
`getAttr`'s switch arm for `AttrType::Failed` is gone, and the
`default:` arm throws `Error("unexpected type in evaluation cache")`
which `doSQLite` does not catch (it only catches `SQLiteError`). The
version bump is the cheapest invalidation mechanism and matches the
v5->v6 precedent in rl-2.31.md.

Public-API note: `eval-cache.hh` ships via `install_headers`; removing
`CachedEvalError`, `failed_t`, and the `Failed` enumerator is a
public-API break for external consumers (Hydra, Lix, plugins). In-tree
the only external touch was `src/nix/main.cc`'s catch arm, removed
here. The numeric value `5` for the former `Failed` enumerator is
documented as reserved in `eval-cache.hh` so future enumerators do not
silently re-use it.

Refs candidates NixOS#202, NixOS#203.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 29, 2026
setPlaceholder, setMissing and setMisc were byte-identical except for the
AttrType enum: each ran the same doSQLite + lock + insertAttribute with
the value column stored as (0, false). Extract a private
setTagged(key, type) and make the three one-line wrappers.

(setFailed, the fourth tag-only setter, was already removed by NixOS#202/NixOS#203
on this branch, so the post-merge scope is exactly these three.)

Refs candidate NixOS#252.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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