Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shellify use the local nixpkgs path instead of the remote one #12

Open
RoadRoller01 opened this issue Apr 28, 2024 · 10 comments
Open

shellify use the local nixpkgs path instead of the remote one #12

RoadRoller01 opened this issue Apr 28, 2024 · 10 comments

Comments

@RoadRoller01
Copy link

image
i am using flake for my nixos, and set the nixpkgs to "github:nixos/nixpkgs/nixos-unstable" so
it should use it instead of the local one.

@danielrolls
Copy link
Owner

Hi @RoadRoller01, the value for that input is actually taken from the output of nix flakes registry list. If you run nix shell nixpkgs#someProgram you'll get someProgram from whatever nixpkgs is set to in the registry. nix-shell -p someProgam will instead take someProgram from the wherever nixpkgs points but AFAIK flakes can't point at this environment variable. I have to admit I didn't know all this until I wrote this tool.

I could add functionality to try to in some circumstances decode the value of nixpkgs and attempt to convert it to a flake input. But I wonder if it's overkill, especially since using nix-shell is the old way now. I tried to get a feeling of what the community want on discourse but didn't get a lot of discussion. Please consider contributing there if you have ideas as it's not clear to me what the consensus is on this from the community so I'm keen to see discussion on the matter:
https://discourse.nixos.org/t/shellify-tool-for-shell-nix-generation/33935

Also, it would be interesting to know why your nixpkgs registry entry is a local path. My nixos is built from flakes too and it doesn't look like that. Do you happen to know why yours is like that? Can you please share your nix registry list output?

Thanks for the feedback.

@RoadRoller01
Copy link
Author

sure,
its

system flake:nixpkgs path:/nix/store/801l7gvdz7yaibhjsxqx82sc7zkakjbq-source
global flake:agda github:agda/agda
global flake:arion github:hercules-ci/arion
global flake:blender-bin github:edolstra/nix-warez?dir=blender
global flake:bundlers github:NixOS/bundlers
global flake:cachix github:cachix/cachix
global flake:composable github:ComposableFi/composable
global flake:disko github:nix-community/disko
global flake:dreampkgs github:nix-community/dreampkgs
global flake:dwarffs github:edolstra/dwarffs
global flake:emacs-overlay github:nix-community/emacs-overlay
global flake:fenix github:nix-community/fenix
global flake:flake-parts github:hercules-ci/flake-parts
global flake:flake-utils github:numtide/flake-utils
global flake:gemini github:nix-community/flake-gemini
global flake:helix github:helix-editor/helix
global flake:hercules-ci-agent github:hercules-ci/hercules-ci-agent
global flake:hercules-ci-effects github:hercules-ci/hercules-ci-effects
global flake:home-manager github:nix-community/home-manager
global flake:hydra github:NixOS/hydra
global flake:mach-nix github:DavHau/mach-nix
global flake:nickel github:tweag/nickel
global flake:nimble github:nix-community/flake-nimble
global flake:nix github:NixOS/nix
global flake:nix-darwin github:LnL7/nix-darwin
global flake:nix-serve github:edolstra/nix-serve
global flake:nixops github:NixOS/nixops
global flake:nixos-hardware github:NixOS/nixos-hardware
global flake:nixos-homepage github:NixOS/nixos-homepage
global flake:nixos-search github:NixOS/nixos-search
global flake:nixpkgs github:NixOS/nixpkgs/nixpkgs-unstable
global flake:nur github:nix-community/NUR
global flake:patchelf github:NixOS/patchelf
global flake:poetry2nix github:nix-community/poetry2nix
global flake:pridefetch github:SpyHoodle/pridefetch
global flake:sops-nix github:Mic92/sops-nix
global flake:systems github:nix-systems/default
global flake:templates github:NixOS/templates

for some reason i have two nixpkgs one tagged global and one tagged system, so i think you should use the global one?

@danielrolls
Copy link
Owner

Thanks for sharing the output.

If I were to use the system one this would break for somebody choosing to override the global one with their own local version. It would be good to understand how the local one got there. You might want to try updating your Nixos flake and see if the system nixpkgs changes. If it doesn't then you should delete it because it is surely growing stale. If it changes I suspect you are using something that chooses to pin nixpkgs to a local version and my gut feeling is that shellify should respect that rather then do something confusing or convoluted.

I'm interested to know if your flake did this and whether others are likely to get have situation.

@RoadRoller01
Copy link
Author

i quit nixos(:

@Vaisakhkm2625
Copy link

i quit nixos(:

:( nooooo.....
i was about to ask if you could add a flag to use global values...

@danielrolls
Copy link
Owner

@Vaisakhkm2625, I'm now seeing the system value set to a Nix store path too. I think this behavior may have changed. I now suspect we should ignore the system value for at least nixpkgs by default and not with a flag. It would be good to understand this better though. Any experiments or analysis in this area are most welcome.

@Vaisakhkm2625
Copy link

@Vaisakhkm2625, I'm now seeing the system value set to a Nix store path too. I think this behavior may have changed. I now suspect we should ignore the system value for at least nixpkgs by default and not with a flag. It would be good to understand this better though. Any experiments or analysis in this area are most welcome.

so can we reopen the issue to make it global?

@danielrolls
Copy link
Owner

@Vaisakhkm2625, I'm now seeing the system value set to a Nix store path too. I think this behavior may have changed. I now suspect we should ignore the system value for at least nixpkgs by default and not with a flag. It would be good to understand this better though. Any experiments or analysis in this area are most welcome.

so can we reopen the issue to make it global?

Yes, of course we can. The main thing I think we need to understand to address this is whether the pinning of the system value is happening for nixpkgs only or whether we need to change the rules for all inputs. I don't want to make the situation amny more complicated than it already is.

@danielrolls danielrolls reopened this Nov 23, 2024
@danielrolls
Copy link
Owner

I'm part way through reading the comments in NixOS/nix#7422 which may help us understand the situation better.

@danielrolls
Copy link
Owner

So I read the above and found a link to https://github.com/NixOS/nixpkgs/pull/254405/files which appears to be pinning the system flake specifically for the case of nixpkgs. I don't think it makes sense to copy this pinning over into flake.nix (although pinning flake.lock would be beneficial). I'm thinking we should do the following for now:

  1. By default take from the user registry, then system if not available and finally from global.

  2. In the case of nixpkgs only, if the system entry is set to point to a path then fall straight through to the global entry.

  3. Keep the above by default but add a switch --always-take-from-system-registry to revert to the old behavior.

@Vaisakhkm2625 what do you think? This is more complicated than I would like but I think it's necessary due to the complicated implementation of nix registries in the nix tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants