Skip to content

prim_toPath: Actually make the string a path - #47

Closed
shlevy wants to merge 1 commit into
NixOS:masterfrom
shlevy:fix-toPath
Closed

shlevy wants to merge 1 commit into
NixOS:masterfrom
shlevy:fix-toPath

Conversation

@shlevy

@shlevy shlevy commented Aug 29, 2012

Copy link
Copy Markdown
Member

builtins.toPath currently doesn't actually turn something into a path. In fact, while it does check if the argument is indeed a path and canonicalize it, it actually returns a string even the argument was a path! This fixes that.

$ cat test.nix

let
  a = builtins.readFile (builtins.unsafeDiscardStringContext (derivation {
    name = "a";
    builder = "/bin/false";
    system = "sys";
    path = /etc/nixos/configuration.nix;
  }).drvPath);

  b = builtins.readFile (builtins.unsafeDiscardStringContext (derivation {
    name = "b";
    builder = "/bin/false";
    system = "sys";
    path = builtins.toPath "/etc/nixos/configuration.nix";
  }).drvPath);

  c = builtins.readFile (builtins.unsafeDiscardStringContext (derivation {
    name = "c";
    builder = "/bin/false";
    system = "sys";
    path = builtins.toPath /etc/nixos/configuration.nix;
  }).drvPath);
in

import "${(import <nixpkgs> {}).runCommand "paths.nix" {} ''
  echo "'''" > $out
  echo "${a}" | sed 's/.*\(path,[^)]*\)).*/\1/' >> $out
  echo "${b}" | sed 's/.*\(path,[^)]*\)).*/\1/' >> $out
  echo "${c}" | sed 's/.*\(path,[^)]*\)).*/\1/' >> $out
  echo "'''" >> $out
''}"

Before:
$ echo -e $(nix-instantiate test.nix >/dev/null 2>&1 || nix-instantiate test.nix --eval-only | sed 's"\g')

path,/nix/store/ms6xqxb4pvxga4m9wlmj5rp8my418dwz-configuration.nix
path,/etc/nixos/configuration.nix
path,/etc/nixos/configuration.nix

After:
$ echo -e $(nix-instantiate test.nix >/dev/null 2>&1 || nix-instantiate test.nix --eval-only | sed 's"\g')

path,/nix/store/ms6xqxb4pvxga4m9wlmj5rp8my418dwz-configuration.nix
path,/nix/store/ms6xqxb4pvxga4m9wlmj5rp8my418dwz-configuration.nix
path,/nix/store/ms6xqxb4pvxga4m9wlmj5rp8my418dwz-configuration.nix

@shlevy

shlevy commented Aug 29, 2012

Copy link
Copy Markdown
Member Author

Wow, that was a really complicated test-case. I can post a much simpler one if the issue isn't clear.

@edolstra

Copy link
Copy Markdown
Member

Did you see the comment just above toPath that suggests it's obsolete?

@shlevy

shlevy commented Aug 29, 2012

Copy link
Copy Markdown
Member Author

There's a question mark :) Eh, probably anything that can be done with toPath can be done without it, but it seems misleading to have it be called that and still there and not working. It's not documented in the nix manual as being obsolete and there's no warning message printed or anything, so most users probably wouldn't know that it is and are almost certainly expecting a different behavior than what actually happens. IMO even if it is obsolete it should be correct as long as it's still there and usable.

@edolstra

Copy link
Copy Markdown
Member

Merged, thanks.

@edolstra edolstra closed this Oct 26, 2012
edolstra pushed a commit that referenced this pull request May 16, 2019
Content hashes
meditans pushed a commit to Ericson2314/nix that referenced this pull request Aug 28, 2020
P-E-Meunier pushed a commit to P-E-Meunier/nix that referenced this pull request Feb 26, 2025
edolstra referenced this pull request in DeterminateSystems/nix-src Mar 5, 2025
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
DerivationGoal::doneSuccess and DerivationBuildingGoal::doneSuccess
shared identical bookkeeping around their `MaintainCount` handle:
reset the handle, bump `worker.doneBuilds` on `Built`, push
`worker.updateProgress()`, then forward to `Goal::doneSuccess`. Their
doneFailure overrides were byte-identical except for the handle name.

Lift the bookkeeping into two protected helpers on `Goal`:
`doneBuildSuccess(mc, success)` and `doneBuildFailure(mc, ex)`. Each
takes the per-class `MaintainCount` slot by reference and runs the
shared body. The two derivation goals' overrides reduce to one-line
forwards, with their per-class `builtOutputs` shape passed in via the
`BuildResult::Success` argument.

Catalog candidate NixOS#47.

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
…ards

Adds **Branch:** lines to the 30 catalog entries that landed as commits
on the four cleanup shard branches (libexpr, libstore, libutil,
nix-cli) over the previous batch.

Per-shard tally (commits on each branch beyond the previously-pushed
tip):

- libexpr (HEAD 437eea9 -> +10): NixOS#64, NixOS#66, NixOS#68, NixOS#106, NixOS#107, NixOS#109,
  NixOS#110, NixOS#112, NixOS#196, NixOS#199. Two of the original twelve were skipped on
  rule grounds: NixOS#194 (LookupPath::Elem flatten) — the candidate
  framing claimed the types were internal, but search-path.hh ships
  via install_headers, so collapsing is a public-ABI break, not a
  trivial flatten; NixOS#197 (one-arg findFile drop) — EvalState::lookupPath
  is a private member, so the candidate's "have callers pass it
  explicitly" prescription cannot apply.

- libstore (HEAD 5f5b815 -> +12): NixOS#4, NixOS#5, NixOS#6, NixOS#14, NixOS#47, NixOS#82, NixOS#114,
  NixOS#115, NixOS#119, NixOS#157, NixOS#159, NixOS#165. Several departures from the literal
  prescription, recorded in each commit body and in the per-candidate
  Branch line: NixOS#14 lifted only getRemoteFSAccessor with a
  getLocalNarCacheDir hook (left the trivial getFSAccessor overrides
  per-class); NixOS#115 extracted only the prelude (lockProfile +
  findGenerations) since two callers use stateful reverse iteration;
  NixOS#119 confirmed init's setDefault is a different shape and stayed
  out; NixOS#159 dropped the assert(!childEOF) defensive check after walking
  Goal::handleEOF producers; NixOS#165 used option (b) of the prescription
  (a new derivation-output-fwd.hh) because option (a) would have
  introduced an include cycle.

- libutil (HEAD 784a4f4 -> +3): NixOS#29, NixOS#99, NixOS#117. NixOS#29's commit body
  caveat (XDG_*_HOME / XDG_CONFIG_DIRS reads moved from per-call to
  cached) is recorded on the candidate Branch line.

- nix-cli (HEAD 48524e0 -> +5): NixOS#24, NixOS#77, NixOS#89, NixOS#91, NixOS#187. NixOS#91 shipped
  the GcRootNamer + nameForCurrent consolidation but deferred the
  candidate's addPermRootWithCounter free helper because three
  behavioural differences across call sites (rootNr increment
  position, absPath timing, printGCWarning conditions on store2 null)
  would have either changed user-visible path naming or grown the API.

STATUS.md's cleanup-branches table is updated with each shard's
expanded Addresses list, and the Status column now distinguishes the
already-pushed tips (libfetchers/libflake/libmain remain Pushed since
they got no new commits) from the four shards whose new commits are
local-only.

Push policy is explicit-only — none of the four shard branches has
been pushed past its prior tip.

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
Three deep-dive adversarial reviews of the post-cleanup state surfaced
work that wasn't reflected in the catalog:

- **Wire-format review** found a public-API break in NixOS#6 (the
  GET_PROTOCOL_MAJOR/MINOR macros lived in install_headers-shipped
  headers; their deletion is observed by external consumers like
  Hydra/Lix/plugins). The candidate's Branch line now documents this
  as a deliberate API break and gives a migration recipe via
  WorkerProto::Version::Number::fromWire, including the subtle
  semantic shift (the old macro returned the high byte unshifted).
  The deletion-commit body in cleanup/libstore is amended to match.

- **Traceability audit** found that the macro→template follow-up
  commit on cleanup/libstore had no candidate reference in its body
  and neither NixOS#4 nor NixOS#5 mentioned the follow-up in their Branch line.
  Both now describe the two-stage evolution (initial macro
  consolidation, then full replacement with the
  LengthPrefixedProtoHelper template constrained on
  LengthPrefixContainer). Pattern matches the NixOS#6 hoist-then-delete
  and NixOS#110 extended-to-forceValueDeep annotations.

- **Bare libstore Branch lines** in NixOS#47 (DerivationGoal/
  DerivationBuildingGoal done* dedupe), NixOS#82 (tryAcquireSlotLock with
  the FdLock-bypass rationale), NixOS#114 (file-static getAttr<T>
  template) gain descriptive parentheticals matching the
  libexpr/libutil/nix-cli style.

STATUS.md `vibe-coding/cleanup/libstore` row's Addresses column gains
two annotations (`NixOS#4 (extended to template form)`, `NixOS#5 (extended to
template form)`) plus the existing `NixOS#6 (hoist-then-delete)` framing,
so future readers can map row entries to commit ranges without having
to walk git history.

The libstore commit body for `1812c99a3` (macro→template) is amended
in a parallel rebase on cleanup/libstore to add `Refs candidates NixOS#4
and NixOS#5`. The deletion commit `9f2478416` is amended to include the
public-API break documentation. The NixOS#159 ChildEvents collapse commit
(`ead54c3c7`) is amended to add a `childEventsHighWatermark = 16`
runtime assert in pushChildEvent, converting the structural fd-count
bound documented in popChildEvent's comment into a check that catches
future Goal subclasses with many fds.

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
DerivationGoal::doneSuccess and DerivationBuildingGoal::doneSuccess
shared identical bookkeeping around their `MaintainCount` handle:
reset the handle, bump `worker.doneBuilds` on `Built`, push
`worker.updateProgress()`, then forward to `Goal::doneSuccess`. Their
doneFailure overrides were byte-identical except for the handle name.

Lift the bookkeeping into two protected helpers on `Goal`:
`doneBuildSuccess(mc, success)` and `doneBuildFailure(mc, ex)`. Each
takes the per-class `MaintainCount` slot by reference and runs the
shared body. The two derivation goals' overrides reduce to one-line
forwards, with their per-class `builtOutputs` shape passed in via the
`BuildResult::Success` argument.

Catalog candidate NixOS#47.

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
…le, §10, §16)

Batches tasks NixOS#42, NixOS#44, NixOS#45, NixOS#46, NixOS#47, NixOS#48:
- Add WalkHit entry in §6 with {resultHash, terminalCur} shape
- Add EvolutionStep entry in §17 (was referenced, never defined)
- Retitle §14 'argAncestry' (drop 'the enclosing scope of a subject' — 'scope' was the word we eliminated)
- Trim §16 argCell redundant sentence
- Reword §10 opening ('probed the other way around' → 'the other side probes')
- Deduplicate §17 SubjectEvolutionEdge — schema now referenced from §18 rather than restated

Task NixOS#41 (define EvolutionStep) subsumed by the §17 addition.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants