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

darwin-rebuild segfault #467

Closed
zmre opened this issue May 26, 2022 · 4 comments
Closed

darwin-rebuild segfault #467

zmre opened this issue May 26, 2022 · 4 comments

Comments

@zmre
Copy link

zmre commented May 26, 2022

I just did a nix flake update and a darwin-rebuild switch --flake ~/.config/nixpkgs/.#$(hostname -s) --show-trace today -- something I generally do at least once a week, but I'm getting an error:

warning: Git tree '/Users/x/.config/nixpkgs' is dirty
building the system configuration...
warning: Git tree '/Users/x/.config/nixpkgs' is dirty
[25 built, 70 copied (661.4 MiB), 98.0 MiB DL]
/run/current-system/sw/bin/darwin-rebuild: line 159: 96473 Segmentation fault: 11  nix "${flakeFlags[@]}" build "$flake#$flakeAttr.system" "${extraBuildFlags[@]}" "${extraLockFlags[@]}"

I have tracing on, but I don't get any other details on what the error is. Is this a known problem? Any suggestions on how I should troubleshoot? Is it even a darwin-rebuild issue? This is on an M1, but again, things have been working fine for months and nothing has changed since my last successful update except the flake.lock file.

I can experiment with rolling that back and with rebooting, but hoping someone has better suggestions.

@montchr
Copy link
Contributor

montchr commented May 26, 2022

I've run into segfaults unexpectedly before, though I haven't seen that particular error. A couple things I would try:

Try setting nix.useSandbox = false; -- while unfortunate, sandbox mode can be troublesome on darwin. Most recently the segfaults I've run into were fixed by disabling the sandbox. But those were different error messages.

darwin-rebuild switch --flake ~/.config/nixpkgs/.#$(hostname -s) --show-trace

You've indicated that you've run this command before, but I would try simplifying it a little to see if you can rule out any issues with the command itself. The error message alludes to a nix command.

As long as your hostname matches one of the outputs in darwinConfigurations, you probably don't even need the whole #$(hostname -s) part.

Does the following work:

darwin-rebuild switch --flake ~/.config/nixpkgs

If not, what happens if you replace the $(hostname -s) part in your original command with the literal hostname?

@zmre
Copy link
Author

zmre commented May 26, 2022

Thanks for the suggestions. I rebooted, set useSandbox = false, and ran with the simplified command you suggested. Seems it redownloaded and built for awhile and then gave me an almost identical error:

/run/current-system/sw/bin/darwin-rebuild: line 159: 20868 Segmentation fault: 11  nix "${flakeFlags[@]}" build "$flake#$flakeAttr.system" "${extraBuildFlags[@]}" "${extraLockFlags[@]}"

The number after the line number (is that a PID, maybe?) is the only thing that has changed.

I didn't realize that darwin-rebuild was a bash script. Looking at that, line 159 is the end of an if block that looks familiar:

 151 if [ "$action" = switch ] || [ "$action" = build ] || [ "$action" = check ]; then
 152   echo "building the system configuration..." >&2
 153   if [ -z "$flake" ]; then
 154     systemConfig="$(nix-build '<darwin>' "${extraBuildFlags[@]}" -A system)"
 155   else
 156     nix "${flakeFlags[@]}" build "$flake#$flakeAttr.system" "${extraBuildFlags[@]}" "${extraLockFlags[@]}"
 157     systemConfig=$(readlink -f result)
 158   fi
 159 fi

So I'm guessing this is a nix problem and not a darwin-rebuild problem, maybe?

❯ nix --version
nix (Nix) 2.8.1

I'll see if I can figure out the parameters going to Nix to reproduce it more directly. Open to other ideas, too.

@zmre
Copy link
Author

zmre commented Jun 1, 2022

I attempted to rollback (that worked fine, but upgrading from there still gave me a segfault), to reboot, and I tried directly calling nix in various ways to try to get more info. Eventually I started for nix troubleshooting commands and options and I found this:

nix-store --verify --check-contents --repair

I ran that, also updated my flake.lock again with nix flake update and my next try succeeded. Closing this. Hope it helps the next person.

@zmre zmre closed this as completed Jun 1, 2022
@LnL7
Copy link
Owner

LnL7 commented Jul 29, 2023

Oh, thought this was the same issue as the git problem #693

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