ci.scm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018, 2019, 2020, 2021 Christopher Baines <mail@cbaines.net>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify
  7. ;;; it under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation, either version 3 of the License, or
  9. ;;; (at your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful,
  12. ;;; but 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 (gnu services ci)
  19. #:use-module (guix gexp)
  20. #:use-module (guix records)
  21. #:use-module (gnu packages admin)
  22. #:use-module (gnu packages ci)
  23. #:use-module (gnu services)
  24. #:use-module (gnu services base)
  25. #:use-module (gnu services shepherd)
  26. #:use-module (gnu services admin)
  27. #:use-module (gnu system shadow)
  28. #:use-module (ice-9 match)
  29. #:export (laminar-configuration
  30. laminar-configuration?
  31. laminar-configuration-home-directory
  32. laminar-configuration-bind-http
  33. laminar-configuration-bind-rpc
  34. laminar-configuration-title
  35. laminar-configuration-keep-rundirs
  36. laminar-configuration-archive-url
  37. laminar-configuration-base-url
  38. laminar-service-type))
  39. ;;;; Commentary:
  40. ;;;
  41. ;;; This module implements a service that to run instances of Laminar, a
  42. ;;; continuous integration tool.
  43. ;;;
  44. ;;;; Code:
  45. (define-record-type* <laminar-configuration>
  46. laminar-configuration make-laminar-configuration
  47. laminar-configuration?
  48. (laminar laminars-configuration-laminar
  49. (default laminar))
  50. (home-directory laminar-configuration-home-directory
  51. (default "/var/lib/laminar"))
  52. (bind-http laminar-configuration-bind-http
  53. (default "*:8080"))
  54. (bind-rpc laminar-configuration-bind-rpc
  55. (default "unix-abstract:laminar"))
  56. (title laminar-configuration-title
  57. (default "Laminar"))
  58. (keep-rundirs laminar-keep-rundirs
  59. (default 0))
  60. (archive-url laminar-archive-url
  61. (default #f))
  62. (base-url laminar-base-url
  63. (default #f)))
  64. (define laminar-shepherd-service
  65. (match-lambda
  66. (($ <laminar-configuration> laminar home-directory
  67. bind-http bind-rpc
  68. title keep-rundirs archive-url
  69. base-url)
  70. (list (shepherd-service
  71. (documentation "Run Laminar.")
  72. (provision '(laminar))
  73. (requirement '(networking))
  74. (start #~(make-forkexec-constructor
  75. (list #$(file-append laminar "/sbin/laminard"))
  76. #:environment-variables
  77. `(,(string-append "LAMINAR_HOME="
  78. #$home-directory)
  79. ,(string-append "LAMINAR_BIND_HTTP="
  80. #$bind-http)
  81. ,(string-append "LAMINAR_TITLE="
  82. #$title)
  83. ,(string-append "LAMINAR_KEEP_RUNDIRS="
  84. #$(number->string
  85. keep-rundirs))
  86. ,@(if #$archive-url
  87. (list
  88. (string-append "LAMINAR_ARCHIVE_URL="
  89. #$archive-url))
  90. '())
  91. ,@(if #$base-url
  92. (list
  93. (string-append "LAMINAR_BASE_URL="
  94. #$base-url))
  95. '()))
  96. #:user "laminar"
  97. #:group "laminar"))
  98. (stop #~(make-kill-destructor)))))))
  99. (define (laminar-account config)
  100. "Return the user accounts and user groups for CONFIG."
  101. (list (user-group
  102. (name "laminar")
  103. (system? #t))
  104. (user-account
  105. (name "laminar")
  106. (group "laminar")
  107. (system? #t)
  108. (comment "Laminar privilege separation user")
  109. (home-directory (laminar-configuration-home-directory config))
  110. (shell #~(string-append #$shadow "/sbin/nologin")))))
  111. (define laminar-service-type
  112. (service-type
  113. (name 'laminar)
  114. (extensions
  115. (list
  116. (service-extension shepherd-root-service-type laminar-shepherd-service)
  117. (service-extension account-service-type laminar-account)))
  118. (default-value (laminar-configuration))
  119. (description
  120. "Run the Laminar continuous integration service.")))