pack.scm 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (guix build pack)
  19. #:use-module (guix build utils)
  20. #:export (tar-base-options))
  21. (define* (tar-base-options #:key tar compressor)
  22. "Return the base GNU tar options required to produce deterministic archives
  23. deterministically. When TAR, a GNU tar command file name, is provided, the
  24. `--sort' option is used only if supported. When COMPRESSOR, a command such as
  25. '(\"gzip\" \"-9n\"), is provided, the compressor is explicitly specified via
  26. the `-I' option."
  27. (define (tar-supports-sort? tar)
  28. (with-error-to-port (%make-void-port "w")
  29. (lambda ()
  30. (zero? (system* tar "cf" "/dev/null" "--files-from=/dev/null"
  31. "--sort=name")))))
  32. `(,@(if compressor
  33. (list "-I" (string-join compressor))
  34. '())
  35. ;; The --sort option was added to GNU tar in version 1.28, released
  36. ;; 2014-07-28. For testing, we use the bootstrap tar, which is older
  37. ;; and doesn't support it.
  38. ,@(if (and=> tar tar-supports-sort?)
  39. '("--sort=name")
  40. '())
  41. ;; Use GNU format so there's no file name length limitation.
  42. "--format=gnu"
  43. "--mtime=@1"
  44. "--owner=root:0"
  45. "--group=root:0"
  46. ;; The 'nlink' of the store item files leads tar to store hard links
  47. ;; instead of actual copies. However, the 'nlink' count depends on
  48. ;; deduplication in the store; it's an "implicit input" to the build
  49. ;; process. Use '--hard-dereference' to eliminate it.
  50. "--hard-dereference"
  51. "--check-links"))