all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Pierre Neidhardt <mail@ambrevar.xyz>
To: zimoun <zimon.toutoune@gmail.com>
Cc: Guix Devel <guix-devel@gnu.org>
Subject: Re: Parameterized packages
Date: Mon, 20 Jan 2020 19:57:30 +0100	[thread overview]
Message-ID: <875zh6rm5h.fsf@ambrevar.xyz> (raw)
In-Reply-To: <CAJ3okZ0ZN6UKkUN4=C5gXxmFOq+nSHFMrhTR=+SZCesyVog5Ag@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6182 bytes --]

zimoun <zimon.toutoune@gmail.com> 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 à 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 package.

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 inputs.

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
>       …))
> --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:

--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 >=1080P VIDEOS
             `("FFMPEG" ,FFMPEG)
             '())))             
    (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 one
              ;; 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 ‘'ffmpeg'’: the
                    ;; same string is also used when sniffing ffmpeg's output.
                    (("(FFMPEG == |\\()'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 access
    (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)))
--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:

- To configure the build system, i.e. here to set which python version
  is going to be used to compile the program.

- To make the FFmpeg input optional.

- 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?

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

  reply	other threads:[~2020-01-20 18:57 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-14 11:54 Parameterized packages Ludovic Courtès
2019-05-14 15:17 ` Tobias Geerinckx-Rice
2019-05-17 14:23   ` Pierre Neidhardt
2019-05-17 18:15   ` Mark H Weaver
2019-07-19  5:41     ` Chris Marusich
2019-07-19 20:29     ` ison
2020-01-02 19:23       ` Pierre Neidhardt
2020-01-09 11:10         ` Pierre Neidhardt
2020-01-09 23:13           ` Marius Bakke
2020-01-10 12:29             ` Pierre Neidhardt
2020-01-10 16:19         ` Ludovic Courtès
2020-01-11 11:31           ` Pierre Neidhardt
2020-01-14 15:05             ` zimoun
2020-01-15  9:40               ` Pierre Neidhardt
2020-01-15 11:30                 ` zimoun
2020-01-15 11:51                   ` Pierre Neidhardt
2020-01-15 13:54                     ` zimoun
2020-01-16 19:06                       ` ison
2020-01-16 20:55                         ` Ricardo Wurmus
2020-01-17 16:34                           ` Pierre Neidhardt
2020-01-17  9:15                         ` L p R n d n
2020-01-17 16:46                           ` Pierre Neidhardt
2020-01-17 15:53                         ` zimoun
2020-01-17 16:56                           ` Pierre Neidhardt
2020-01-20 14:34                             ` zimoun
2020-01-21 10:56                             ` Build systems and implicit inputs Ludovic Courtès
2020-01-21 12:24                               ` zimoun
2020-01-21 13:07                                 ` Pierre Neidhardt
2020-01-21 18:02                                   ` zimoun
2020-01-19 20:34                           ` Parameterized packages Ludovic Courtès
2020-01-20  9:08                             ` Pierre Neidhardt
2020-01-20 14:50                               ` zimoun
2020-01-20 18:57                                 ` Pierre Neidhardt [this message]
2020-01-20 19:07                                   ` Pierre Neidhardt
2020-01-20 22:57                                   ` ison
2020-01-21 10:09                                     ` Pierre Neidhardt
2020-01-21 10:49                                     ` Ludovic Courtès
2020-01-21 12:15                                   ` zimoun
2020-01-21 13:13                                     ` Pierre Neidhardt
2020-01-21 19:04                                       ` zimoun
2020-01-22  9:54                                         ` Pierre Neidhardt
2020-01-22 12:23                                           ` zimoun
2020-01-24 21:56                                             ` ison
2020-01-26 19:35                                               ` zimoun
2020-01-27 10:13                                                 ` Pierre Neidhardt
2020-01-27 11:23                                                   ` zimoun
2020-01-27 11:50                                                     ` Pierre Neidhardt
2020-01-27 12:34                                                       ` zimoun
2020-01-27 10:04                                               ` Pierre Neidhardt
2020-01-25 18:52                                             ` John Soo
2020-01-27 10:17                                               ` Pierre Neidhardt
2020-01-20 14:12                             ` zimoun
2020-01-17 16:31                         ` Pierre Neidhardt
     [not found]                         ` <875zhbvzfz.fsf@guixSD.i-did-not-set--mail-host-address--so-tickle-me>
2020-01-17 16:41                           ` Pierre Neidhardt
2020-01-19 20:30                           ` Ludovic Courtès
2020-01-15 11:43                 ` Pierre Neidhardt
2020-01-15 11:44           ` Pierre Neidhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875zh6rm5h.fsf@ambrevar.xyz \
    --to=mail@ambrevar.xyz \
    --cc=guix-devel@gnu.org \
    --cc=zimon.toutoune@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.