all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Skyler Ferris <skyvine@protonmail.com>
To: Rodrigo Morales <moralesrodrigo1100@gmail.com>, help-guix@gnu.org
Subject: Re: Let's share examples of simplistic and useless package definitions
Date: Sun, 28 May 2023 19:40:40 +0000	[thread overview]
Message-ID: <82625bf4-3fe0-d56d-e8ed-ec9d2e1fb82b@protonmail.com> (raw)
In-Reply-To: <CAGxMbPZN21Skh9QvTH2Y=XnEVyNo34pXEnRBb=mYwiiC0c6H8A@mail.gmail.com>

Hi Rodrigo! In a topic adjacent to your second question, I wanted to share
something that I recently learned about using local-file in package 
definitions.
I ran through a similar exercise when building a package that largely 
consisted
of local file, and came upon a similar solution of adding local-file 
forms to the
source field. However, I ran into an issue when including multiple local 
files,
because the name that the build code looks up is just an underscore by 
default
(I do not remember for sure how it handles multiple local files, I think 
it was just
adding an extra underscore for each new file). This is fine with just 
one file as in
your example, but is not particularly readable when you're working with 
multiple
files. The names can be set explicitly, but this syntax is deprecated (see
https://guix.gnu.org/blog/2021/the-big-change/ for a detailed discussion 
of this,
if you aren't already familiar). And unfortunately, you can't mix the 
two syntaxes;
that is, if you are writing a more complex package with both local files and
normal package inputs, you would have to write the normal package inputs
using the deprecated syntax as well, or accept the underscore names.

However, after digging through some upstream package definitions, I learned
that there is an idiom to solve this: there is actually no need to 
include the local
files in the source field, you can include them directly in the build 
definition using
g-expressions!  Written with this idiom, a simple package that just 
copies a file
would look like this:

,---
| (use-modules
|     (guix build-system trivial)
|     (guix gexp)
|     (guix packages)
|     )
|
| (package
|     (name        "copy-file-using-gexp")
|     (version     "0.1")
|     (home-page   #f)
|     (synopsis    #f)
|     (description #f)
|     (license     #f)
|     (source      #f)
|
|     (build-system trivial-build-system)
|     ; NOTE: arguments is now a plain list instead of a quoted list
|     (arguments (list
|         #:modules '((guix build utils))
|         ; NOTE: builder is now defined inside of a gexp, indicated by 
the #~
|         #:builder #~(begin
|             (use-modules (guix build utils))
|
|             (let* ((dir  (string-append %output "/share"))
|                    (file (string-append dir "/foo.txt")))
|                 (mkdir-p dir)
|                 ; NOTE: the local file is now included inline as an 
ungexp'd
|                 ;       form, indicated by the #$
|                 (copy-file #$(local-file "/tmp/foo.txt") file))))))
`---

I hope this was helpful and/or interesting!
- Skyler



      reply	other threads:[~2023-05-28 19:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-26 18:59 Let's share examples of simplistic and useless package definitions Rodrigo Morales
2023-05-28 19:40 ` Skyler Ferris [this message]

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=82625bf4-3fe0-d56d-e8ed-ec9d2e1fb82b@protonmail.com \
    --to=skyvine@protonmail.com \
    --cc=help-guix@gnu.org \
    --cc=moralesrodrigo1100@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.