nix-collect-garbage --dry-run flag has incorrect behaviour #432

Closed
opened 2024-07-05 16:57:12 +00:00 by quantumbjump · 2 comments

Describe the bug

The --dry-run flag in nix-collect-garbage doesn't print out unused nix store paths, as I would expect from a dry run. The code here means that if you pass the --dry-run flag, it completely skips the entire body of the script and just returns 0.

Steps To Reproduce

  1. Have a nix store with some dead paths
  2. Run nix-collect-garbage --dry-run
  3. See no output (implying that there's nothing to garbage collect)
  4. Run nix-collect-garbage
  5. See that it does delete the dead paths

Expected behavior

nix-collect-garbage --dry-run should print the paths that would be deleted, and then not delete them.

nix --version output

nix (Lix, like Nix) 2.91.0-dev-pre20240704-d00edfb

Additional context

I'm not well versed in C++, but this seems like it should be a relatively easy fix. The GCOptions struct has a gcReturnDead action, which should return the list of paths that would be deleted instead of actually deleting them. It should be as simple as setting the action to gcReturnDead if the dryRun flag is set, and gcDeleteDead if it isn't.

## Describe the bug The `--dry-run` flag in `nix-collect-garbage` doesn't print out unused nix store paths, as I would expect from a dry run. The code [here](https://git.lix.systems/lix-project/lix/src/branch/main/src/nix-collect-garbage/nix-collect-garbage.cc#L91) means that if you pass the `--dry-run` flag, it completely skips the entire body of the script and just returns 0. ## Steps To Reproduce 1. Have a nix store with some dead paths 2. Run `nix-collect-garbage --dry-run` 3. See no output (implying that there's nothing to garbage collect) 4. Run `nix-collect-garbage` 5. See that it does delete the dead paths ## Expected behavior `nix-collect-garbage --dry-run` should print the paths that *would* be deleted, and then not delete them. ## `nix --version` output `nix (Lix, like Nix) 2.91.0-dev-pre20240704-d00edfb` ## Additional context I'm not well versed in C++, but this seems like it should be a relatively easy fix. The GCOptions struct has a `gcReturnDead` action, which should return the list of paths that would be deleted instead of actually deleting them. It *should* be as simple as setting the action to `gcReturnDead` if the `dryRun` flag is set, and `gcDeleteDead` if it isn't.
quantumbjump added the
bug
label 2024-07-05 16:57:12 +00:00
Member

This issue was mentioned on Gerrit on the following CLs:

  • commit message in cl/1566 ("Fix dry-run flag for nix-collect-garbage")
<!-- GERRIT_LINKBOT: {"cls": [{"backlink": "https://gerrit.lix.systems/c/lix/+/1566", "number": 1566, "kind": "commit message"}], "cl_meta": {"1566": {"change_title": "Fix dry-run flag for nix-collect-garbage"}}} --> This issue was mentioned on Gerrit on the following CLs: * commit message in [cl/1566](https://gerrit.lix.systems/c/lix/+/1566) ("Fix dry-run flag for nix-collect-garbage")
lunaphied added the
ux
label 2024-07-07 20:49:45 +00:00
Owner

this has been fixed but wasn't auto-closed.

this has been fixed but wasn't auto-closed.
Sign in to join this conversation.
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#432
No description provided.