From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pierre Neidhardt Subject: Re: Parameterized packages Date: Mon, 20 Jan 2020 19:57:30 +0100 Message-ID: <875zh6rm5h.fsf@ambrevar.xyz> References: <8736ldq74z.fsf@netris.org> <20190719202906.lbanx5puk7t6q4cr@cf0> <87a7753boq.fsf@ambrevar.xyz> <87h813wah0.fsf@gnu.org> <87v9piut40.fsf@ambrevar.xyz> <87o8v5ukgb.fsf@ambrevar.xyz> <87d0blhr9s.fsf@ambrevar.xyz> <20200116190644.uytvzvypuvdwh2iq@n0> <87d0bfrxr1.fsf@gnu.org> <87tv4qjy06.fsf@ambrevar.xyz> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:32874) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itcEz-00054n-6i for guix-devel@gnu.org; Mon, 20 Jan 2020 13:57:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itcEx-0003pB-8w for guix-devel@gnu.org; Mon, 20 Jan 2020 13:57:36 -0500 In-Reply-To: List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane-mx.org@gnu.org Sender: "Guix-devel" To: zimoun Cc: Guix Devel --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable zimoun writes: > What is the final aim to have parametrized packages? > What does it mean "parametrized"? Easy and composable customization of packages. > Does it mean extend the transformation options as Ludo described [2]. I think you forgot this reference. If you meant "like Ludo described in the original post" I'd say yes, more or less that. > Could you define what do you mean by "parameters"? > Sorry to be slow but I am not clear about what we are talking about > precisely. :-) No problem. "Parameters" is a term Ludo came up with, I believe. We can always change the naming later. In my understanding, a parameter is a "first class, globally defined object -- that comes with a description and a type -- which value can be used as condition in a package to modify its output. A package may rely on multiple parameters to modify its output." > 1. Because the initial Ludo's message was about glic-locale which is > somehow an input. Yes, but in my opinion the example just happened to be an input modification, it does not have to be. Gentoo USE flags don't only change the dependencies, they also change the compilation options, etc. > 2. The thread spoke also about flags =C3=A0 la Gentoo USE flags. Indeed, they are essentially the same, but recent discussions are leading towards limiting Guix parameters a bit more to avoid a combinatorial explosion in the maintenance complexity. > 3. Other messages were about set X or Wayland or no-X for this or that pa= ckage. Just like Gentoo "X" USE flag I think. > 4. Another were about change the toolchain of the build systems. > etc. In my opinion, we don't need to change anything in the build system. The point is that parameters can be used anywhere in the package definition, and thus it can change #:arguments fields like #:python to customize the python builder. > All are "parameters". :-) > > The solution of 1. and 4. seems to be able to re-write all the implicit i= nputs. As Ison mentioned, this might not be reasonable because it might just break too often. A better approach could be to only customize the direct inputs (and build system options). > The solution of 2. and 3. seems to write, as Ludo mentioned: > > --8<---------------cut here---------------start------------->8--- > (define (make-me-a-package option1 option2) > (package > =E2=80=A6)) > --8<---------------cut here---------------end--------------->8--- The ellipsis is a bit vague here. What is this trying to do? > Well, could you clarify what do you have in mind about "parameters"? > Just to stay on the wavelength and keep focus. :-) OK, I'll try with one full example: =2D-8<---------------cut here---------------start------------->8--- (define-public you-get (package (name "you-get") (version "0.4.1355") (PARAMETERS VIDEO-PLAYER PYTHON-VERSION WITH-FFMPEG) (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/soimort/you-get.git") (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 (base32 "0xq7z04hvw3b3npiahlpzhbxsjvam9n9dynplyrkn84dx6k9ajbj")))) (build-system python-build-system) (inputs `(("PLAYER" ,(DEREF-PARAM VIDEO-PLAYER)) ,@(IF (DEREF-PARAM WITH-FFMPEG) ;; FOR MULTI-PART AND >=3D1080P VIDEOS `("FFMPEG" ,FFMPEG) '())))=20=20=20=20=20=20=20=20=20=20=20=20=20 (arguments `(#:PYTHON ,(DEREF-PARAM PYTHON-VERSION) #:phases (modify-phases %standard-phases ,(WHEN (DEREF-PARAM WITH-FFMPEG) (add-after 'unpack 'qualify-input-references ;; Explicitly invoke the input ffmpeg, instead of whichever o= ne ;; happens to be in the user's $PATH at run time. (lambda* (#:key inputs #:allow-other-keys) (let ((ffmpeg (string-append (assoc-ref inputs "ffmpeg") "/bin/ffmpeg"))) (substitute* "src/you_get/processor/ffmpeg.py" ;; Don't blindly replace all occurrences of =E2=80=98'f= fmpeg'=E2=80=99: the ;; same string is also used when sniffing ffmpeg's outp= ut. (("(FFMPEG =3D=3D |\\()'ffmpeg'" _ prefix) (string-append prefix "'" ffmpeg "'"))) #t)))) (ADD-AFTER 'UNPACK 'TWEAK-PLAYER-SETTINGS (LAMBDA* (#:KEY INPUTS #:ALLOW-OTHER-KEYS) (MATCH ,(DEREF-PARAM VIDEO-PLAYER) (VLC ;; DO SOMETHING WITH VLC. ) (MPV ;; DO SOMETHING WITH MPV. ) (_ ;; ERROR OUT? ))))) #:tests? #f)) ; XXX some tests need Internet acce= ss (synopsis "Download videos, audio, or images from Web sites") (description "You-Get is a command-line utility to download media contents (videos, audio, images) from the Web. It can use either mpv or vlc for playback.") (home-page "https://you-get.org/") (license license:expat))) =2D-8<---------------cut here---------------end--------------->8--- In the above I've highlighted the changes in uppercase. On line (PARAMETERS ...) I've declared which parameters I'm going to use in my package declaration. Those parameters must be defined globally somewhere in Guix. The point of declaring the parameters in advance is that it allows the user to list all parameters used by a given package. In the above example, parameters are used for various things: =2D To configure the build system, i.e. here to set which python version is going to be used to compile the program. =2D To make the FFmpeg input optional. =2D To let the user choose which video player to use. This is a popular USE flag on Gentoo (maybe with a different name). Does that make more sense now? =2D-=20 Pierre Neidhardt https://ambrevar.xyz/ --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAl4l+BoACgkQm9z0l6S7 zH+WRggAkRO6L2iGXb3FMdioFTKeZYEdVU1N+K0AdFmse+i1GFb9aj3tmGTBYG+f FvtkByWh98CDdSFLmSdiz+yXVUJWmfwLaIRD79oX5PnaRi1Csj+YT1hoqlXU9PfQ yNMqlHdlkhJ3pRkCsuOz1EM7YwfIQmt63/wTU6HBdfIzP1BRL+gibw606aCdlorc l2wd/xKGGZS2xIlpkm9IJVCMoeIH3cpDeSyJvix11uwuEpaEQZzFS2e0J/8/azCM DUdkt/gHSmFhrUgsGLKh+LHSWXZEPRdh3kmvspoS6e2TctdxWhHr7L07Ha6HnqZM bSiny5uiUCVNoF+nW6wkOSS9V1yJlQ== =uRnQ -----END PGP SIGNATURE----- --=-=-=--