Next: , Previous: , Up: Setup   [Contents][Index]


2.1.2.2 Channels

Guix and its package collection can be extended through channels. A channel is a Git repository, public or not, containing .scm files that provide packages (see Defining Packages in GNU Guix Reference Manual) or services (see Defining Services in GNU Guix Reference Manual).

How would you go about creating a channel? First, create a directory that will contain your .scm files, say ~/my-channel:

mkdir ~/my-channel

Suppose you want to add the ‘my-hello’ package we saw previously; it first needs some adjustments:

(define-module (my-hello)
  #:use-module (guix licenses)
  #:use-module (guix packages)
  #:use-module (guix build-system gnu)
  #:use-module (guix download))

(define-public my-hello
  (package
    (name "my-hello")
    (version "2.10")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/hello/hello-" version
                                  ".tar.gz"))
              (sha256
               (base32
                "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
    (build-system gnu-build-system)
    (synopsis "Hello, Guix world: An example custom Guix package")
    (description
     "GNU Hello prints the message \"Hello, world!\" and then exits.  It
serves as an example of standard GNU coding practices.  As such, it supports
command-line arguments, multiple languages, and so on.")
    (home-page "https://www.gnu.org/software/hello/")
    (license gpl3+)))

Note that we have assigned the package value to an exported variable name with define-public. This is effectively assigning the package to the my-hello variable so that it can be referenced, among other as dependency of other packages.

If you use guix package --install-from-file=my-hello.scm on the above file, it will fail because the last expression, define-public, does not return a package. If you want to use define-public in this use-case nonetheless, make sure the file ends with an evaluation of my-hello:

;; ...
(define-public my-hello
  ;; ...
  )

my-hello

This last example is not very typical.

Now how do you make that package visible to guix commands so you can test your packages? You need to add the directory to the search path using the -L command-line option, as in these examples:

guix show -L ~/my-channel my-hello
guix build -L ~/my-channel my-hello

The final step is to turn ~/my-channel into an actual channel, making your package collection seamlessly available via any guix command. To do that, you first need to make it a Git repository:

cd ~/my-channel
git init
git add my-hello.scm
git commit -m "First commit of my channel."

And that’s it, you have a channel! From there on, you can add this channel to your channel configuration in ~/.config/guix/channels.scm (see Specifying Additional Channels in GNU Guix Reference Manual); assuming you keep your channel local for now, the channels.scm would look something like this:

(append (list (channel
                (name 'my-channel)
                (url (string-append "file://" (getenv "HOME")
                                    "/my-channel"))))
        %default-channels)

Next time you run guix pull, your channel will be picked up and the packages it defines will be readily available to all the guix commands, even if you do not pass -L. The guix describe command will show that Guix is, indeed, using both the my-channel and the guix channels.

See Creating a Channel in GNU Guix Reference Manual, for details.


Next: Direct checkout hacking, Previous: Local file, Up: Setup   [Contents][Index]