Skip to content

nix profile counter-intuitively uses regexp to match packages #7962

@bobvanderlinden

Description

@bobvanderlinden

nix profile remove and upgrade accept an regexp argument to be able to match specific (or ranges of) packages. This usually results in confusion. Some common errors that people can run into:

Forgetting quotation in most shells:

$ nix profile remove .*vim.*
fish: No matches for wildcard '.*vim.*'. See `help wildcards-globbing`.
nix profile remove .*vim.*
                   ^~~~~~^
$ nix profile remove .*vim.*
zsh: no matches found: .*vim.*

Using wildcards instead of regexp result in confusing error message:

$ nix profile remove '*vim*'
error: Mismatched '(' and ')' in regular expression

Which ( and )?

Forgetting regexp and wildcards altogether:

$ nix profile remove vim
warning: 'vim' does not match any packages
warning: Use 'nix profile list' to see the current profile.

This makes it seem like vim was not installed at all, but it just wasn't matched by the regexp vim, because it should match flake:nixpkgs#legacyPackages.x86_64-linux.vim.

I'm thinking nix profile should only optionally accept regexp and it should be very explicit about it. For instance --regex "your regex". It shouldn't be the default to match packages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnew-cliRelating to the "nix" command

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions