diff options
| author | Efraim Flashner <efraim@flashner.co.il> | 2023-11-28 12:35:48 +0200 |
|---|---|---|
| committer | Efraim Flashner <efraim@flashner.co.il> | 2024-04-07 14:51:04 +0300 |
| commit | 0fa6ba879af5625a3220f94fd699d5fae9e999d4 (patch) | |
| tree | 1f3c4d126d35e858d1498a803b39f0f5abffc4b7 /gnu/packages/python.scm | |
| parent | eae83f64ef1d30e8076bbbd71dac54257e8bb992 (diff) | |
gnu: python: Use system SSL certificates.
* gnu/packages/python.scm (python)[replacement]: New field.
(python/fixed): Provide a python with a patched python-certifi which
only offers to use the system's SSL certificates.
Change-Id: Ic5bcfb6b32282a7e0628232b1dc4cd60f3f2da52
Diffstat (limited to 'gnu/packages/python.scm')
| -rw-r--r-- | gnu/packages/python.scm | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 12a5148cb1b..5df25ac1652 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm | |||
| @@ -14,7 +14,7 @@ | |||
| 14 | ;;; Copyright © 2015, 2016, 2017, 2021 Leo Famulari <leo@famulari.name> | 14 | ;;; Copyright © 2015, 2016, 2017, 2021 Leo Famulari <leo@famulari.name> |
| 15 | ;;; Copyright © 2015, 2017 Ben Woodcroft <donttrustben@gmail.com> | 15 | ;;; Copyright © 2015, 2017 Ben Woodcroft <donttrustben@gmail.com> |
| 16 | ;;; Copyright © 2015, 2016 Erik Edrosa <erik.edrosa@gmail.com> | 16 | ;;; Copyright © 2015, 2016 Erik Edrosa <erik.edrosa@gmail.com> |
| 17 | ;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Efraim Flashner <efraim@flashner.co.il> | 17 | ;;; Copyright © 2015-2020, 2023 Efraim Flashner <efraim@flashner.co.il> |
| 18 | ;;; Copyright © 2015, 2017 Kyle Meyer <kyle@kyleam.com> | 18 | ;;; Copyright © 2015, 2017 Kyle Meyer <kyle@kyleam.com> |
| 19 | ;;; Copyright © 2015, 2016 Chris Marusich <cmmarusich@gmail.com> | 19 | ;;; Copyright © 2015, 2016 Chris Marusich <cmmarusich@gmail.com> |
| 20 | ;;; Copyright © 2016 Danny Milosavljevic <dannym+a@scratchpost.org> | 20 | ;;; Copyright © 2016 Danny Milosavljevic <dannym+a@scratchpost.org> |
| @@ -96,6 +96,7 @@ | |||
| 96 | #:use-module (guix gexp) | 96 | #:use-module (guix gexp) |
| 97 | #:use-module (guix packages) | 97 | #:use-module (guix packages) |
| 98 | #:use-module (guix download) | 98 | #:use-module (guix download) |
| 99 | #:use-module (guix search-paths) | ||
| 99 | #:use-module (guix utils) | 100 | #:use-module (guix utils) |
| 100 | #:use-module (guix build-system gnu) | 101 | #:use-module (guix build-system gnu) |
| 101 | #:use-module (guix build-system trivial) | 102 | #:use-module (guix build-system trivial) |
| @@ -424,6 +425,7 @@ data types.") | |||
| 424 | (inherit python-2) | 425 | (inherit python-2) |
| 425 | (name "python") | 426 | (name "python") |
| 426 | (version "3.10.7") | 427 | (version "3.10.7") |
| 428 | (replacement python-3.10/fixed) | ||
| 427 | (source (origin | 429 | (source (origin |
| 428 | (method url-fetch) | 430 | (method url-fetch) |
| 429 | (uri (string-append "https://www.python.org/ftp/python/" | 431 | (uri (string-append "https://www.python.org/ftp/python/" |
| @@ -982,6 +984,80 @@ data types.") | |||
| 982 | (properties '((cpe-name . "python"))) | 984 | (properties '((cpe-name . "python"))) |
| 983 | (license license:psfl))) | 985 | (license license:psfl))) |
| 984 | 986 | ||
| 987 | (define python-3.10/fixed | ||
| 988 | (package | ||
| 989 | (inherit python-3.10) | ||
| 990 | (arguments | ||
| 991 | (substitute-keyword-arguments (package-arguments python-3.10) | ||
| 992 | ((#:phases phases) | ||
| 993 | #~(modify-phases #$phases | ||
| 994 | ;; Also remove the bundled CA certificates. | ||
| 995 | ;; TODO: Rename this phase when merging back into python. | ||
| 996 | (replace 'remove-windows-binaries | ||
| 997 | (lambda _ | ||
| 998 | ;; Delete .exe from embedded .whl (zip) files | ||
| 999 | (for-each | ||
| 1000 | (lambda (whl) | ||
| 1001 | (let ((dir "whl-content") | ||
| 1002 | (circa-1980 (* 10 366 24 60 60))) | ||
| 1003 | (mkdir-p dir) | ||
| 1004 | (with-directory-excursion dir | ||
| 1005 | (let ((whl (string-append "../" whl))) | ||
| 1006 | (invoke "unzip" whl) | ||
| 1007 | (for-each delete-file | ||
| 1008 | (find-files "." "\\.exe$")) | ||
| 1009 | (delete-file whl) | ||
| 1010 | |||
| 1011 | ;; Search for cacert.pem, delete it, and rewrite the | ||
| 1012 | ;; file which directs python to look for it. | ||
| 1013 | (let ((cacert (find-files "." "cacert\\.pem"))) | ||
| 1014 | (unless (null? cacert) | ||
| 1015 | (let ((certifi (dirname (car cacert)))) | ||
| 1016 | (delete-file (string-append certifi "/cacert.pem")) | ||
| 1017 | (delete-file (string-append certifi "/core.py")) | ||
| 1018 | (with-output-to-file (string-append certifi "/core.py") | ||
| 1019 | (lambda _ | ||
| 1020 | (display "\"\"\" | ||
| 1021 | certifi.py | ||
| 1022 | ~~~~~~~~~~ | ||
| 1023 | This file is a Guix-specific version of core.py. | ||
| 1024 | |||
| 1025 | This module returns the installation location of SSL_CERT_FILE or | ||
| 1026 | /etc/ssl/certs/ca-certificates.crt, or its contents. | ||
| 1027 | \"\"\" | ||
| 1028 | import os | ||
| 1029 | |||
| 1030 | _CA_CERTS = None | ||
| 1031 | |||
| 1032 | try: | ||
| 1033 | _CA_CERTS = os.environ [\"SSL_CERT_FILE\"] | ||
| 1034 | except: | ||
| 1035 | _CA_CERTS = os.path.join(\"/etc\", \"ssl\", \"certs\", \"ca-certificates.crt\") | ||
| 1036 | |||
| 1037 | def where() -> str: | ||
| 1038 | return _CA_CERTS | ||
| 1039 | |||
| 1040 | def contents() -> str: | ||
| 1041 | with open(where(), \"r\", encoding=\"ascii\") as data: | ||
| 1042 | return data.read()")))))) | ||
| 1043 | |||
| 1044 | ;; Reset timestamps to prevent them from ending | ||
| 1045 | ;; up in the Zip archive. | ||
| 1046 | (ftw "." (lambda (file stat flag) | ||
| 1047 | (utime file circa-1980 circa-1980) | ||
| 1048 | #t)) | ||
| 1049 | (apply invoke "zip" "-X" whl | ||
| 1050 | (find-files "." #:directories? #t)))) | ||
| 1051 | (delete-file-recursively dir))) | ||
| 1052 | (find-files "Lib/ensurepip" "\\.whl$")))))))) | ||
| 1053 | (native-search-paths | ||
| 1054 | (list (guix-pythonpath-search-path (package-version python-3.10)) | ||
| 1055 | $SSL_CERT_FILE | ||
| 1056 | ;; Used to locate tzdata by the zoneinfo module introduced in | ||
| 1057 | ;; Python 3.9. | ||
| 1058 | (search-path-specification | ||
| 1059 | (variable "PYTHONTZPATH") | ||
| 1060 | (files (list "share/zoneinfo"))))))) | ||
| 985 | 1061 | ||
| 986 | ;; Next 3.x version. | 1062 | ;; Next 3.x version. |
| 987 | (define-public python-next python-3.12) | 1063 | (define-public python-next python-3.12) |
