ci.scm 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018, 2019, 2020, 2021 Christopher Baines <mail@cbaines.net>
  3. ;;; Copyright © 2021 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_TITLE="
  83. #$title)
  84. ,(string-append "LAMINAR_KEEP_RUNDIRS="
  85. #$(number->string
  86. keep-rundirs))
  87. ,@(if #$archive-url
  88. (list
  89. (string-append "LAMINAR_ARCHIVE_URL="
  90. #$archive-url))
  91. '())
  92. ,@(if #$base-url
  93. (list
  94. (string-append "LAMINAR_BASE_URL="
  95. #$base-url))
  96. '()))
  97. #:user "laminar"
  98. #:group "laminar"))
  99. (stop #~(make-kill-destructor)))))))
  100. (define (laminar-account config)
  101. "Return the user accounts and user groups for CONFIG."
  102. (list (user-group
  103. (name "laminar")
  104. (system? #t))
  105. (user-account
  106. (name "laminar")
  107. (group "laminar")
  108. (system? #t)
  109. (comment "Laminar privilege separation user")
  110. (home-directory (laminar-configuration-home-directory config))
  111. (shell #~(string-append #$shadow "/sbin/nologin")))))
  112. (define (laminar-activation config)
  113. (let ((bind-http (laminar-configuration-bind-http config)))
  114. #~(begin
  115. ;; If listen is a unix socket, create its parent directory.
  116. (when (string-prefix? "unix:" #$bind-http)
  117. (let ((run-directory
  118. (dirname (substring #$bind-http (string-length "unix:"))))
  119. (user (getpw "laminar")))
  120. (mkdir-p run-directory)
  121. (chown run-directory (passwd:uid user) (passwd:gid user)))))))
  122. (define laminar-service-type
  123. (service-type
  124. (name 'laminar)
  125. (extensions
  126. (list
  127. (service-extension shepherd-root-service-type laminar-shepherd-service)
  128. (service-extension account-service-type laminar-account)
  129. (service-extension activation-service-type laminar-activation)))
  130. (default-value (laminar-configuration))
  131. (description
  132. "Run the Laminar continuous integration service.")))