all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob d3913f3efd361fdcc976b20b0eeb88892d2bed29 7762 bytes (raw)
name: website/posts/guix-packager.md 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
 
title: Write package definitions in a breeze
author: Ludovic Courtès, Philippe Virouleau
tags: Scheme API, Programming interfaces
date: 2023-11-25 14:00
---

More than 28,000 packages available in Guix today, not counting
third-party channels.  That’s a lot—the [5th largest GNU/Linux
distro](https://repology.org/)!  But it’s nothing if the one package you
care about is missing.  So even you, dear reader, may one day find
yourself defining a package for your beloved deployment tool.  This post
introduces a new tool poised to significantly lower the barrier to
writing new packages.

# Introducing Guix Packager

[Defining
packages](https://guix.gnu.org/manual/devel/en/html_node/Defining-Packages.html)
for Guix is not all that hard but, as always, it’s much harder the first
time you do it, especially when starting from a blank page and/or not
being familiar with the programming environment of Guix.  [Guix
Packager](https://guix-hpc.gitlabpages.inria.fr/guix-packager/) is a new
web user interface to get you started—[try
it!](https://guix-hpc.gitlabpages.inria.fr/guix-packager/).  It arrived
right in time as an aid to the [packaging
tutorial](https://hpc.guix.info/events/2023/workshop/program/#how-to-get-started-writing-guix-packages)
given last week at the Workshop on Reproducible Software Environments.

![Screenshot showing the Guix Packager interface.](/static/blog/img/guix-packager.gif)

The interface is largely self-describing: you fill in forms on the left
and it produces a valid, ready-to-use package definition on the right.
Importantly, it lets you avoid pitfalls that trip up every newcomer:

  - When you add a dependency in one of the “Inputs” fields, it adds the
    right variable name in the generated code *and* imports the right
    [package
    module](https://guix.gnu.org/manual/devel/en/html_node/Package-Modules.html).
  - Likewise, you can choose a license and be sure the `license` field
    will refer to the right variable representing that license.
  - You can change things like turning tests on and off and adding
    configure flags.  These translate to a valid `arguments` field of
    your package, letting you discover the likes of [keyword
    arguments](https://guix.gnu.org/cookbook/en/html_node/A-Scheme-Crash-Course.html)
    and
    [G-expressions](https://guix.gnu.org/manual/en/html_node/G_002dExpressions.html)
    without having to first dive into the manual.

Pretty cool, no?

# Implementation

All the credit for this tool goes to co-worker and intrepid hacker
Philippe Virouleau.  A unique combination of paren aversion and web
development superpowers—unique in the Guix community that is—led
Philippe to develop the whole thing in a glimpse (says Ludovic!).

The purpose was to provide a single view to be able to edit a package recipe,
therefore the application is a basic *single-page application* (SPA) written in
using the UI library Philippe is most comfortable with: [React](https://react.dev/),
and [MaterialUI](https://mui.com/material-ui/) for styling the components.
It's built with [TypeScript](https://www.typescriptlang.org/), and the library
part actually defines all the types needed to manipulate Guix packages and their
components (such as build systems or package sources).
One of the challenging parts was to be able to provide decent “search as you
type” inputs over the 25k+ packages. It required a combination of using
MaterialUI's [virtualized inputs](https://mui.com/material-ui/react-autocomplete/#virtualization),
as well as caching the packages data in the browser's local storage,
when possible (packaging metadata itself is fetched from
`https://guix.gnu.org/packages.json`, a generic representation of the
current package set).

While the feature set should be enough for what the tool is
intended—providing a decent starting point—, there are still a few
things that may be worth implementing.  For instance, only the GNU and
CMake build systems are supported so far; it would make sense to include
a few others (Python-related ones might be good candidates).

Running a local (development) version of the application can happen on
top of Guix, since—obviously—it's been developped with the `node`
version packaged in Guix, using the quite standard `packages.json` for
JavaScript dependencies installed through `npm`.  [Contributions
welcome!](https://gitlab.inria.fr/guix-hpc/guix-packager/)

# Lowering the barrier to entry

This neat tool complements a set of steps we’ve taken over time to make
packaging in Guix approachable.  Indeed, while package definitions are
actually code written in the Scheme language, the `package` “language”
was designed [from the get-go](https://arxiv.org/abs/1305.4584) to be
fully declarative—think JSON with parens instead of curly braces and
semicolons.  More recently we [simplified the way package inputs are
specified](https://guix.gnu.org/en/blog/2021/the-big-change/) with an
eye on making package definitions less intimidating.

The [`guix import`
command](https://guix.gnu.org/manual/devel/en/html_node/Invoking-guix-import.html)
also exists to make it easier to simplify packaging: it can generate a
package definition for anything that exists in other package
repositories such as PyPI, CRAN, Crates.io, and so forth.  If your
preference goes to curly braces rather than parens, it can also [convert
a JSON package
description](https://guix.gnu.org/manual/devel/en/html_node/Invoking-guix-import.html#index-JSON_002c-import)
to Scheme code.  Once you have your first `.scm` file, `guix build`
print hints for common errors such missing module imports (those
`#:use-module` stanzas).  We also put effort into providing [reference
documentation](https://guix.gnu.org/manual/devel/en/html_node/Defining-Packages.html),
a [video
tutorial](https://guix.gnu.org/en/videos/2020/packaging-part-two/), and
a [tutorial for more complex
packages](https://guix.gnu.org/cookbook/en/html_node/Packaging-Tutorial.html).

Those syntactic issues matter because that’s the first thing new
packagers encounter.  But really, what makes packaging truly
approachable in Guix for anyone who’s tried other packaging tools before
(apart from Nix!) is *predictability*.  If `guix build my-package` works
on your laptop, it’ll work everywhere else; if it fails, it will also
fail elsewhere in the same way.  If the [continuous integration
platform](https://ci.guix.gnu.org) built the package, then a local build
can be
[*substituted*](https://guix.gnu.org/manual/en/html_node/Substitutes.html)
by the binary artifact downloaded from the platform.  These concrete and
underrated aspects of reproducible, isolated builds, make for a much
nicer packaging experience.

Do share your experience [with us](https://guix.gnu.org/contact) and
until then, happy packaging!

#### About GNU Guix

[GNU Guix](https://guix.gnu.org) is a transactional package manager and
an advanced distribution of the GNU system that [respects user
freedom](https://www.gnu.org/distros/free-system-distribution-guidelines.html).
Guix can be used on top of any system running the Hurd or the Linux
kernel, or it can be used as a standalone operating system distribution
for i686, x86_64, ARMv7, AArch64 and POWER9 machines.

In addition to standard package management features, Guix supports
transactional upgrades and roll-backs, unprivileged package management,
per-user profiles, and garbage collection.  When used as a standalone
GNU/Linux distribution, Guix offers a declarative, stateless approach to
operating system configuration management.  Guix is highly customizable
and hackable through [Guile](https://www.gnu.org/software/guile)
programming interfaces and extensions to the
[Scheme](http://schemers.org) language.

debug log:

solving d3913f3 ...
found d3913f3 in https://yhetil.org/guix/20231121141128.11329-1-ludo@gnu.org/

applying [1/1] https://yhetil.org/guix/20231121141128.11329-1-ludo@gnu.org/
diff --git a/website/posts/guix-packager.md b/website/posts/guix-packager.md
new file mode 100644
index 0000000..d3913f3

Checking patch website/posts/guix-packager.md...
Applied patch website/posts/guix-packager.md cleanly.

index at:
100644 d3913f3efd361fdcc976b20b0eeb88892d2bed29	website/posts/guix-packager.md

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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.