Skip to content

python3Packages.certifi: use system certificate bundle - #589174

Open
Skyb0rg007 wants to merge 2 commits into
NixOS:stagingfrom
Skyb0rg007:no-cacert-dep
Open

Skyb0rg007 wants to merge 2 commits into
NixOS:stagingfrom
Skyb0rg007:no-cacert-dep

Conversation

@Skyb0rg007

@Skyb0rg007 Skyb0rg007 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

This removes certifi's dependency on the Nix store cacert package, instead looking at the path specified in the NIX_SSL_CERT_FILE environment variable, the /etc/ssl/certs/ca-certificates.crt file, or a short list of other common system CA bundle locations.

Instead of using a patch file, the entire core.py file is replaced. The simplifications are safe to perform; the rewrite is modeled after Debian's certifi patch.

This is an important step to removing the cacert package from nixpkgs packages' runtime closures. The currently trusted CA certificates are a property of a running system: embedding them into the derivation doesn't improve purity, it just makes it harder to be secure. Instead, the cacert package should be listed as a nativeCheckInput when needed. While #578494 is a partial solution to this problem, nixpkgs packages should not rely on an environment variable being set to not be insecure.

Related to #8247

A warning: the treewide commit is not complete - there will likely need to be follow-up fixes for other leaf packages that depend on certifi. The treewide commit here only covers the derivations with the most number of nixpkgs rebuilds.

Things done

nixpkgs-branch-check[bot]

This comment was marked as outdated.

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 6.topic: python Python is a high-level, general-purpose programming language. labels Nov 16, 2026
@Skyb0rg007
Skyb0rg007 changed the base branch from master to staging November 16, 2026 21:19
@nixpkgs-ci nixpkgs-ci Bot closed this Nov 16, 2026
@nixpkgs-ci nixpkgs-ci Bot reopened this Nov 16, 2026
@Skyb0rg007 Skyb0rg007 mentioned this pull request Nov 16, 2026
3 of 13 tasks
@nixpkgs-branch-check
nixpkgs-branch-check Bot dismissed their stale review November 16, 2026 21:26

Review dismissed automatically

@Skyb0rg007
Skyb0rg007 marked this pull request as ready for review November 19, 2026 02:40
@nixpkgs-ci nixpkgs-ci Bot added 9.needs: reviewer This PR currently has no reviewers requested and needs attention. 6.topic: jupyter Interactive computing tooling: kernels, notebook, jupyterlab labels Nov 19, 2026
The certifi.where() function now uses the $NIX_SSL_CERT_FILE environment
variable, falling back to a list of common system locations. This
removes cacert from the runtime closure of the package.
python3Packages.certifi doesn't have cacert in propagagedBuildInputs, so
dependencies that need access to CA certificates inside the sandbox
(often for tests) now need to add cacert to nativeCheckInputs.
Comment on lines -28 to +25
# Use our system-wide ca-bundle instead of the bundled one
rm -v "certifi/cacert.pem"
ln -snvf "${cacert}/etc/ssl/certs/ca-bundle.crt" "certifi/cacert.pem"
rm -v certifi/{core.py,cacert.pem}
cp "${./core.py}" "certifi/core.py"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So the original code already replaced the certificate bundle with the system one. Am I misunderstanding something, or is this just achieving the same thing with a bigger diff?

@Skyb0rg007 Skyb0rg007 Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's making sure we use the cacert that's a part of the running system. This means nix run some-old-flake#python3Packages.somepkg https://example.com would use the up-to-date certificates in /etc instead of the out-of-date certificates in the runtime closure.

This ensures future eMudhra-style events don't make nix packages insecure, as the package will always delegate the certificate bundle to the system

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No, I understand the intent, but the original code already replaced certifi/cacert.pem with a symlink to the CA bundle in the cacert package. The only difference I see here is that if the NIX_SSL_CERT_FILE is not set, your change makes certifi fall back to the system certificate bundle, which seems less secure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the original code already replaced certifi/cacert.pem with a symlink to the CA bundle in the cacert package.

Which is less secure.

For example, a project might include a shell.nix which pins project dependencies. If that project uses certifi to download files, then any certificate changes the system administrator tries to enforce are moot: the packages will use the cacert from the pinned nixpkgs (which may include certificates the admin doesn't want to trust like eMudhra or doesn't include their own certificates that they want to trust for their own personal domains).

@nixpkgs-ci nixpkgs-ci Bot removed the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: jupyter Interactive computing tooling: kernels, notebook, jupyterlab 6.topic: python Python is a high-level, general-purpose programming language. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants