+
Perl software in GNU Guix
Hello, my name is Chris, and I'm talking about GNU Guix
and Perl, mostly Guix.
You might know Perl, it's a very established programming
language.
GNU Guix is a more recent project, it started in
2012. It's a package manager, and distribution of the GNU
system.
Through Guix you can...
Get and use Perl
Get and use Perl modules
Get and use tools and applications written in Perl
Perl is an important component for Guix as a package
manager, as many other packages depend on Perl at build
time, or runtime.
It's also something Guix can help you use. If you want to
run Perl, you can use Guix to install it.
Guix also packages some Perl (around 700) modules.
There's also software packaged for Guix that's written in
Perl, and I'll mention a couple of examples.
Getting Perl
→ guix install perl
...
→ perl --version
This is perl 5, version 28, subversion 0 (v5.28.0) built for
x86_64-linux-thread-multi
...
Back to getting Perl though. Installing packages through
Guix is quite simple, you can run the `guix install`
command with the name of the package.
Using Perl modules
→ guix install perl perl-uri
...
→ echo $PERL5LIB
/gnu/store/h3ryiwyhp8qcxyf74sxyv746171zpazr-profile/lib/perl5/site_perl
→ ls /gnu/store/h3r...azr-profile/lib/perl5/site_perl/5.28.0/
URI URI.pm x86_64-linux-thread-multi
Installing Perl with some modules is very similar.
Note here that these modules have to be specifically
packaged for Guix, more about that later.
If you're familiar with other distributions that use a
more standard filesystem hierarchy, Guix isn't like that.
Most things end up in the `/gnu/store` directory. Guix
however, does understand that Perl uses the PERL5LIB
environment variable to find things within the `lib/perl5/site_perl`
directory within packages, so when it creates a profile, a
grouping together of packages, it'll group the Perl
modules together, and include the appropriate value for
the `PERL5LIB` environment variable.
Wiki compiler
Static site generator
I occasionally use it for blogging
On to some software that's written in Perl.
Ikiwiki is a wiki compiler, built around a flexible static
site generator. I personally use it for simple websites
and blogs.
It's written in Perl, and I was using it before I started
using Guix. It was also absent from Guix back then, so I
packaged it, and some of it's missing dependencies.
cbaines pushed a change to branch master
in repository guix.
from 921bb35 gnu: linux-libre@4.9: Fix hash.
new 31d3a7c gnu: Add discount.
new 9d46919 gnu: Add perl-text-markdown-discount.
new 19d81cf gnu: Add perl-test-cpan-meta-json.
new d5b5020 gnu: Add perl-test-cpan-meta.
new b4387d8 gnu: Add perl-devel-cycle.
new 3d74955 gnu: Add perl-test-memory-cycle.
new 8800255 gnu: Add perl-test-notabs.
new 7d1f9c9 gnu: Add perl-test-eol.
new 4f0ee1b gnu: Add perl-html-scrubber.
new 86bd64b gnu: Add perl-yaml-libyaml.
new f0539b6 gnu: Add perl-cgi-session.
new 909dcf5 gnu: Add ikiwiki.
I don't want to spend too much time on this, but I thought
it might be useful to skim over the Guix package
definition for Ikiwiki. It's too long to fit on one slide,
but hopefully this'll give you an idea of what goes in to
a Guix package.
(define-public ikiwiki
(package
(name "ikiwiki" )
(version "3.20190228" )
(source
(origin
(method url-fetch)
(uri (string-append "http://snapshot.debian.org/archive/debian/"
"20190301T035241Z/pool/main/i/ikiwiki/ikiwiki_"
version ".orig.tar.xz" ))
(sha256
(base32
"17pyblaqhkb61lxl63bzndiffism8k859p54k3k4sghclq6lsynh" ))))
...
Packages in Guix are defined through a record type in
Guile scheme. I've only done a little bit of Perl
programming, but I think it has a concept of a record as
well.
So, `define-public ikiwiki` is defining a value called
`ikiwiki`, which is a package.
(next)
Next there are some fields in the package record. The
package has a name, and the version is also specified.
(next)
Then the `source` is defined. This says to fetch something
from a URL. In this case, the Ikiwiki package is a little
odd. Normally this would be a release tarball from the
upstream authors, not the snapshot.debian.org site.
Importantly, the expected hash of the file is also
specified. This means there'll be no surprises, and that
the behaviour will be consistent in to the future.
(define-public ikiwiki
(package
...
(build-system perl-build-system)
(arguments
`(#:phases
(modify-phases %standard-phases
(add-after 'unpack 'include-PERL5LIB-in-wrapper
(lambda _
(substitute* "IkiWiki/Wrapper.pm"
(("^@wrapper\\_hooks" )
(string-append
"@wrapper_hooks\n"
" addenv(\"PERL5LIB\", \""
(getenv "PERL5LIB" )
"\");" )))))
(add-after 'patch-source-shebangs 'patch-Makefile
(lambda _
(substitute* "Makefile.PL"
(("SYSCONFDIR\\?=" ) "SYSCONFDIR?=$(PREFIX)" ))
#t))
(add-after 'install 'wrap-programs
(lambda* (#:key outputs #:allow-other-keys)
(let* ((out (assoc-ref outputs "out" ))
(bin (string-append out "/bin/" ))
(path (getenv "PERL5LIB" )))
(for-each (lambda (file)
(wrap-program file
`("PERL5LIB" ":" prefix (,path))))
(find-files bin))
#t))))))
...
Moving on, each package has a build system. There are
quite a few build systems, each representing common build
steps that apply to multiple packages.
In this case, Ikiwiki uses the perl-build-system. This
will look for files like Build.PL and Makefile.PL, and use
them if they exist.
(next)
The build system can be passed some arguments. Here, some
of the phases of the build process are being tweaked.
(next)
After the `'unpack` phase, there's a small change being
made to the source code. The value of the PERL5LIB
environment variable is being included in a file. This is
so Ikiwiki can find the modules it requires at runtime.
(next)
The Makefile is then patched to have the example
configuration installed. Often this isn't necessary.
Finally, one common step is wrapping the files within the
bin directory with the value of the PERL5LIB environment
variable. This is also to ensure that Ikiwiki can find the
modules it requires at runtime.
(define-public ikiwiki
(package
...
(native-inputs
`(("which" ,which)
("perl-html-tagset" ,perl-html-tagset)
("perl-timedate" ,perl-timedate)
("perl-xml-sax" ,perl-xml-sax)
("perl-xml-simple" ,perl-xml-simple)
("gettext" ,gettext-minimal)
("subversion" ,subversion)
("git" ,git)
("bazaar" ,bazaar)
("cvs" ,cvs)
("mercurial" ,mercurial)))
(inputs
`(("python" ,python-wrapper)
("perl-cgi-formbuilder" ,perl-cgi-formbuilder)
("perl-cgi-session" ,perl-cgi-session)
("perl-cgi-simple" ,perl-cgi-simple)
("perl-db-file" ,perl-db-file)
("perl-html-parser" ,perl-html-parser)
("perl-html-scrubber" ,perl-html-scrubber)
("perl-html-template" ,perl-html-template)
("perl-image-magick" ,perl-image-magick)
("perl-json" ,perl-json)
("perl-text-markdown-discount" ,perl-text-markdown-discount)
("perl-uri" ,perl-uri)
("perl-yaml-libyaml" ,perl-yaml-libyaml)))
...
Next come the inputs to the package.
The terminology comes from the "functional" package
management paradigm that Guix uses. If you consider a
building a package a function, the dependencies are inputs
to that function, and the output of the function is the
built package in the store.
There are multiple types of inputs, native-inputs are
those that are just used at build time. Whereas inputs are
used at runtime, and maybe also when the package is being
built.
The distinction is mostly important when cross compiling,
something which the Perl build system doesn't currently
support as far as I'm aware.
Thinking back to the use of the PERL5LIB environment
variable on the previous slide, these are the modules
which will be mentioned in the value of that environment
variable.
When building a Guix package, the build process takes
place in an isolated environment, with only the store
items that the package and build system explicitly
require, along with their dependnecies.
Guix will ensure that any store item referenced by the
generated outputs exists within the store. Which it's why
it's important for the Ikiwiki package to reference the
modules it requires explicitly.
This is similar to what other package managers do with the
notion of dependencies, except in Guix it's much more
specific and unchanging.
(define-public ikiwiki
(package
...
(home-page "https://ikiwiki.info/" )
(synopsis "Wiki compiler, capable of generating HTML" )
(description
"Ikiwiki is a wiki compiler, capable of generating a static set of web
pages, but also incorporating dynamic features like a web based editor and
commenting." )
(license license:gpl2+)))
Moving on, the last few fields within the package record are some
metadata, the home page, and license for the package, along with a
short synopsis and longer description.
→ guix build ikiwiki
...
/gnu/store/hcrv2cqzbisdb35hg2xmbxp1r2z7ijzd-ikiwiki-3.20190228
With this definition, we can instruct Guix to build the
Ikiwiki package.
Stuff may happen, then you should see the store item that
has been created.
The hash here in the name represents the process that's
gone in to creating this package. Including all the
inputs, the build system and the arguments in the package
definition. Change any of that, the hash will change, and
you'll get a different store item.
/gnu/store/hcrv2cqzbisdb35hg2xmbxp1r2z7ijzd-ikiwiki-3.20190228
├── bin
│ ├── ikiwiki
│ ├── ikiwiki-calendar
│ ├── ikiwiki-comment
│ ├── ikiwiki-makerepo
│ ├── ikiwiki-transition
│ └── ikiwiki-update-wikilist
├── etc
│ └── ikiwiki
│ └── ...
├── lib
│ ├── ikiwiki
│ │ └── ...
│ ├── perl5
│ │ └── ...
│ └── w3m
│ └── cgi-bin
│ └── ikiwiki-w3m.cgi
├── sbin
│ └── ikiwiki-mass-rebuild
└── share
├── ikiwiki
│ └── ...
├── locale
│ └── ...
└── man
├── man1
│ └── ...
└── man8
└── ikiwiki-mass-rebuild.8.gz
While Guix doesn't follow the same filesystem hierachy as
other distributions of GNU, what you find within the store
item for a package might be more familiar. Particularly
the bin, lib and share directories.
(Any questions about Ikiwiki?)
Sensible database change management
Next, I thought I'd mention Sqitch. It's a database change
management tool that I've recently started using.
cbaines pushed a change to branch master
in repository guix.
from 1b7436a gnu: wine-staging: Update to 4.6.
new 41c685f gnu: Add perl-http-tinyish.
new ef9902d gnu: Add perl-config-gitlike.
new 366b76c gnu: Add perl-cpan-distnameinfo.
new 54a5178 gnu: Add perl-tie-handle-offset.
new f73d4b1 gnu: Add perl-io-pager.
new e748fbe gnu: Add perl-string-formatter.
new 9273ebf gnu: Add perl-template-tiny.
new ce6bea4 gnu: Add perl-uri-nested.
new 618d52a gnu: Add perl-uri-db.
new c1a4e78 gnu: Add perl-test-checkdeps.
new 9c5551c gnu: Add perl-test-dir.
new 402cfeb gnu: Add perl-test-file.
new 709a9e9 gnu: Add perl-test-file-contents.
new 3840c51 gnu: Add perl-test-version.
new 55916fa gnu: Add perl-mysql-config.
new 7b23313 gnu: Add perl-string-shellquote.
new cabe8f1 gnu: Add sqitch.
It's written in Perl, and I recently packaged it for
Guix. The process and package definition is similar to
Ikiwiki, this time, let's look at packaging one of the
missing modules required by Sqitch.
→ guix import cpan HTTP::Tinyish
Starting download of /tmp/guix-file.f6bYLw
From http://www.cpan.org/authors/id/M/MI/MIYAGAWA/HTTP-Tinyish-0.15.tar.gz...
…-0.15.tar.gz 16KiB 722KiB/s 00:00 [##################] 100.0%
(package
(name "perl-http-tinyish" )
(version "0.15" )
(source
(origin
(method url-fetch)
(uri (string-append
"mirror://cpan/authors/id/M/MI/MIYAGAWA/HTTP-Tinyish-"
version
".tar.gz" ))
(sha256
(base32
"199sa722amvwhq0czjfb7psj3hbqmvni5vxkrm579r5943pg0rax" ))))
(build-system perl-build-system)
(propagated-inputs
`(("perl-file-which" ,perl-file-which)
("perl-ipc-run3" ,perl-ipc-run3)))
(home-page
"https://metacpan.org/release/HTTP-Tinyish" )
(synopsis
"HTTP::Tiny compatible HTTP client wrappers" )
(description fill-in-yourself!)
(license perl-license))
Guix has several importers. These importers utilise the
information that already exists about packages to help
creating Guix package definitions.
In this case, the information from CPAN is used to fill in
some of the parts of the perl-http-tinyish package
definition.
Importers can make it much easier to create package
definitions for Perl modules, as well as lots of other
languages.
Recap: Through Guix you can...
Get and use Perl
Get and use Perl modules
Get and use tools and applications written in Perl
So to recap, I haven't gone much in to the more general
what and why around Guix, but hopefully some of these Perl
examples have been useful.