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.

160 lines
5.6 KiB

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