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

Flake setups are not reliably detected #210

Open
emilazy opened this issue May 23, 2023 · 10 comments · May be fixed by #227
Open

Flake setups are not reliably detected #210

emilazy opened this issue May 23, 2023 · 10 comments · May be fixed by #227

Comments

@emilazy
Copy link

emilazy commented May 23, 2023

I have an all-flakes nix-darwin/home-manager setup but the command-not-found.sh script gives me nix-shell output. It seems like I have no user profile to look for a manifest.json in:

emily@yuyuko ~> ls -l ~/.nix-profile
lrwxr-xr-x  1 emily  staff  44 20 May 10:49 /Users/emily/.nix-profile@ -> /nix/var/nix/profiles/per-user/emily/profile
emily@yuyuko ~> ls -l /nix/var/nix/profiles/per-user/emily/profile
ls: /nix/var/nix/profiles/per-user/emily/profile: No such file or directory

I'm not sure what a reliable way to detect a flakes setup is, though.

@figsoda
Copy link
Member

figsoda commented Jun 15, 2023

Would it make more sense if command-not-found.sh looks at the enabled experimental features instead?

@emilazy
Copy link
Author

emilazy commented Jun 16, 2023

Maybe; I can see people using e.g. https://github.com/DeterminateSystems/nix-installer with a conventional non-flakes setup and getting unexpected results because of the defaulted-on experimental feature. Not sure if that's worth worrying about though. Is there an easy way to check the experimental features without trying to parse nix.conf?

@bennofs
Copy link
Collaborator

bennofs commented Jun 16, 2023

One possibility would be to check if "nix registry list" is successful?

@figsoda
Copy link
Member

figsoda commented Jun 16, 2023

we can run nix show-config experimental-features and check if it contains flakes

@bennofs
Copy link
Collaborator

bennofs commented Jun 16, 2023

but that will break if flakes is no longer an experimental feature, right?

@figsoda
Copy link
Member

figsoda commented Jun 16, 2023

yeah that's true, though I'm a bit worried that nix registry list and other flakes commands would try to download/refresh the flake registry and slow down command-not-found

@bennofs
Copy link
Collaborator

bennofs commented Jun 16, 2023

true, so let's check for nix show-config experimental-features and later add a version check if nix ever makes flakes support non-experimental?

@figsoda
Copy link
Member

figsoda commented Jun 16, 2023

sounds good to me, and we can just do a nix --version check once that happens

@emilazy
Copy link
Author

emilazy commented Jun 16, 2023

For what it's worth it seems like nix show-config experimental-features and nix --version are both noticeably kind of slow for me, maybe because they're unconditionally poking the daemon or something:

emily@yuyuko ~> hyperfine --warmup 3 'nix --version' 'nix show-config experimental-features' 'rg experimental-features /etc/nix/nix.conf'
Benchmark 1: nix --version
  Time (mean ± σ):      81.0 ms ±   4.0 ms    [User: 67.0 ms, System: 12.0 ms]
  Range (min … max):    75.6 ms …  90.3 ms    34 runs
 
Benchmark 2: nix show-config experimental-features
  Time (mean ± σ):      78.2 ms ±   4.0 ms    [User: 64.9 ms, System: 11.3 ms]
  Range (min … max):    74.2 ms …  91.3 ms    37 runs
 
Benchmark 3: rg experimental-features /etc/nix/nix.conf
  Time (mean ± σ):       7.5 ms ±   0.8 ms    [User: 4.1 ms, System: 2.2 ms]
  Range (min … max):     5.2 ms …   9.3 ms    255 runs
 
Summary
  rg experimental-features /etc/nix/nix.conf ran
   10.38 ± 1.18 times faster than nix show-config experimental-features
   10.76 ± 1.21 times faster than nix --version

(Though I find command-not-found already a bit too slow for my tastes, so up to you whether that is reason to avoid making it worse or a reason it's not that big of a deal.)

@figsoda figsoda linked a pull request Jun 17, 2023 that will close this issue
4 tasks
@figsoda
Copy link
Member

figsoda commented Jun 17, 2023

Just opened #227 to rewrite command-not-found.sh in rust, hoping to improve a few things including this one

the new flakes detection logic parses the nix config file and looks for flakes in experimental-features and should be able to solve the issue
https://github.com/figsoda/nix-index/blob/0a9ed9273a6283ff79e93cef87b6bca3b1c344e1/src/bin/nix-locate.rs#L163

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

Successfully merging a pull request may close this issue.

3 participants