Skip to content

derivation.nix: Respect __ignoreNulls for outputs - #223

Closed
shlevy wants to merge 1 commit into
NixOS:masterfrom
shlevy:ignore-nulls-outputs
Closed

shlevy wants to merge 1 commit into
NixOS:masterfrom
shlevy:ignore-nulls-outputs

Conversation

@edolstra

Copy link
Copy Markdown
Member

Why would we want this? Why not just not set outputs to null?

If it's about giving a better error message, then you should do something like `if ! isList outputs then throw ... else ...".

@shlevy

shlevy commented Mar 12, 2014

Copy link
Copy Markdown
Member Author

For the same reason we have __ignoreNulls at all: Setting outputs to [ "out" ] results in a different derivation than not setting outputs at all. If we're OK with saying "just don't set outputs to null", what's the justification for having __ignoreNulls? Note that derivationStrict ignores outputs when it's null.

Note that the specific case is https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/kernel/manual-config.nix#L77 . We could of course just do else [ "out" ] there or assign outputs inside of an optionalAttrs, but again I wonder why we have __ignoreNulls at all if that's preferable?

@edolstra

Copy link
Copy Markdown
Member

The only reason for __ignoreNulls was to introduce a change to the derivation hashing scheme (namely, that nulls are equivalent to not setting an attribute) in a backward-compatible way. It's not intended to imply some sort of universal overloading that nulls are acceptable values everywhere. The type of outputs is "a list of strings", not "a list of strings or a null".

So yes, you should set it to ["out"], not to null.

@shlevy

shlevy commented Mar 12, 2014

Copy link
Copy Markdown
Member Author

Why is it desirable for null to be equivalent to not setting an attribute for every attribute except outputs?

@edolstra

Copy link
Copy Markdown
Member

Because null is only intended to be equivalent to not setting an attribute for the purpose of hash computation.

@shlevy

shlevy commented Mar 12, 2014

Copy link
Copy Markdown
Member Author

Alright

@shlevy shlevy closed this Mar 12, 2014
@shlevy
shlevy deleted the ignore-nulls-outputs branch March 12, 2014 12:40
zolodev pushed a commit to zolodev/nix that referenced this pull request Jan 1, 2024
….3.2

chore(deps): bump sphinx from 4.3.1 to 4.3.2
tebowy pushed a commit to tebowy/nix that referenced this pull request Jul 11, 2024
This is terrible UX, and frankly an eval failure should be a cache
invalidation anyway.

This removes the CachedEvalError type entirely.

Fixes NixOS#223.

Change-Id: I91f8003eabd0ea45003024e96d1de3c7ae8e49d8
P-E-Meunier pushed a commit to P-E-Meunier/nix that referenced this pull request Feb 26, 2025
It already works for `dependencies` and `build-dependencies`, just seems
like an oversight.

I ran `cargo test`, seems to pass.

Fixes NixOS#223.
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
…p amends

Three new catalog candidates filed during the post-audit follow-up
sweep:

  - NixOS#222 (libmain → 11-legacy-cli.md): --max-freed parses as int64_t
    then std::max-clamps before assigning to uint64_t.  Implemented
    on vibe-coding/cleanup/libmain: both call sites switched to
    getIntArg<uint64_t> with the clamp dropped.  User-visible
    behaviour change: --max-freed -1 now errors at parse time
    instead of silently disabling, and N above int64_t::max() is
    now honoured up to uint64_t::max().

  - NixOS#223 (libmain → 11-legacy-cli.md): getIntArg<N> is now a
    5-line wrapper; inlining at the two call sites would let it be
    deleted from shared.hh.  Filed but NOT implemented — the inline
    form is 3 lines per site vs 1 line currently, and the candidate
    body itself notes "stylistic regression, not behavioural".

  - NixOS#224 (libutil → 12-libutil-libstore-core-extras.md):
    NarIndexer::createMember computes path depth via
    `for (auto _ : path) (void) _; ++level;` instead of any idiomatic
    accessor.  Filed but NOT implemented — the cleaner factor is to
    add `CanonPath::numSegments()` first; deferred to a future
    libutil batch where canon-path.hh is already being touched.

Plus four code/doc follow-up amends folded into existing commits:

  - libexpr NixOS#214 (eval.hh): added "// Only instantiated in eval.cc"
    note above the mkFailedFromCurrentException declaration to
    prevent future contributors from adding cross-TU callers that
    would link-fail.
  - libstore NixOS#135 (unix/user-lock.cc): nested UidRange inside
    AutoUserLock since it is the only user; eliminates a file-scope
    type for a struct used by exactly one method.
  - libstore NixOS#221 (configuration.hh): expanded the parseSettingTokens
    docstring to document why the libutil specialisations
    (Strings/StringSet/list<path>/set<path>/set<ExperimentalFeature>)
    were intentionally not migrated, so future readers don't try
    to "finish the job".
  - libutil NixOS#163 (file-descriptor.hh): added a "calling-style note"
    to the PipeOptions docstring documenting that pipe.create({})
    is intentionally NOT recommended due to the latent ambiguity
    with the existing arity-asymmetric overload's default arg.

INVENTORY.md catalog total updated 221+44 → 224+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 23, 2026
…ild-dir reconfigure

After the post-audit follow-up sweep landed:

  - NixOS#222 implemented on libmain (a7bb49f): --max-freed parses
    as uint64_t directly, std::max clamp dropped.
  - NixOS#223 filed but not implemented (inline tradeoff documented).
  - NixOS#224 filed but not implemented (depends on a CanonPath
    accessor that hasn't been added).
  - Four code/doc amends folded into existing commits:
    libexpr NixOS#214 instantiation note, libstore NixOS#135 UidRange
    nested in AutoUserLock, libstore NixOS#221 doxygen scope expansion,
    libutil NixOS#163 PipeOptions ambiguity note.
  - Plus a load-bearing protocol fix: libmain build dir was
    misconfigured against master source per the worktree-source-
    drift gotcha in HANDOFF.md; reconfigured against the worktree
    so all subsequent builds compile the actual cleanup tree.

Final tip SHAs: libexpr c9401c3, libfetchers dc5dc00, libflake
fd75c93, libmain a7bb49f, libstore e565149, libutil e3f2287,
nix-cli ef32368.  All seven branches Local-only past their pushed
tips; push policy explicit-only.

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
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
The original complaint — that getIntArg<N> had become a 5-line wrapper
that did its own iterator advance, end-check, and parse — was real:
after NixOS#128 dropped the bool allowUnit parameter, the body was just
a near-duplicate of the free getArg(opt, i, end) function followed by
a call to string2IntWithUnitPrefix<N>(*i).

Delegate the advance-and-error half to getArg, which already does
exactly that. Body collapses to one line; semantics are preserved
(same UsageError wording, same end-check timing, same iterator state
after the call). The function template stays in the shipped
libmain/include/nix/main/shared.hh so external callers (Hydra, Lix)
continue to see the same signature.

The candidate body warned about a "stylistic regression" — re-spelling
the "requires an argument" error at each call site if the wrapper
were inlined. Keeping getIntArg as a wrapper avoids that regression
entirely; the two in-tree call sites in nix-store/nix-store.cc::opGC
and nix-collect-garbage/nix-collect-garbage.cc::main_nix_collect_garbage
keep their getIntArg<uint64_t>(...) form unchanged.

Refs candidate NixOS#223.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 25, 2026
opInstall's --priority arm hand-rolled the same advance + end-check +
"requires an argument" throw + parse pattern that getArg encapsulates.
After libmain NixOS#223 turned getIntArg<N> into a one-line wrapper around
getArg(opt, i, end) + string2IntWithUnitPrefix<N>, this was the only
remaining in-tree CLI-arg-parse site doing the work inline.

The site can't use getIntArg directly because getIntArg parses with
string2IntWithUnitPrefix<N>, which accepts K/M/G suffixes that don't
make sense for a profile priority. opInstall wants string2Int (no
unit prefix) with explicit nullopt-handling for the "couldn't parse
as int" diagnostic.

Replace the inline end-check + iterator advance + UsageError throw
with a single getArg(arg, i, opFlags.end()) call; keep the
string2Int<int>(...) parse + nullopt-check unchanged. Three lines
become one; the diagnostic for "missing argument" now matches the
canonical "'%1%' requires an argument" wording getArg emits (which
is what the inline code was throwing anyway).

Refs candidate NixOS#231.

Co-Authored-By: Claude Opus 4.7 (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