From d492eab963522f2dcea7bad1016fe6b718ddffed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Thu, 17 Feb 2022 16:06:39 +0100 Subject: [PATCH 2/3] profiles: 'profile-derivation' rejects unsupported packages. Previously user-facing commands would happily start building packages even if they do not support that system. With this change, all the user-facing commands reject unsupported packages without going further. * guix/profiles.scm (profile-derivation): Add #:allow-unsupported-packages?. Define 'check-supported-packages' and honor #:allow-unsupported-packages?. * tests/guix-pack.sh, tests/guix-package.sh, tests/guix-shell.sh: Ensure that unsupported packages are rejected. --- guix/profiles.scm | 22 ++++++++++++++++++++-- tests/guix-pack.sh | 5 ++++- tests/guix-package.sh | 13 ++++++++++++- tests/guix-shell.sh | 5 ++++- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/guix/profiles.scm b/guix/profiles.scm index 9715a769aa..bad9b95519 100644 --- a/guix/profiles.scm +++ b/guix/profiles.scm @@ -33,7 +33,7 @@ (define-module (guix profiles) #:use-module ((guix utils) #:hide (package-name->name+version)) #:use-module ((guix build utils) #:select (package-name->name+version mkdir-p)) - #:use-module ((guix diagnostics) #:select (&fix-hint)) + #:use-module ((guix diagnostics) #:select (&fix-hint formatted-message)) #:use-module (guix i18n) #:use-module (guix records) #:use-module (guix packages) @@ -1860,6 +1860,7 @@ (define* (profile-derivation manifest (name "profile") (hooks %default-profile-hooks) (locales? #t) + (allow-unsupported-packages? #f) (allow-collisions? #f) (relative-symlinks? #f) system target) @@ -1868,7 +1869,9 @@ (define* (profile-derivation manifest the monadic procedures listed in HOOKS--such as an Info 'dir' file, etc. Unless ALLOW-COLLISIONS? is true, a '&profile-collision-error' is raised if entries in MANIFEST collide (for instance if there are two same-name packages -with a different version number.) +with a different version number.) Unless ALLOW-UNSUPPORTED-PACKAGES? is true +or TARGET is set, raise an error if MANIFEST contains a package that does not +support SYSTEM. When LOCALES? is true, the build is performed under a UTF-8 locale; this adds a dependency on the 'glibc-utf8-locales' package. @@ -1878,12 +1881,27 @@ (define* (profile-derivation manifest When TARGET is true, it must be a GNU triplet, and the packages in MANIFEST are cross-built for TARGET." + (define (check-supported-packages system) + ;; Raise an error if a package in MANIFEST does not support SYSTEM. + (map-manifest-entries + (lambda (entry) + + (match (manifest-entry-item entry) + ((? package? package) + (unless (supported-package? package system) + (raise (formatted-message (G_ "package ~a does not support ~a") + (package-full-name package) system)))) + (_ #t))) + manifest)) + (mlet* %store-monad ((system (if system (return system) (current-system))) (target (if target (return target) (current-target-system))) + (ok? -> (or allow-unsupported-packages? target + (check-supported-packages system))) (ok? (if allow-collisions? (return #t) (check-for-collisions manifest system diff --git a/tests/guix-pack.sh b/tests/guix-pack.sh index 0339221ac2..1356a74083 100644 --- a/tests/guix-pack.sh +++ b/tests/guix-pack.sh @@ -1,6 +1,6 @@ # GNU Guix --- Functional package management for GNU # Copyright © 2018 Chris Marusich -# Copyright © 2018, 2019, 2020 Ludovic Courtès +# Copyright © 2018, 2019, 2020, 2022 Ludovic Courtès # # This file is part of GNU Guix. # @@ -36,6 +36,9 @@ export GUIX_BUILD_OPTIONS test_directory="`mktemp -d`" trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT +# Reject unsuppoted packages. +! guix pack intelmetool -s armhf-linux -n + # Compute the derivation of a pack. drv="`guix pack coreutils -d --no-grafts`" guix gc -R "$drv" | grep "`guix build coreutils -d --no-grafts`" diff --git a/tests/guix-package.sh b/tests/guix-package.sh index 92ab565c5b..d1b383d2ad 100644 --- a/tests/guix-package.sh +++ b/tests/guix-package.sh @@ -1,5 +1,5 @@ # GNU Guix --- Functional package management for GNU -# Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès +# Copyright © 2012-2022 Ludovic Courtès # Copyright © 2013 Nikita Karetnikov # # This file is part of GNU Guix. @@ -59,6 +59,17 @@ test -L "$profile" && test -L "$profile-1-link" ! test -f "$profile-2-link" test -f "$profile/bin/guile" +# Unsupported packages cannot be installed. +! guix package -e '(begin (use-modules (guix) (gnu packages base)) (package (inherit sed) (supported-systems (list))))' -n +case $(uname -m) in + x86_64|i[3456]86) + ! guix package -i novena-eeprom -n + break;; + *) + ! guix package -i intelmetool -n + break;; +esac + # Collisions are properly flagged (in this case, 'g-wrap' propagates # guile@2.2, which conflicts with guile@2.0.) ! guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0 diff --git a/tests/guix-shell.sh b/tests/guix-shell.sh index 23ff1c5bcf..6340f90574 100644 --- a/tests/guix-shell.sh +++ b/tests/guix-shell.sh @@ -1,5 +1,5 @@ # GNU Guix --- Functional package management for GNU -# Copyright © 2021 Ludovic Courtès +# Copyright © 2021-2022 Ludovic Courtès # # This file is part of GNU Guix. # @@ -35,6 +35,9 @@ guix shell --bootstrap --pure guile-bootstrap -- guile --version # '--ad-hoc' is a thing of the past. ! guix shell --ad-hoc guile-bootstrap +# Rejecting unsupported packages. +! guix shell -s armhf-linux intelmetool -n + # Ignoring unauthorized files. cat > "$tmpdir/guix.scm" <