Passing flake arguments to nixpkgs package

I expected I’d find an answer to this online somewhere, but maybe I’m struggling to find the right search terms. I have seen a few threads about how it’s difficult to pass arguments to flakes, but AFAICT none of those contained clear general solutions.

I can get spotifyd with nix shell nixpkgs#spotifyd. But the package has a flag, withMpris, disabled by default, which I wish to enable. How do I modify my nix shell invocation to set withMpris to true?

1 Like

It isn’t exactly pretty, but you could do this:

nix shell "$(nix eval --raw nixpkgs#spotifyd --apply 'x: (x.override {withMpris = true;}).drvPath')"

This will evaluate the derivation file with your desired override applied, and then you can call nix shell directly on that derivation.

This works in a pinch, but to make it nicer you could make your own flake that simply exports the modified package.

1 Like

Cool, that worked on Nix 2.14. I had to modify it to nix shell "$(nix eval --raw nixpkgs#spotifyd --apply 'x: (x.override {withMpris = true;}).drvPath')^*" due to changes in Nix 2.15.

Do you happen to know if there’s any intention to make this sort of thing more ergonomic?

Incidentally, figuring out what had changed with the syntax was not straightforward. Running the original command gave me:

warning: The interpretation of store paths arguments ending in `.drv` recently changed. If this command is now failing try again with '/nix/store/ckz6h4cv98d7744n56smp2j5d0y6q57a-spotifyd-0.3.4.drv!*'

But the suggested modification didn’t work. It was only after reviewing the release notes that I successfully tried replacing ! with ^. It’s not clear to me what the difference is, though I haven’t really looked in to it.