Skip to content

nix-env: Add support for --delete-generations 15d - #222

Closed
wizeman wants to merge 2 commits into
NixOS:masterfrom
wizeman:days
Closed

wizeman wants to merge 2 commits into
NixOS:masterfrom
wizeman:days

Conversation

@wizeman

@wizeman wizeman commented Mar 11, 2014

Copy link
Copy Markdown
Member

It will delete all generations older than the specified number of days.

@wizeman

wizeman commented Mar 11, 2014

Copy link
Copy Markdown
Member Author

I have also added a --delete-days option to nix-collect-garbage.

Note however, that I haven't tested the changes to the manuals (the build in nixpkgs breaks if I change them), and I also don't know anything about the docbook format, so the build may break or the result might look ugly.

@edolstra

Copy link
Copy Markdown
Member

Can you rename --delete-days to --delete-older-than (since we're not deleting days), and get rid of -dd (since all single-dash options must be one character)?

It also seems a bit inconsistent to allow a d suffix in nix-env --delete-generations, but not in nix-collect-garbage. Maybe we'd like to allow other suffixes in the future.

Comment thread src/nix-env/nix-env.cc Outdated

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.

This can be done easier with tolower().

wizeman added 2 commits March 12, 2014 14:35
It will delete all generations older than the specified number of days.
@wizeman

wizeman commented Mar 12, 2014

Copy link
Copy Markdown
Member Author

@edolstra Fixed all the issues you mentioned :)

@redbaron

Copy link
Copy Markdown
Contributor

+1

@edolstra

Copy link
Copy Markdown
Member

Applied!

@edolstra edolstra closed this Mar 29, 2014
zolodev pushed a commit to zolodev/nix that referenced this pull request Jan 1, 2024
…ser-0.16.1

chore(deps): bump myst-parser from 0.16.0 to 0.16.1
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
GCOptions::maxFreed (in libstore/include/nix/store/gc-store.hh) is
declared as `uint64_t maxFreed{numeric_limits<uint64_t>::max()}`, but
both call sites in `nix-store --gc --max-freed N` and
`nix-collect-garbage --max-freed N` parsed via `getIntArg<int64_t>(...)`
and clamped negatives via `std::max(..., (int64_t) 0)` before
implicit-converting to `uint64_t`. The clamp silently disabled
`--max-freed` for any value above `INT64_MAX` because the parser
overflows to a negative `int64_t`.

Parse as `uint64_t` directly. `string2IntWithUnitPrefix<uint64_t>`
rejects negative values at the parser level (the leading `-` does not
match the integer pattern), so the clamp becomes unnecessary. Net
behaviour: `--max-freed -1` (or any non-numeric) now errors at parse
time instead of silently disabling the cap; `--max-freed N` for N
outside `int64_t` range is now honoured up to `uint64_t::max()`.

Refs candidate NixOS#222.

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

Four cleanup-branch commits land the in-source corrections and
release-note entries surfaced by the holistic review:

- libexpr 2064c3a: lexer.l ID-rule pinning comment retargeted
  from print.cc → print.hh; doc/manual/rl-next/
  primop-diagnostic-position.md added.
- libstore 3123c3c: worker-protocol-connection.hh operator
  coercion docstrings rewritten (no longer claim "serve
  protocol serializers"); common-protocol.hh negotiateVersion
  docstring documents why server-side handshakes use bare
  std::min.
- libmain 0b66d94: doc/manual/rl-next/max-freed-clamp.md
  documents the parse-error and full-uint64-range changes from
  candidate NixOS#222.
- libfetchers d1a856c: github-fetcher-param-validation.md
  extended to cover the treeHash attribute rejection.

The libfetchers github.cc:328 FIXME annotation was deferred per
the reviewer's own conditional framing — the next code change
in that region picks it up.

No push.

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
…ange changes

Candidate NixOS#222 changed two user-visible behaviours of `nix-store --gc
--max-freed N` and `nix-collect-garbage --max-freed N`:

- Negative values previously silently disabled the cap (because the
  pre-fix code did `std::max(parse_int64, 0)` and overflowed on the
  parse). They now error at parse.
- Values above INT64_MAX (~9.2 EB) likewise overflowed and silently
  disabled the cap. The full uint64_t range is now honoured.

Add a release-note entry covering both. Anyone who relied on a
negative value as a "no cap" sentinel should drop the flag entirely.

Refs candidate NixOS#222.

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
…3 coverage gaps + NixOS#218 stale inventory

Pass-4 adversarial review caught a BLOCKER and three lower-grade
findings. The BLOCKER (NixOS#185 missing rl-next) was fixed in a
separate commit on cleanup-libstore (09abb81); this commit
records the doc-branch fallout.

STATUS.md cleanup-branches table libstore row: tip moves to
09abb81 (was 6022c29) with a Pass-4 review note. STATUS
Current tip SHAs block updated in lockstep.

New "Post-batch-H Pass-4" recently-completed entry summarising
the BLOCKER fix and three coverage-gap findings recorded but
not actioned this round (any new tests would mean new commits
on already-pushed branches; defer until the next batch lands
alongside).

Catalog body amends:

- NixOS#218 wire-marker inventory (12-libutil-libstore-core-extras.md)
  added a "Pre-implementation note (Pass-4 review)" warning
  that the `worker-protocol.cc`-cited site is pre-NixOS#1+NixOS#3
  template-lift; the marker now lives in
  `common-protocol-impl.hh`. NixOS#218 is queued/unimplemented; the
  note prompts a re-run of the inventory grep before scoping.
- NixOS#222 Branch line gained a "Coverage gap" note: the negative-
  value error path has no functional-test coverage.
- NixOS#235 Branch line gained a "Coverage gap" note: no functional
  test asserts the warning text appears on stderr.

NixOS#80's existing Branch line already self-disclosed "No existing
tests exercised the Windows side"; no edit needed there.

Push-state finding (recorded in STATUS, not actioned): three of
seven origin tips diverge and require force-push when
published — libstore (origin still has dropped b9a750f),
libutil (origin still has pre-rebase da1e0d7), nix-cli
(origin lacks Batch H).

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
…OS#259, fixes ledger

Independent whole-branch audit (22 agents -> dedup -> per-finding
adversarial verify): 70 findings, 63 confirmed, 7 refuted.

Catalog corrections (counts/claims re-derived against master):
  - NixOS#65: recorded grep was malformed (anchored `builtins\."` returns 2,
    not 79); restored the unanchored form, noted the 87-name-anchored
    alternative is a different set (F014).
  - NixOS#18: B3's grep returns 24 lines / 23 hand-written, not 17; added the
    six omitted names (F016).
  - NixOS#169/NixOS#217/N33: friend count is 11 Expr* lines / 10 distinct, not
    "10 / 9" (F013).
  - NixOS#103/N6 + verified/05: RewritingSink no longer "tracks match
    positions"; matches is dead and HashModuloSink::finish's loop is
    inert since 3ebe134 (F019).
  - NixOS#138: eval.cc read-site is copyPathToStore, not the nonexistent
    "addToStore" (F006).
  - NixOS#218 + STATUS: placeholder inventory undercounted (6 -> 7-8); the
    wire-marker is the BuildResult compat StringMap, not a DrvOutput
    serialisation; nix-store.cc misfiled as a "legitimate constant"
    (F007-F011).
  - README U7b/U7c + N1: migratable cache count and per-site exclusion
    reasons (F017/F018).
  - verified/19: nix_get_external is a functional bug, not a "quirk";
    nix_store_path_hash missing-preamble outlier (F003/F052).
  - verified/17: tree glyphs live in libutil util.hh, not "libcmd
    headers" (F035).
  - NixOS#11-legacy NixOS#222/NixOS#231 + FOLLOWUPS: --max-freed mechanism and the
    --priority getArg mis-recommendation (F001/F002).

New candidates NixOS#241-NixOS#259 filed into their topical sections (per the
catalog's group-by-symptom principle): 03 (NixOS#244), 07 (NixOS#246), 08 (NixOS#243),
10 (NixOS#253,NixOS#255), 12 (NixOS#241,NixOS#242,NixOS#259), 13 (NixOS#248,NixOS#249,NixOS#251), 16
(NixOS#245,NixOS#247), 17 (NixOS#254,NixOS#256), 20 (NixOS#250,NixOS#252), 23 (NixOS#257,NixOS#258).

NixOS#122: re-verified the stackOverflowHandler symbol-mangle caveat is
correct as written (F062).

The audit is recorded as a STATUS.md "Recently completed" event (it
subsumes the per-finding report; no standalone report file is kept).
The corresponding code fixes are uncommitted on the cleanup worktrees.
Also converted the macOS /Users/cbaker2 paths in HANDOFF.md/STATUS.md to
the Linux /home/cbaker2 paths used on this machine.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 29, 2026
The release note for the NixOS#222 --max-freed change described the old
behaviour incorrectly on every point:
  - It said `--max-freed -1` "silently disabled the cap". In fact -1
    clamped via std::max(..., 0) to 0, which means "free nothing" (the
    strictest cap); the no-limit sentinel is uint64_t's max (the
    default when the flag is omitted).
  - It said values above INT64_MAX "overflowed to negative and clamped
    to zero". In fact boost::lexical_cast<int64_t> rejects out-of-range
    input by throwing (it does not wrap), so over-range already errored
    at parse; the clamp was never reached.
  - It advised users relying on a negative "no cap" sentinel to "drop
    the flag entirely instead" — which performs an UNBOUNDED GC, the
    inverse of the old no-op. There was no negative no-cap sentinel.

Rewrite the note to describe the true old/new behaviour and remove the
dangerous migration advice. The underlying code change (parse as
uint64_t, drop the clamp) is correct and unchanged.

Surfaced by the 2026-05 adversarial audit (finding F002). Refs
candidate NixOS#222.

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

nix-store --gc --max-freed N and nix-collect-garbage --max-freed N
previously parsed the argument as int64_t and clamped through
std::max(..., 0) before assigning to the uint64_t field. Document the
two user-visible consequences accurately:

  - Negative values (e.g. --max-freed -1) clamped to 0, i.e. "free
    nothing" (a near-no-op collection, the strictest cap); they now
    error at parse time.
  - Values above INT64_MAX already errored at parse (boost::lexical_cast
    rejects out-of-range input; it does not wrap), and the full uint64_t
    range above INT64_MAX is now accepted.

There was never a negative "no cap" sentinel, so a prior --max-freed -1
has no equivalent flag form and must simply be dropped (dropping the
flag yields an unbounded GC, not the old no-op).

Refs candidate NixOS#222.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
roberth added a commit to roberth/nix that referenced this pull request Aug 9, 2026
…t raw params

Follow-up to NixOS#218: the resolveIdentity CBApply branch was still hand-parsing
params["parent"] / params["argObsSet"] as strings and doing its own
Hash::parseNonSRIUnprefixed. Route through trace::resolveFromJson + std::get_if
so the on-wire ↔ in-memory boundary sits at resolve() exclusively, matching
what dispatchQueryRequest already does.

Suite unchanged: 325/3/7.

Assisted-by: Claude Code (Claude Opus 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.

3 participants