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

nix doctor: add command #2394

Merged
merged 8 commits into from Oct 27, 2018
Merged

nix doctor: add command #2394

merged 8 commits into from Oct 27, 2018

Conversation

LnL7
Copy link
Member

@LnL7 LnL7 commented Sep 2, 2018

This command performs a bunch of sanity checks on the nix installation, most of these are not necceceraly a problem but can be very useful when debugging an issue. Most notably a way to detect worker/serve protocol mismatches in various conditions. This also works in combination with --store ssh://host to help debug eg. nix-copy-closure issues like #2383.

TODO: also include the details nix-info generates?

The code probably also needs a bit of cleanup.


$ nix doctor
Store uri: daemon

Warning: multiple versions of nix found in PATH.

  /nix/store/1wgsprdh6lafnqf8iddnm01k9kxvx5xv-nix-2.0.4/bin
  /src/nix/inst/bin

Warning: found profiles outside of /nix/var/nix/profiles.
The generation this profile points to might not have a gcroot and could be
garbage collected, resulting in broken symlinks.

  /tmp/foo/bin

Warning: protocol version of this client does not match the store.
While this is not necessarily a problem it's recommended to keep the client in
sync with the daemon.

Client protocol: 1.21
Store protocol: 1.20

Inspired by the homebrew command, shows a combination of debugging
information and warnings with potential issues with a nix installation.
A protocol mismatch can sometimes cause problems when using specific
features with an older daemon. For example:

Nix 2.0 changed the way files are compied to the store.  The daemon is
backwards compatible and can still handle older clients, however a 1.11
nix-daemon isn't forwards compatible.
The serve protocol used by LegacySSHStore has a different major and
shouldn't be compared to PROTOCOL_VERSION.
It's pretty easy to unintentionally install a second version of nix
into the user profile when using a daemon install.  In this case it
looks like nix was upgraded while the nix-daemon is probably still
unning an older version.
In most cases profiles that are in PATH should have a gcroot.
@grahamc
Copy link
Member

grahamc commented Sep 2, 2018

Warning: found profiles without a gcroot.
The generation this profile points to will be deleted with the next gc, resulting
in broken symlinks.  Make sure your profiles are in /nix/var/nix/profiles.

Maybe provide a way to fix these, too?

@LnL7
Copy link
Member Author

LnL7 commented Sep 2, 2018

I didn't spend a lot of time on the error messages, they can definitively be improved. But I'm not sure if moving the all the <profile> with all of it's <profile>-<gen>-link symlinks and creating a pointer to those (like ~/.nix-profile) is always correct.

Not all store types LegacySSHStore support these operations and it
doesn't really make sense to check those.
bool found = false;
for (auto & i : roots)
if (referrers.find(i.second) != referrers.end())
found = true;
Copy link
Member Author

@LnL7 LnL7 Sep 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to do this? It's slow and can trigger gc unrelated messages.

@copumpkin
Copy link
Member

This is awesome. As the go-to person for "dude my Nix is broken halp" at my company, this will be a godsend for me 😄

@LnL7
Copy link
Member Author

LnL7 commented Sep 2, 2018

Anything else you can think of that would be low hanging fruit to include here?

@copumpkin
Copy link
Member

Not sure how best to implement it, but some way to determine if nix-daemon was started before your changed nix.conf would be pretty neat. I've seen a lot of people get confused because they change a setting in nix.conf and don't realize they need to restart the daemon.

@timokau
Copy link
Member

timokau commented Sep 6, 2018

Would it make sense to merge this with nix-info? That way you could just tell somebody to execute nix doctor and post the results (if they can't fix it themselves based on the report).

@dtzWill
Copy link
Member

dtzWill commented Sep 23, 2018

This is great!! Not sure it should stall on implementing all fixes we can think of, but of course it'd be great to add more as we can.

Thoughts from @NixOS/nix-core ?

Calculating roots seems significantly slower on darwin compared to
linux.  Checking for /profile/ links could show some false positives but
should still catch most issues.
@LnL7
Copy link
Member Author

LnL7 commented Sep 26, 2018

I was thinking of adding some more stuff first, but I guess there's no reason to wait. Especially if this could be included in 2.1 (client only changes). I reimplemented the profile check to use similar logic as upgrade-nix to detect normal profiles, fixing my main annoyance with it.

@tomberek
Copy link
Contributor

Merge?

@edolstra edolstra merged commit ed25753 into NixOS:master Oct 27, 2018
@LnL7 LnL7 deleted the nix-doctor branch October 28, 2018 22:25
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 this pull request may close these issues.

None yet

8 participants