fhs.scm 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. (define-module (nongnu services fhs)
  2. #:use-module (ice-9 ftw) ;; for creating recursive list of directories of libs for FHS #:use-module (guix download)
  3. #:use-module (srfi srfi-1) ;; For filter-map
  4. #:use-module (guix records) ;; For defining record types
  5. #:use-module (guix profiles) ;; for manifest-entries
  6. #:use-module (gnu services) ;; For defining services
  7. #:use-module (guix gexp) ;; For computed-file and other things
  8. #:use-module (guix packages) ;; For package
  9. #:use-module (gnu packages) ;; For specifications->manifest
  10. #:use-module (gnu packages base) ;; For glibc
  11. #:export (fhs-binaries-compatibility-service-type
  12. fhs-binaries-compatibility-service
  13. fhs-configuration))
  14. (define (32bit-package pkg)
  15. (package (inherit pkg)
  16. (name (string-append (package-name pkg) "-i686-linux"))
  17. (arguments
  18. `(#:system "i686-linux"
  19. ,@(package-arguments pkg)))))
  20. (define glibc-for-fhs
  21. (package (inherit glibc)
  22. (name "glibc-for-fhs") ;; Maybe rename this to "glibc-with-ldconfig-for-fhs"
  23. (source (origin
  24. (inherit (package-source glibc))
  25. (snippet #f))))) ;; Re-enable ldconfig
  26. (define (packages->ld.so.conf packages)
  27. (computed-file
  28. "ld.so.conf"
  29. (with-imported-modules
  30. `((guix build union)
  31. (guix build utils))
  32. #~(begin
  33. (use-modules (guix build union)
  34. (guix build utils))
  35. (let* ((packages '#$packages) ;; Need to quote "#$packages" as #$packages tries to "apply" the first item to the rest, like a procedure.
  36. (find-lib-directories-in-single-package
  37. (lambda (package)
  38. (find-files (string-append package "/lib")
  39. (lambda (file stat)
  40. ;; setting keyword "stat" to "stat" means it will follow
  41. ;; symlinks, unlike what it's set to by default ("lstat").
  42. (eq? 'directory (stat:type stat)))
  43. #:stat stat
  44. #:directories? #t)))
  45. (find-lib-directories-in-all-packages
  46. (lambda (packages)
  47. (apply append ;; Concatenate the directory lists from "map" into one list
  48. (map (lambda (package)
  49. (find-lib-directories-in-single-package package))
  50. packages))))
  51. (fhs-lib-dirs
  52. (find-lib-directories-in-all-packages packages)))
  53. (with-output-to-file
  54. #$output
  55. (lambda _
  56. (format #t
  57. (string-join fhs-lib-dirs "\n"))
  58. #$output)))))))
  59. (define (ld.so.conf->ld.so.cache ld-conf)
  60. (computed-file "ld.so.cache"
  61. (with-imported-modules `((guix build utils))
  62. #~(begin
  63. (use-modules (guix build utils))
  64. (let* ((ldconfig (string-append #$glibc-for-fhs "/sbin/ldconfig")))
  65. (invoke ldconfig
  66. "-X" ;; Don't update symbolic links
  67. "-f" #$ld-conf ;; Use #$configuration as configuration file
  68. "-C" #$output)))))) ;; Use #$output as cache file
  69. (define (packages->ld.so.cache packages)
  70. (ld.so.conf->ld.so.cache (packages->ld.so.conf packages)))
  71. (define-record-type* <fhs-configuration>
  72. fhs-configuration
  73. make-fhs-configuration
  74. fhs-configuration?
  75. (lib-packages fhs-configuration-lib-packages
  76. (default '()))
  77. (additional-profile-packages fhs-configuration-additional-profile-packages ;; For putting programs in $PATH and for share data
  78. (default '()))
  79. (additional-special-files fhs-configuration-additional-special-files
  80. (default '())))
  81. (define* (union name packages #:key options)
  82. (computed-file name
  83. (with-imported-modules `((guix build union))
  84. #~(begin
  85. (use-modules (guix build union))
  86. (union-build #$output '#$packages)))
  87. #:options options))
  88. (define* (fhs-libs-union packages #:key system)
  89. (let* ((name (if system
  90. (string-append "fhs-libs-" system)
  91. "fhs-libs")))
  92. (union name
  93. packages
  94. #:options `(#:system ,system))))
  95. (define (fhs-special-files-service config)
  96. "Return the list of special files for the fhs service"
  97. (let* ((fhs-lib-packages (fhs-configuration-lib-packages config))
  98. (fhs-lib-package-unions (append fhs-lib-packages
  99. `(,(fhs-libs-union fhs-lib-packages #:system "i686-linux"))))
  100. (fhs-glibc-special-files
  101. `(("/etc/ld.so.cache" ,(packages->ld.so.cache fhs-lib-package-unions))
  102. ("/etc/ld.so.conf" ,(packages->ld.so.conf fhs-lib-package-unions)) ;;Not needed to function, but put it here anyway for debugging purposes
  103. ("/lib64/ld-linux-x86-64.so.2" ,(file-append (canonical-package glibc-for-fhs) "/lib/ld-linux-x86-64.so.2"))
  104. ("/lib/ld-linux.so.2" ,(file-append (canonical-package (32bit-package glibc-for-fhs)) "/lib/ld-linux.so.2"))))
  105. ;; ("/fhs/libs" ,(file-append (canonical-package fhs-libs-64) "/lib"))
  106. (fhs-additional-special-files (fhs-configuration-additional-special-files config)))
  107. (append fhs-glibc-special-files
  108. fhs-additional-special-files)))
  109. (define (fhs-profile-service config)
  110. "Return the list of packages to add to the system profile"
  111. ;; Get list of packages from config to add to system profile and return them
  112. (fhs-configuration-additional-profile-packages config))
  113. (define fhs-binaries-compatibility-service-type
  114. (service-type (name 'fhs-compatibility-service)
  115. (extensions
  116. (list (service-extension special-files-service-type
  117. fhs-special-files-service)
  118. (service-extension profile-service-type
  119. fhs-profile-service)
  120. ))
  121. (description
  122. "Support binaries compiled for the filesystem hierarchy standard.")
  123. (default-value (fhs-configuration))))
  124. (define fhs-binaries-compatibility-service
  125. (service fhs-binaries-compatibility-service-type))