Nix SSL path set incorrectly in the daemon on macOS #226
Labels
No labels
Area/build-packaging
Area/cli
Area/evaluator
Area/fetching
Area/flakes
Area/language
Area/profiles
Area/protocol
Area/releng
Area/remote-builds
Area/repl
Area/store
bug
crash 💥
Cross Compilation
devx
docs
Downstream Dependents
E/easy
E/hard
E/help wanted
E/reproducible
E/requires rearchitecture
imported
Needs Langver
OS/Linux
OS/macOS
performance
regression
release-blocker
RFD
stability
Status
blocked
Status
invalid
Status
postponed
Status
wontfix
testing
testing/flakey
ux
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lix-project/lix#226
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
There's a bug in
scripts/nix-profile-daemon.sh.in
(and debatably all the other activation scripts) where on macOS, if you don't for some reason have system certificates in a path matching a Linux distribution (not a default configuration), it will try to find one in the default or user profile, which if you've accidentally misconfigured them without certificates, will then break, as there's no fallback for macOS.It will then set the environment variable to a "random" broken path within the last profile
This is worse than expected for extremely silly reasons.
It turns out that on macOS, the daemon itself never even actually sees
/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
because that file is loaded by (amongst other places that are unused)/etc/bashrc
. Nix's default daemon is launched via non-interactive, non-login/bin/sh
which runs/bin/bash
in compatibility mode on macOS.This means that it will not even see
/etc/profile
in the first place. So we try running it as a login shell right? Well. Not quite enough either. That will process/etc/profile
and it will recognize itself as running under bash with$BASH
being set, and properly source/etc/bashrc
, except, that won't even get to the line that loads the environment for the Lix daemon, because it starts by checking if there's a$PS1
set already as a proxy for "are we running interactively".What a mess. Let's just manually include the proper sourcing of the environment...
Lix looks at
/etc/ssl/certs/ca-certificates.crt
and/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt
by default for thessl-cert-file
option, which it will then override ifNIX_SSL_CERT_FILE
orSSL_CERT_FILE
is defined. So thenix-daemon.sh
script doesn't really matter here. If/etc/ssl/certs/ca-certificates.crt
doesn't exist and all profiles have uninstalledca-certificates
then we don't have certificates to even find regardless of the environment. A proper fix here is to teach Lix to read the system certificates out of the keychain and synthesize a file for itself. Either that or to have Lix itself depend onpkgs.cacert
to use as a fallback path if the system doesn't have any.If we want to get system certs without writing a bunch of keychain code we could run
security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain
to print all the system roots in PEM format.Does this issue mean that all fresh lix macOS installed does not really work? I tried following the instructions from the website and ends up with an installation where I cannot basically do anything:
Output
I did run into this problem: https://github.com/NixOS/nix/issues/2899. Even though I used lix-installer uninstall and manually removed a bunch of stuff from previous installs. I had a bad/broken symlink in
/etc/ssl/certs/ca-certificates.crt
which made it fail.I haven't run a fresh install in ages, my recollection is it sets up the default profile with both lix and
pkgs.cacert
, and that default profile is how it should find the certs. If you have a broken/etc/ssl/certs/ca-certificates.crt
symlink though that will certainly break things. Perhaps we should detect the broken link when looking for certs?I filed #560 about the broken symlink.