gytis-ivaskevicius / flake-utils-plus

Use Nix flakes without any fluff.
MIT License
459 stars 52 forks source link

nix-shell to respect system's overlays #132

Closed andrevmatos closed 9 months ago

andrevmatos commented 1 year ago

It seems like sharedOverlays and overlaysBuilder are only applied as argument to import <channel> { overlays = ... } instantiation; This makes nix-shell not see those overlays, and therefore neither packages and overrides set on them, to appear and be available in dev environments.

Is there a way to make nix-shell (and maybe other tools which deal with channels and nixpkgs) to see "materialized" versions of nixpkgs (or current, system, or other channels) including overlays set system-wide?

gytis-ivaskevicius commented 9 months ago

I am not quite sure what you mean. You are able to access pkgs with overlays from self.pkgs. Here is an example:

❯ repl
nix-repl> flake.pkgs.x86_64-linux.nixpkgs.g-firefox.pname
"firefox"

I personally use custom repl which is committed in to this repository but there should be no difference between repl's. Probably what you are looking for is using self.pkgs.<system>.<channel>.<your package from overlay> from within nix develop

andrevmatos commented 9 months ago

Maybe an example will make it easier to explain:

Imagine you have an overlay, adding a new packageA to nixpkgs input/channel, and both nix.generateNixPathFromInputs = true; and nix.generateRegistryFromInputs = true;

When using nixpkgs (or pkgs) in a host or module inside mkFlake, you can reference and use packageA: this is possible because nixpkgs is imported with { overlay }

If you try to use the nixpkgs channel somehow else, e.g. nix-shell -p packageA or nix-build '<nixpkgs> -A packageA, it instantiates the channel from the linked source in store, and therefore does NOT include the overlay.

I'm not sure if there's a way to materialize in store a channels-compatible source which would be the same (including overlay and config) from what the instance look to modules inside mkFlake.

gytis-ivaskevicius commented 9 months ago

yes, it is possible to do this kind of thing:

nix shell /etc/nixos#pkgs.x86_64-linux.nixpkgs.g-firefox
nix build /etc/nixos#pkgs.x86_64-linux.nixpkgs.g-firefox

However may I recommend writing some bash helper for this to avoid verbosity

I generally don't need what you described but you might find this function helpful:

nix-cd () {
    cd $(nix eval --expr "(builtins.getFlake "flake:self").outputs.pkgs.x86_64-linux.nixpkgs.$1.outPath" --impure --raw)
}

This function changes directory to the package of my machine in case I need to inspect it. Works with overlays

Can we close this issue?

andrevmatos commented 9 months ago

Yes, we can close the issue. Sure, you can use flakes since output exposes the nixpkgs instance already with overlay applied, and this is the more modern solution; just the channels links don't, but I'd say that is already deprecated in this world of flakes. Thank you.