ci.scm 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018, 2019, 2020, 2021 Christopher Baines <mail@cbaines.net>
  3. ;;; Copyright © 2021, 2022 Arun Isaac <arunisaac@systemreboot.net>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify
  8. ;;; it under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation, either version 3 of the License, or
  10. ;;; (at your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful,
  13. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu services ci)
  20. #:use-module (guix gexp)
  21. #:use-module (guix records)
  22. #:use-module (gnu packages admin)
  23. #:use-module (gnu packages ci)
  24. #:use-module (gnu services)
  25. #:use-module (gnu services base)
  26. #:use-module (gnu services shepherd)
  27. #:use-module (gnu services admin)
  28. #:use-module (gnu system shadow)
  29. #:use-module (ice-9 match)
  30. #:export (laminar-configuration
  31. laminar-configuration?
  32. laminar-configuration-home-directory
  33. laminar-configuration-bind-http
  34. laminar-configuration-bind-rpc
  35. laminar-configuration-title
  36. laminar-configuration-keep-rundirs
  37. laminar-configuration-archive-url
  38. laminar-configuration-base-url
  39. laminar-service-type))
  40. ;;;; Commentary:
  41. ;;;
  42. ;;; This module implements a service that to run instances of Laminar, a
  43. ;;; continuous integration tool.
  44. ;;;
  45. ;;;; Code:
  46. (define-record-type* <laminar-configuration>
  47. laminar-configuration make-laminar-configuration
  48. laminar-configuration?
  49. (laminar laminars-configuration-laminar
  50. (default laminar))
  51. (home-directory laminar-configuration-home-directory
  52. (default "/var/lib/laminar"))
  53. (bind-http laminar-configuration-bind-http
  54. (default "*:8080"))
  55. (bind-rpc laminar-configuration-bind-rpc
  56. (default "unix-abstract:laminar"))
  57. (title laminar-configuration-title
  58. (default "Laminar"))
  59. (keep-rundirs laminar-keep-rundirs
  60. (default 0))
  61. (archive-url laminar-archive-url
  62. (default #f))
  63. (base-url laminar-base-url
  64. (default #f)))
  65. (define laminar-shepherd-service
  66. (match-lambda
  67. (($ <laminar-configuration> laminar home-directory
  68. bind-http bind-rpc
  69. title keep-rundirs archive-url
  70. base-url)
  71. (list (shepherd-service
  72. (documentation "Run Laminar.")
  73. (provision '(laminar))
  74. (requirement '(networking))
  75. (start #~(make-forkexec-constructor
  76. (list #$(file-append laminar "/sbin/laminard"))
  77. #:environment-variables
  78. `(,(string-append "LAMINAR_HOME="
  79. #$home-directory)
  80. ,(string-append "LAMINAR_BIND_HTTP="
  81. #$bind-http)
  82. ,(string-append "LAMINAR_BIND_RPC="
  83. #$bind-rpc)
  84. ,(string-append "LAMINAR_TITLE="
  85. #$title)
  86. ,(string-append "LAMINAR_KEEP_RUNDIRS="
  87. #$(number->string
  88. keep-rundirs))
  89. ,@(if #$archive-url
  90. (list
  91. (string-append "LAMINAR_ARCHIVE_URL="
  92. #$archive-url))
  93. '())
  94. ,@(if #$base-url
  95. (list
  96. (string-append "LAMINAR_BASE_URL="
  97. #$base-url))
  98. '()))
  99. #:user "laminar"
  100. #:group "laminar"))
  101. (stop #~(make-kill-destructor)))))))
  102. (define (laminar-account config)
  103. "Return the user accounts and user groups for CONFIG."
  104. (list (user-group
  105. (name "laminar")
  106. (system? #t))
  107. (user-account
  108. (name "laminar")
  109. (group "laminar")
  110. (system? #t)
  111. (comment "Laminar privilege separation user")
  112. (home-directory (laminar-configuration-home-directory config))
  113. (shell #~(string-append #$shadow "/sbin/nologin")))))
  114. (define (laminar-activation config)
  115. (let ((bind-http (laminar-configuration-bind-http config)))
  116. #~(begin
  117. ;; If listen is a unix socket, create its parent directory.
  118. (when (string-prefix? "unix:" #$bind-http)
  119. (let ((run-directory
  120. (dirname (substring #$bind-http (string-length "unix:"))))
  121. (user (getpw "laminar")))
  122. (mkdir-p run-directory)
  123. (chown run-directory (passwd:uid user) (passwd:gid user)))))))
  124. (define laminar-service-type
  125. (service-type
  126. (name 'laminar)
  127. (extensions
  128. (list
  129. (service-extension shepherd-root-service-type laminar-shepherd-service)
  130. (service-extension account-service-type laminar-account)
  131. (service-extension activation-service-type laminar-activation)))
  132. (default-value (laminar-configuration))
  133. (description
  134. "Run the Laminar continuous integration service.")))