Skip to content

File substitutes - #52

Closed
shlevy wants to merge 24 commits into
NixOS:masterfrom
shlevy:file-substitutes
Closed

shlevy wants to merge 24 commits into
NixOS:masterfrom
shlevy:file-substitutes

Conversation

@shlevy

@shlevy shlevy commented Sep 16, 2012

Copy link
Copy Markdown
Member

This branch (which includes my structured-context work and the better errors when importing from derivations work) adds some new substituter operations (--query haveFile, --query fileInfo, and --read) that should provide enough information to determine if a substitute is available for a derivation that requires importing from another derivation to be realised. Essentially, a substituter can serve up information about some files (type, length, recursive hash, etc., used by coerceToString with copyToStore=true) and the full contents of some regular files (used by prim_import), allowing the import from derivation to be done without the full derivation being realised.

This does not update any real substituters to support these new operations, though tests/file-substituter.sh shows the interface they must follow.

A sketch of how this might be used: I import build.nix from nix's tarball, and the substituter gives back the full nix expression which gets parsed and evaled. build.nix builds individual .c files, so the substituter tells me the recursive hash of those files (but it doesn't need the full contents) so nix can determine the hash of compileC derivations.

There are other operations (e.g. readFile) which might want to use this file substituter mechanism in the import-from-derivation case, but import and coerceToString seemed the most important.

shlevy added 24 commits August 29, 2012 19:37
None of the cases that turned handling off didn't have readOnly set anyway.
…tion in read-only mode, we shouldn't throw an exception just because we're trying to check for substitutable paths
Rather than relying on magic characters and string scanning to extract information out of a string context, a string's context is now a structured data type.

To avoid fragmentation and extra allocations, the context struct and the memory for the strings it points to are all allocated in one call.
…faces in libstore, and use them to see if a file to be imported has a substitute
@shlevy shlevy mentioned this pull request Dec 4, 2012
@shlevy

shlevy commented Jul 2, 2013

Copy link
Copy Markdown
Member Author

Giving up on this getting merged

@shlevy shlevy closed this Jul 2, 2013
@copumpkin

Copy link
Copy Markdown
Member

Pity to see this closed, but has your thinking re: the problem changed at all since this solution? I find myself wanting the behavior. Would you still implement it this way?

@shlevy

shlevy commented Jan 9, 2015

Copy link
Copy Markdown
Member Author

@copumpkin I think as long as we care about read-only evaluation, this kind of approach is the only way to handle "building at eval time". Since doing this work, though, I've come to appreciate the "evaluate at build time" (i.e. recursive nix) approach to the kinds of problems this would solve, especially given the "derivation replacement" model I came up with in my implementation.

@shlevy

shlevy commented Dec 29, 2015

Copy link
Copy Markdown
Member Author

@copumpkin This is actually the latest version of the work in #31, sorry

@copumpkin

Copy link
Copy Markdown
Member

Ah oaky, thanks! @edolstra can we reopen this one then? 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need .outPath here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure really.

@copumpkin

Copy link
Copy Markdown
Member

@shlevy when you have some time, do you think you could:

  1. Reopen this PR so I can try to rebase it (I think I have write access to your repo already) and get GitHub to show the activity to other potential interested parties
  2. Give a very quick high-level overview of what the key differences are from an "end-user" (i.e., nixpkgs developer) standpoint? I see some tests in there but it isn't jumping out at me which of those tests would fail before the change. I know what pain points I've encountered with import-from-derivation but I'm not too clear on which of my pain points this will help with 😄

Thanks for all the great work! I hope to be able to revive it and get more of it merged

@shlevy shlevy reopened this Jan 16, 2016
@shlevy

shlevy commented Jan 16, 2016

Copy link
Copy Markdown
Member Author

Reopened so @copumpkin can take over.

@shlevy

shlevy commented Jan 17, 2016

Copy link
Copy Markdown
Member Author

So there are multiple things happening in this branch. The first half makes nix-env -q lazier and aware of readonly errors, so if it can complete its query without importing from derivation it will and if it can't it will simply skip that drv as if it threw an assert error. The second half adds the concept of a file substituter, which can provide various bits of information that would otherwise require building during evaluation to determine (though no actual file substituter is added, just the protocol).

@shlevy

shlevy commented Aug 9, 2016

Copy link
Copy Markdown
Member Author

@copumpkin Are you planning on reviving this?

@shlevy

shlevy commented Aug 11, 2016

Copy link
Copy Markdown
Member Author

@copumpkin will reopen if so

@shlevy shlevy closed this Aug 11, 2016
meditans pushed a commit to Ericson2314/nix that referenced this pull request Aug 28, 2020
ConnorBaker pushed a commit to ConnorBaker/nix that referenced this pull request Jul 25, 2025
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 22, 2026
Each candidate that has been addressed by a pushed cleanup branch now
carries a **Branch:** line under its **Validation:** paragraph, naming
the vibe-coding/cleanup/* branch on origin that lands the change.

Cross-references:
- vibe-coding/cleanup/libexpr-friend-dup -> NixOS#217 (duplicate-line removal
  only; the broader Counter -> Statistics promotion remains as future
  work)
- vibe-coding/cleanup/libfetchers-curl-stub -> NixOS#52
- vibe-coding/cleanup/libflake-lockfile -> NixOS#48
- vibe-coding/cleanup/libmain-shared -> NixOS#49, NixOS#128
- vibe-coding/cleanup/libstore-dead-decls -> NixOS#54, NixOS#56, NixOS#57, NixOS#60
- vibe-coding/cleanup/libutil-misc -> NixOS#58, NixOS#130
- vibe-coding/cleanup/nix-run -> NixOS#127, NixOS#142

Two non-branch outcomes folded in:
- NixOS#50 (nix_value_incref forwarders): resolved-by-design after re-reading
  the C-API header. The forwarders are the migration *target*, not the
  debt; the typed nix_value_decref form supersedes the @deprecated
  generic nix_gc_decref. No code change.
- NixOS#148 (windowSize() un-leak): reclassified INVALID after an adversarial
  review pass identified a static-destruction-order hazard. The leak is
  load-bearing because ~ProgressBar runs from static destruction and
  the in-flight update-thread draw() iteration calls
  getWindowSize() -> windowSize().lock(). A function-local static would
  be destroyed before that lock; UAM. Same hazard class as
  getInterruptCallbacks; documented in the expanded comment landed on
  vibe-coding/cleanup/libutil-misc.

NixOS#56 (BaseSetting<SandboxMode>::trait header move) and NixOS#57 (COMMA_ macro
hygiene) gained extra detail: NixOS#56 is also a real ODR fix (different TUs
saw different definitions of the explicit specialisation), and NixOS#57's
implementing PR also caught a third leaking macro
(LENGTH_PREFIXED_PROTO_HELPER_X) that the original framing missed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
The static StringSet was declared but never defined or referenced.

Refs candidate NixOS#52.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
…xes + libmain code-review parity

Final cleanup pass after the bidirectional traceability audit.

Audit findings: 0 phantom Branch lines, 0 wrong-fix commits, 7
orphan commits (bodies missing Refs candidate lines), 4 stale
Branch line texts where Pass-B amends shifted the implementation
without updating the catalog.

All 7 orphans fixed via per-shard rebase amends adding the missing
candidate references (libexpr 18-commit rebase for NixOS#217,
libfetchers 2-commit rebase for NixOS#52, libflake 2-commit rebase for
NixOS#48, libmain single-commit amend for NixOS#49+NixOS#128, libstore 23-commit
rebase for NixOS#54+NixOS#56+NixOS#57+NixOS#60, libutil 7-commit rebase for NixOS#58+NixOS#130
and the NixOS#148-tied catalog-cleanup commit, nix-cli 12-commit rebase
for NixOS#127+NixOS#142). All 4 stale Branch lines re-synced.

`/code-review` skill brought to parity on libmain — three-agent
fan-out reported clean across reuse / quality / efficiency.

Final tip SHAs after the orphan-fix rebases: libexpr 9d33402cc,
libfetchers dc5dc00, libflake fd75c93, libmain f9da474,
libstore e7e885bc3, libutil 18a82b524, nix-cli ef32368.

All seven branches still Local-only past their pushed tips; push
policy is explicit-only.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
roberth added a commit to roberth/nix that referenced this pull request Aug 9, 2026
`assertCacheStats <hits> <misses> <fallbacks> -- <cmd>` runs cmd with
NIX_CACHE_STATS_FILE pointing at a tmp sidecar, then locks in the
exact counter tuple from NixOS#52. Prints a diff-style message on mismatch.

cb-stats-sanity.sh exercises the helper against a trivial cached
attrset: cold record asserts 1 miss / 0 hits / 0 fallbacks, warm
replay asserts 6 hits / 0 misses / 0 fallbacks. Counts calibrated
from observed behaviour — any future regression that changes the
trie shape silently will trip this.

Assisted-by: Claude Code (Claude Opus 4.6-4.7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Feature request or proposal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants