Skip to content

nix-shell: Play nicely with non-interactive shells - #170

Closed
shlevy wants to merge 1 commit into
NixOS:masterfrom
shlevy:nix-shell-noninteractive
Closed

shlevy wants to merge 1 commit into
NixOS:masterfrom
shlevy:nix-shell-noninteractive

Conversation

@shlevy

@shlevy shlevy commented Oct 17, 2013

Copy link
Copy Markdown
Member

nix-shell with the --command flag might be used non-interactively, but
if bash starts non-interactively (i.e. with stdin or stderr not a
terminal), it won't source the script given in --rcfile. However, in
that case it will source the script found in $BASH_ENV, so we can use
that instead.

Also, don't source ~/.bashrc in a non-interactive shell (detectable by
checking the PS1 env var)

Signed-off-by: Shea Levy [email protected]

nix-shell with the --command flag might be used non-interactively, but
if bash starts non-interactively (i.e. with stdin or stderr not a
terminal), it won't source the script given in --rcfile. However, in
that case it *will* source the script found in $BASH_ENV, so we can use
that instead.

Also, don't source ~/.bashrc in a non-interactive shell (detectable by
checking the PS1 env var)

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

Copy link
Copy Markdown
Member

Applied!

@edolstra edolstra closed this Oct 18, 2013
CertainLach pushed a commit to deltarocks/nix that referenced this pull request Sep 4, 2025
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 22, 2026
Two adversarial-review and two pattern-discovery passes (Opus 4.7, 1M ctx,
~5,300 lines under doc/inventory/review/) walked the existing 217-entry
catalog and found cross-shard patterns the per-shard catalogers couldn't
see. This commit folds the four reports into the catalog.

Catalog scope rewrite. The README's "Performance work without duplication
or complexity to fix" exclusion was wrong: hot-path container choices,
allocations in inner loops, cache-line alignment costs, and missed
concurrency are all in scope on their own merits. Same for modernisation:
shrinking the Boost dependency surface or migrating hand-rolled idioms
to stdlib equivalents is a real simplification, even when no underlying
duplication backs the change. The README "What this catalog targets"
section adds an explicit "Performance" bullet and rewrites the
modernisation bullet to be in scope; the anti-list now excludes only
cosmetic changes and feature additions.

Verdict-table corrections. NixOS#50 (resolved-by-design) and NixOS#148 (INVALID,
windowSize destruction-order hazard) had verdict-table rows that
contradicted their validation paragraphs; tables now match. NixOS#171
upgraded VALID per the scope rewrite. Section-17 header updated from
"Five VALID; nine PARTIALLY VALID" to "Six VALID; eight PARTIALLY
VALID" to track.

Reclassifications and corrections from the deeper passes:

- NixOS#140 reframed as dead code (zero callers anywhere; not a SIOF
  hazard as the original framing suggested).
- NixOS#149 mechanism corrected: the `created = 123;` debug field is a
  guard against gcc bug 80431 miscompilation, not a use-after-free
  sentinel as pass-1 had stated.
- NixOS#170 corrected to three Goal subclasses + Waker (not four Goal
  subclasses as the catalog body had said).
- NixOS#147 demoted to PARTIALLY VALID; the singleton-leak path is
  load-bearing for legacy callers and must be retained alongside
  any per-Store ownership migration.
- NixOS#122 expanded with two ABI hazards the prior reviewer missed:
  layout drift in `PrimOp::impl` (allocated by `nix_alloc_primop`
  C-API) and symbol-mangle break in `extern fun<...>
  stackOverflowHandler`.
- NixOS#138 expanded: two C-API readers of `settings.readOnlyMode`, not
  one as pass-1 had stated.
- NixOS#160 expanded with HALO-incompatibility hazard for any
  `boost::asio::awaitable<T>` migration that touches `final_awaiter`.
- NixOS#129 expanded with destructor-throw caveat for the
  `MaintainCount` -> `Finally` replacement.
- NixOS#143 expanded with TLS-fallback shutdown-ordering hazard.
- NixOS#56 reframed as a real ODR fix: different TUs previously saw
  different definitions of the explicit specialisation; the values
  coincidentally matched so behaviour was preserved but the program
  was technically ill-formed.

Count corrections (each verified independently via grep): NixOS#137 register
sites = 16 (15 production + 1 test), NixOS#166 forward-decl headers =
9/21/12 (Store +2 over the catalog body), NixOS#167 buffer-size literals =
10 in libutil / 19 tree-wide, NixOS#169 friend declarations = 16 (one
duplicate `ExprVar`), NixOS#172 `unreachable()` sites = 64-65, NixOS#173 pragma
sites = 10, NixOS#176 daemon cases = 37 (35 distinct bodies), NixOS#178
trust-check sites = 11+1, NixOS#146 env vars = 14 in src/.

Forty-four cross-shard candidates (N1-N44) folded into four new section
files (22-25). The N-numbered range is intentionally separate from
1-217 to keep cross-references stable. Pattern clusters A-G,
architectural debt themes A1-A7, C++23/Boost uplift series U1-U10
(with U7 split per pass-2's refinement), and ten redundant-abstraction
pairs R1-R10 are documented in new README subsections.

Eight follow-up agents (E1-E8) deferred for source-level investigation:
verify `impureOutputHash` deletion path, audit C-API `*Settings`
surface lockstep, write a Goal::Co property test pinning O(1) frame
depth, build a daemon-client error-message preservation matrix, set up
periodic branch verification, validate test-support consolidation,
audit forward-decl source-compat, and choose the
`vTrue`/`vFalse`/`vNull`/`vEmptyList` invariant.

The four review reports plus the consolidation log live under
doc/inventory/review/ and stay in-tree for traceability.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
angerman added a commit to angerman/nix that referenced this pull request Aug 5, 2026
…+1 evac fix

Rule 0 — S2.1 (NixOS#170) in progress. This commit (a) records a validated finding, (b)
fixes one confirmed evac gap, (c) pins the open RCA. NOT a claim that S2.1 is done.
Gated NIX_V3_EVAC (+ NIX_V3_MIDEVAL_GC); DEAD BY DEFAULT (runEvacuation returns early
without NIX_V3_EVAC, and runMajorMarkSweep isn't called with no gates). Default
byte-id + --brute unaffected by construction.

VALIDATED (2026-06-25): the existing cell-pin Bartlett evacuator (runEvacuation),
invoked in the mid-eval path (NIX_V3_MIDEVAL_GC=1 NIX_V3_EVAC=1 NIX_V3_EVAC_CELLPIN=1
NIX_V3_EVAC_PCT=1.0), DOES the RSS reclaim the campaign said was blocked:
  - hello/firefox.drvPath BYTE-IDENTICAL under mid-eval full compaction;
  - synthetic (foldl' over 2M genList, correct result 1e8): evac fires mid-eval
    (exitDepth>0), movedCells=18-19, blocksFreed=2-4, freedRSS=33-67MB MUNMAP'd to OS,
    typed/movable=100%. Mid-eval Bartlett compaction is real + byte-correct.

FOUND (brute-audit, max moving stress, low 8MB threshold): a missed-root class —
nursery cells reachable via tenured Bindings.entries[].value / Thunk.evaluated /
ValuePair.right that the post-evac nursery scavenge doesn't forward. ISOLATED: clean
WITHOUT evac (low threshold alone 17/17), fails WITH evac → it's the moving, not the
frequency.

FIX HERE (necessary, NOT sufficient): forward the remembered set (dirtyContainers)
through evac's relocation map — a relocated dirty cell's DirtyEntry must follow the
move or the next minor scavenge walks the freed old cell. Confirmed gap (runEvacuation
never touched dirtyContainers). Did NOT clear the audit: the hits carry
lastWriter=(raw/bulk-path) → those tenured cells are NOT in the dirty list at all
(raw-written, un-barrier'd tenured->nursery edges). RCA CONTINUES: instrument whether
the audit-hit Bindings is a relocated cell + whether it's precise-reachable post-evac;
the fix is likely evac re-discovering/re-dirtying relocated cells with nursery pointers
(or barriering the raw/bulk write path).

Copyright (c) 2026 Moritz Angermann <[email protected]>, Input Output
Group. SPDX-License-Identifier: Apache-2.0
angerman added a commit to angerman/nix that referenced this pull request Aug 5, 2026
…rrowed, 3 killed

Rule 0 — S2.1 (NixOS#170) still in progress; this records progress + a 3rd necessary
moving-GC-hygiene fix + the narrowed RCA. NOT a claim the brute-audit gate passes.
Gated NIX_V3_EVAC (mid-eval moving); DEAD BY DEFAULT (default byte-id verified).

FIX (necessary, mirrors the proven gen-major path vm.cc:4114): when mid-eval EVAC is
on, clear the attrSelect IC (attrSelectCache[].entries[].bindings) in the mid-eval
clear block. The non-moving mid-eval mark WALKS the IC to mark its Bindings in place
("DON'T clear it"); but EVAC MOVES those Bindings without rewriting the libc-resident
IC slot → stale pointer = the NixOS#705 UAF class the gen-major clear exists to prevent.

RCA STATE (brute-audit under mid-eval full-compaction evac, hello-drvPath/outPath AUDIT
hit "nursery X reachable via Bindings[(no-origin)].entries[].value ... raw/bulk-path"):
THREE hypotheses tested + FALSIFIED (each fix left the audit failing):
  (1) stale dirtyContainers entries  -> forward through evac fwd-map: no change;
  (2) relocated cells holding nursery ptrs -> re-dirty all relocated: no change
      (REVERTED — not a gen-major pattern, costly, unproven);
  (3) stale IC-cached Bindings -> clear IC (this commit): no change for THIS audit.
=> the missed holder is reached via NONE of {dirtyContainers, IC, relocation}; a 4th
mechanism remains. Kept (1)+(3) as genuinely-required moving-GC hygiene (gen-major does
both); dropped (2).

VALIDATED EARLIER (still holds): mid-eval moving compaction WORKS in the common case —
hello/firefox.drvPath byte-id + synthetic moves cells/frees blocks/munmaps 33-67MB.
The MECHANISM is proven; HARDENING to pass brute-audit is the remaining work.

NEXT (instrumented RCA, NOT guessing): capture the full evac-brute (NIX_V3_EVAC_BRUTE
pre-free cell scan) + postScavengeAudit root PATH for the failing hello-drvPath to
identify the actual root reaching the stale holder. Suspect: the experimental evac
(NIX_V3_EVAC, an "unrevived path") under the never-validated cell-pin + EVAC_PCT=1.0 +
mid-eval combination has a latent incomplete-rewrite bug.

Copyright (c) 2026 Moritz Angermann <[email protected]>, Input Output
Group. SPDX-License-Identifier: Apache-2.0
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