I think I’ve been seeing (and trying to figure out) the same thing for the last few days. We’ve been talking about it a little in the “Nix on macOS” room on Matrix.
It seems like it’s only segfaulting when I do something with a traditional CLI tool that needs to realize a store path. (The new/experimental CLI doesn’t segfault, and the traditional CLI is fine as long as it doesn’t need to realize something.)
Do you see roughly what I see if you try a sequence like below?
Not certain why we aren’t seeing quite the same behavior. I have flaked my system and removed my channels, so I guess maybe both of my invocations are pointing to the same nixpkgs rev while yours may be pointing to different ones.
I do still think it smells like the ~same segfault.
Here’s what I see when I use --verbose (though I’m changing up the package since I now have both cowsay and nix-info in my store and don’t want to gc atm…):
$ nix-shell -p hello --run "hello heh" --verbose
... stuff in nixpkgs ...
evaluating file '/Users/abathur/.config/nixpkgs/overlays/overrides.nix'
evaluating file '/Users/abathur/.config/nixpkgs/overlays/packages.nix'
... stuff in nixpkgs ...
evaluating file '/Users/abathur/.config/nixpkgs/config.nix'
... stuff in nixpkgs ...
evaluating file '/nix/store/1dklh99pdzxcxmrxz3i63rb3pa832yik-source/pkgs/by-name/he/hello/package.nix'
evaluating file '/nix/store/1dklh99pdzxcxmrxz3i63rb3pa832yik-source/pkgs/stdenv/generic/common-path.nix'
querying info about '/nix/store/67bnnxkgnqcf3id74d4n8ijizxifcjvl-hello-2.12.1' on 'https://cache.nixos.org'...
downloading 'https://cache.nixos.org/67bnnxkgnqcf3id74d4n8ijizxifcjvl.narinfo'...
Segmentation fault: 11
That said, poking at this one disproved my own thesis about this only affecting the traditional commands:
$ nix run --verbose --print-build-logs nixpkgs#hello heh
Segmentation fault: 11
$ nix run -vvvvv nixpkgs#hello heh
acquiring write lock on '/nix/var/nix/temproots/95971'
using cache entry '{"name":"flake-registry.json","type":"file","url":"https://channels.nixos.org/flake-registry.json"}' -> '{"etag":"W/\"5af996fe37b5c4ba47ef9b3d545ba977b527e2dcdc6e926dda7787b7db6bcf6e\"","url":"https://channels.nixos.org/flake-registry.json"}', '/nix/store/5fjljy6g6l4lfdxcb1hjkg4bwrs2kqpx-flake-registry.json'
looked up 'flake:nixpkgs' -> 'path:/nix/store/1dklh99pdzxcxmrxz3i63rb3pa832yik-source?lastModified=1701336116&narHash=sha256-kEmpezCR/FpITc6yMbAh4WrOCiT2zg5pSjnKrq51h5Y%3D&rev=f5c27c6136db4d76c30e533c20517df6864c46ee'
using substituted/cached input 'path:/nix/store/1dklh99pdzxcxmrxz3i63rb3pa832yik-source?lastModified=1701336116&narHash=sha256-kEmpezCR/FpITc6yMbAh4WrOCiT2zg5pSjnKrq51h5Y%3D&rev=f5c27c6136db4d76c30e533c20517df6864c46ee' in '/nix/store/1dklh99pdzxcxmrxz3i63rb3pa832yik-source'
got tree '/nix/store/1dklh99pdzxcxmrxz3i63rb3pa832yik-source' from 'path:/nix/store/1dklh99pdzxcxmrxz3i63rb3pa832yik-source?lastModified=1701336116&narHash=sha256-kEmpezCR/FpITc6yMbAh4WrOCiT2zg5pSjnKrq51h5Y%3D&rev=f5c27c6136db4d76c30e533c20517df6864c46ee'
checking access to '/nix/store/1dklh99pdzxcxmrxz3i63rb3pa832yik-source/flake.nix'
evaluating file '/nix/store/1dklh99pdzxcxmrxz3i63rb3pa832yik-source/flake.nix'
old lock file: {
"nodes": {
"root": {}
},
"root": "root",
"version": 7
}
computing lock file node ''
new lock file: {
"nodes": {
"root": {}
},
"root": "root",
"version": 7
}
trying flake output attribute 'apps.x86_64-darwin.hello'
using cached attrset attribute ''
trying flake output attribute 'packages.x86_64-darwin.hello'
using cached attrset attribute ''
trying flake output attribute 'legacyPackages.x86_64-darwin.hello'
trying flake output attribute 'hello'
using cached attrset attribute ''
using cached string attribute 'legacyPackages.x86_64-darwin.hello.type'
using cached string attribute 'legacyPackages.x86_64-darwin.hello.drvPath'
using cached string attribute 'legacyPackages.x86_64-darwin.hello.outPath'
using cached string attribute 'legacyPackages.x86_64-darwin.hello.outputName'
using cached string attribute 'legacyPackages.x86_64-darwin.hello.name'
using cached string attribute 'legacyPackages.x86_64-darwin.hello.meta.mainProgram'
querying info about missing paths...
starting pool of 24 threads
checking substituter 'https://cache.nixos.org' for path '/nix/store/67bnnxkgnqcf3id74d4n8ijizxifcjvl-hello-2.12.1'
checking substituter 'https://cache.nixos.org' for path '/nix/store/67bnnxkgnqcf3id74d4n8ijizxifcjvl-hello-2.12.1'
Segmentation fault: 11
Discussion on Matrix (mostly others reporting not having this problem) is making me think this might be hinging on macOS version. We’re both using 10.15.7, and I’ve also been able to confirm similar behavior on an old 10.14.6 system.
This may also have something to do with the recent stdenv bump to LLVM 16.
I don’t see the segfault with a pre-2.19 build of Nix that uses libcxx-11.1.0, while I do see segfaults with a more recent build of Nix 2.18.1 that uses libcxx-16.0.6.
I poked at this a bit this weekend and have a better sense of where it’s failing and even a workaround for at least one case.
The segfaults appear to happen when printMissing tries to printMsg the float document/NAR sizes here:
We only end up on this code path when print-missing is true (though this is the default):
So, if you invoke with --option print-missing false, it should at least work for now. This segfault occurs before the --dry-run flag takes effect, so you can use it to help confirm the segfault/no-segfault behavior here without realizing whatever test package you’re using.
Without the flag, nix-shell is working in my system only if the derivation is not available locally, and it has to be downloaded (so the first time). At the second run, I have a segfault. Adding the option, nix-shell continues working after the first invocation.
@aaronpkelly I’m not sure if you can un-mark the solution, but it might be useful to leave this ~open so that it’s easier for others to find and interact with until we see if we can get a more proper fix here (whether in Nix or Nixpkgs).
I’ve been successfully using nix-shell --option print-missing false as a work around. But now I’m trying to upgrade nix per this https://nixos.org/manual/nix/stable/installation/upgrading
and getting a segfault running sudo nix-env --install --file '<nixpkgs>' --attr nix -I nixpkgs=channel:nixpkgs-unstable
Adding --option print-missing false to it doesn’t work either.
Is there any way to work around this segfault, so that a newer nixpkgs can be used?