Next: , Previous: , Up: Nastavenie   [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+)))

Všimnite si, že sme tentokrát zadanie balíka uložili do verejnej premennej my-hello pomocou define-public, na ktorú je možné odkazovať, medzi iným aj ako na závislosť v rámci zadania nejakého ďalšieho balíka.

Ak spustíte guix package --install-from-file=my-hello.scm s použitím vyššie uvedeného súboru, tak príkaz zlyhá, pretože posledný výraz, define-public, nevracia balík. Ak aj napriek tomu chcete v tomto prípade použiť define-public, uistite sa, že súbor končí vykonaním my-hello:

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

my-hello

Tento posledný príklad nie je veľmi bežný.

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: Priamy zásah do git repozitára, Previous: Miestny súbor, Up: Nastavenie   [Contents][Index]