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.

119 lines
4.5 KiB

  1. -*- mode: org; coding: utf-8; -*-
  2. #+TITLE: Hacking 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. * Porting the Guix distro on a new platform
  8. ** Introduction
  9. Unlike Make or similar build tools, Guix requires absolutely /all/ the
  10. dependencies of a build process to be specified.
  11. For a user-land software distribution, that means that the process that
  12. builds GCC (then used to build all other programs) must itself be
  13. specified; and the process to build the C library to build that GCC; and
  14. the process to build the GCC to build that library; and... See the
  15. problem? Chicken-and-egg.
  16. To break that cycle, the distro starts from a set of pre-built
  17. binaries–usually referred to as “bootstrap binaries.” These include
  18. statically-linked versions of Guile, GCC, Coreutils, Make, Grep, sed,
  19. etc., and the GNU C Library.
  20. This section describes how to build those bootstrap binaries when
  21. porting to a new platform.
  22. ** When the platform is supported by Nixpkgs
  23. In that case, the easiest thing is to bootstrap the distro using
  24. binaries from Nixpkgs.
  25. To do that, you need to comment out the definitions of
  26. ‘%bootstrap-guile’ and ‘%bootstrap-inputs’ in distro/packages/base.scm
  27. to force the use of Nixpkgs derivations. For instance, when porting to
  28. ‘i686-linux’, you should redefine these variables along these lines:
  29. #+BEGIN_SRC scheme
  30. (define %bootstrap-guile
  31. (nixpkgs-derivation "guile" "i686-linux"))
  32. (define %bootstrap-inputs
  33. (compile-time-value
  34. `(("libc" ,(nixpkgs-derivation "glibc" "i686-linux"))
  35. ,@(map (lambda (name)
  36. (list name (nixpkgs-derivation name "i686-linux")))
  37. '("gnutar" "gzip" "bzip2" "xz" "patch"
  38. "coreutils" "gnused" "gnugrep" "bash"
  39. "gawk" ; used by `config.status'
  40. "gcc" "binutils")))))
  41. #+END_SRC
  42. That should allow the distro to be bootstrapped.
  43. Then, the tarballs containing the initial binaries of Guile, Coreutils,
  44. GCC, libc, etc. need to be built. To that end, run the following
  45. commands:
  46. #+BEGIN_SRC sh
  47. ./pre-inst-env guix-build \
  48. -e '(@@ (distro packages base) %guile-bootstrap-tarball)' \
  49. --system=i686-linux
  50. ./pre-inst-env guix-build \
  51. -e '(@@ (distro packages base) %bootstrap-binaries-tarball)' \
  52. --system=i686-linux
  53. ./pre-inst-env guix-build \
  54. -e '(@@ (distro packages base) %binutils-bootstrap-tarball)' \
  55. --system=i686-linux
  56. ./pre-inst-env guix-build \
  57. -e '(@@ (distro packages base) %glibc-bootstrap-tarball)' \
  58. --system=i686-linux
  59. ./pre-inst-env guix-build \
  60. -e '(@@ (distro packages base) %gcc-bootstrap-tarball)' \
  61. --system=i686-linux
  62. #+END_SRC
  63. These should build tarballs containing statically-linked tools usable on
  64. that system.
  65. In the source tree, you need to install binaries for ‘mkdir’, ‘bash’,
  66. ‘tar’, and ‘xz’ under ‘distro/packages/bootstrap/i686-linux’. These
  67. binaries can be extracted from the static-binaries tarball built above.
  68. A rule for
  69. ‘distro/packages/bootstrap/i686-linux/guile-bootstrap-2.0.6.tar.xz’
  70. needs to be added in ‘’, with the appropriate hexadecimal
  71. vrepresentation of its SHA256 hash.
  72. You may then revert your changes to ‘base.scm’. For the variables
  73. ‘%bootstrap-coreutils&co’, ‘%bootstrap-binutils’, ‘%bootstrap-glibc’,
  74. and ‘%bootstrap-gcc’, the expected SHA256 of the corresponding tarballs
  75. for ‘i686-linux’ (built above) must be added.
  76. This should be enough to bootstrap the distro without resorting to
  77. Nixpkgs.
  78. ** When the platform is *not* supported by Nixpkgs
  79. In that case, the bootstrap binaries should be built using whatever
  80. tools are available on the target platform. That is, the tarballs and
  81. binaries show above must first be built manually, using the available
  82. tools.
  83. They should have the same properties as those built by the Guix recipes
  84. shown above. For example, all the binaries (except for glibc) must be
  85. statically-linked; the bootstrap Guile must be relocatable (see patch in
  86. the Guix distro); the static-binaries tarball must contain the same
  87. programs (Coreutils, Grep, sed, Awk, etc.); and so on.