Nix: Nix doesn't use the flake inputs

Created on 1 Jul 2020  路  5Comments  路  Source: NixOS/nix

Describe the bug

When running nix shell nixpkgs#hello in a repository that contains a flake.nix and flake.lock files, I would expect Nix to use the version of nixpkgs that is specified in the lock file. Instead, it sources it from the latest registry version.

This means that every time the flake TTL is reached, Nix will try and pull the latest registry and maybe get a different version of the package. I would prefer if I was able to pin and control when that version gets updated for a particular project.

Workaround

It's possible to re-export nixpkgs in the flake and then access it, for example with nix shell .#nixpkgs.hello.

While this is possible, I think that it would be more convenient to get access to the underlying inputs directly. That will make debugging easier for example.

nix-env --version output

nix-env (Nix) 2.4pre20200521_00b562c
bug flakes

Most helpful comment

Here's an idea: we could have a flag that overrides the registry using the lock file entries from the specified flake. E.g.

$ nix run --override-from . nixpkgs#hello

I.e. the registry entry for nixpkgs would be set to the nixpkgs input from the flake in the current directory.

This could have other uses, like copying lock file entries from another flake (e.g. nix flake update --override-from /path/to/other/flake --update-input nixpkgs).

All 5 comments

I don't see it as a bug, but as an expected behavior. I think this behavior would confuse if running nix shell from different dirs creates a different shell

I agree, but it would be nice to have some syntax to use a flake input from another flake.

Here's an idea: we could have a flag that overrides the registry using the lock file entries from the specified flake. E.g.

$ nix run --override-from . nixpkgs#hello

I.e. the registry entry for nixpkgs would be set to the nixpkgs input from the flake in the current directory.

This could have other uses, like copying lock file entries from another flake (e.g. nix flake update --override-from /path/to/other/flake --update-input nixpkgs).

I like that idea. This would also allow me to write a wrapper script that can search-up for the flake.lock file so that nix build can be called anywhere from within that repository.

That should probably work without any wrapper scripts...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

copumpkin picture copumpkin  路  41Comments

ryanbooker picture ryanbooker  路  34Comments

domenkozar picture domenkozar  路  53Comments

cbarrett picture cbarrett  路  49Comments

matthewbauer picture matthewbauer  路  64Comments