You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
5.9 KiB

  1. -*- mode: org; coding: utf-8; -*-
  2. #+TITLE: Hacking GNU Guix and its incredible distro
  3. Copyright © 2012 Ludovic Courtès <>
  4. Copying and distribution of this file, with or without modification,
  5. are permitted in any medium without royalty provided the copyright
  6. notice and this notice are preserved.
  7. * Adding new packages
  8. Package recipes in Guix look like this:
  9. #+BEGIN_SRC scheme
  10. (package
  11. (name "nettle")
  12. (version "2.5")
  13. (source
  14. (origin
  15. (method http-fetch)
  16. (uri (string-append ""
  17. version ".tar.gz"))
  18. (sha256
  19. (base32
  20. "0wicr7amx01l03rm0pzgr1qvw3f9blaw17vjsy1301dh13ll58aa"))))
  21. (build-system gnu-build-system)
  22. (inputs `(("gnum4" ,gnum4)))
  23. (propagated-inputs `(("gmp" ,gmp)))
  24. (home-page
  25. "")
  26. (synopsis "GNU Nettle, a cryptographic library")
  27. (description
  28. "Nettle is a cryptographic library...")
  29. (license "GPLv2+"))
  30. #+END_SRC
  31. Such a recipe can be written by hand, and then tested by running
  32. ‘./pre-inst-env guix-build nettle’.
  33. When writing the recipe, the base32-encoded SHA256 hash of the source
  34. code tarball, which can be seen in the example above, can be obtained by
  35. running:
  36. guix-download
  37. Alternatively, it is possible to semi-automatically import recipes from
  38. the [[][Nixpkgs]] software distribution using this command:
  39. guix-import /path/to/nixpkgs/checkout nettle
  40. The command automatically fetches and converts to Guix the “Nix
  41. expression” of Nettle.
  42. * Porting the Guix distro on a new platform
  43. ** Introduction
  44. Unlike Make or similar build tools, Guix requires absolutely /all/ the
  45. dependencies of a build process to be specified.
  46. For a user-land software distribution, that means that the process that
  47. builds GCC (then used to build all other programs) must itself be
  48. specified; and the process to build the C library to build that GCC; and
  49. the process to build the GCC to build that library; and... See the
  50. problem? Chicken-and-egg.
  51. To break that cycle, the distro starts from a set of pre-built
  52. binaries–usually referred to as “bootstrap binaries.” These include
  53. statically-linked versions of Guile, GCC, Coreutils, Make, Grep, sed,
  54. etc., and the GNU C Library.
  55. This section describes how to build those bootstrap binaries when
  56. porting to a new platform.
  57. ** When the platform is supported by Nixpkgs
  58. In that case, the easiest thing is to bootstrap the distro using
  59. binaries from Nixpkgs.
  60. To do that, you need to comment out the definitions of
  61. ‘%bootstrap-guile’ and ‘%bootstrap-inputs’ in distro/packages/bootstrap.scm
  62. to force the use of Nixpkgs derivations. For instance, when porting to
  63. ‘i686-linux’, you should redefine these variables along these lines:
  64. #+BEGIN_SRC scheme
  65. (define %bootstrap-guile
  66. (nixpkgs-derivation "guile" "i686-linux"))
  67. (define %bootstrap-inputs
  68. (compile-time-value
  69. `(("libc" ,(nixpkgs-derivation "glibc" "i686-linux"))
  70. ,@(map (lambda (name)
  71. (list name (nixpkgs-derivation name "i686-linux")))
  72. '("gnutar" "gzip" "bzip2" "xz" "patch"
  73. "coreutils" "gnused" "gnugrep" "bash"
  74. "gawk" ; used by `config.status'
  75. "gcc" "binutils")))))
  76. #+END_SRC
  77. That should allow the distro to be bootstrapped.
  78. Then, the tarballs containing the initial binaries of Guile, Coreutils,
  79. GCC, libc, etc. need to be built. To that end, run the following
  80. commands:
  81. #+BEGIN_SRC sh
  82. ./pre-inst-env guix-build \
  83. -e '(@@ (distro packages base) %guile-bootstrap-tarball)' \
  84. --system=i686-linux
  85. ./pre-inst-env guix-build \
  86. -e '(@@ (distro packages base) %bootstrap-binaries-tarball)' \
  87. --system=i686-linux
  88. ./pre-inst-env guix-build \
  89. -e '(@@ (distro packages base) %binutils-bootstrap-tarball)' \
  90. --system=i686-linux
  91. ./pre-inst-env guix-build \
  92. -e '(@@ (distro packages base) %glibc-bootstrap-tarball)' \
  93. --system=i686-linux
  94. ./pre-inst-env guix-build \
  95. -e '(@@ (distro packages base) %gcc-bootstrap-tarball)' \
  96. --system=i686-linux
  97. #+END_SRC
  98. These should build tarballs containing statically-linked tools usable on
  99. that system.
  100. In the source tree, you need to install binaries for ‘mkdir’, ‘bash’,
  101. ‘tar’, and ‘xz’ under ‘distro/packages/bootstrap/i686-linux’. These
  102. binaries can be extracted from the static-binaries tarball built above.
  103. A rule for
  104. ‘distro/packages/bootstrap/i686-linux/guile-bootstrap-2.0.6.tar.xz’
  105. needs to be added in ‘’, with the appropriate hexadecimal
  106. vrepresentation of its SHA256 hash.
  107. You may then revert your changes to ‘base.scm’. For the variables
  108. ‘%bootstrap-coreutils&co’, ‘%bootstrap-binutils’, ‘%bootstrap-glibc’,
  109. and ‘%bootstrap-gcc’, the expected SHA256 of the corresponding tarballs
  110. for ‘i686-linux’ (built above) must be added.
  111. This should be enough to bootstrap the distro without resorting to
  112. Nixpkgs.
  113. ** When the platform is *not* supported by Nixpkgs
  114. In that case, the bootstrap binaries should be built using whatever
  115. tools are available on the target platform. That is, the tarballs and
  116. binaries show above must first be built manually, using the available
  117. tools.
  118. They should have the same properties as those built by the Guix recipes
  119. shown above. For example, all the binaries (except for glibc) must be
  120. statically-linked; the bootstrap Guile must be relocatable (see patch in
  121. the Guix distro); the static-binaries tarball must contain the same
  122. programs (Coreutils, Grep, sed, Awk, etc.); and so on.