containers.scm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Timmy Douglas <mail@timmydouglas.com>
  3. ;;; Copyright © 2022 Tobias Geerinckx-Rice <me@tobias.gr>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; 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 packages containers)
  20. #:use-module (guix gexp)
  21. #:use-module ((guix licenses) #:prefix license:)
  22. #:use-module (gnu packages)
  23. #:use-module (guix packages)
  24. #:use-module (guix download)
  25. #:use-module (guix git-download)
  26. #:use-module (guix build-system gnu)
  27. #:use-module (guix build-system go)
  28. #:use-module (guix build-system meson)
  29. #:use-module (guix utils)
  30. #:use-module (gnu packages admin)
  31. #:use-module (gnu packages autotools)
  32. #:use-module (gnu packages base)
  33. #:use-module (gnu packages bash)
  34. #:use-module (gnu packages check)
  35. #:use-module (gnu packages compression)
  36. #:use-module (gnu packages glib)
  37. #:use-module (gnu packages gnupg)
  38. #:use-module (gnu packages golang)
  39. #:use-module (gnu packages linux)
  40. #:use-module (gnu packages python)
  41. #:use-module (gnu packages networking)
  42. #:use-module (gnu packages pkg-config)
  43. #:use-module (gnu packages selinux)
  44. #:use-module (gnu packages version-control)
  45. #:use-module (gnu packages virtualization)
  46. #:use-module (gnu packages web))
  47. (define-public crun
  48. (let ((commit "8e5757a4e68590326dafe8a8b1b4a584b10a1370"))
  49. (package
  50. (name "crun")
  51. (version "1.3")
  52. (source
  53. (origin
  54. (method git-fetch)
  55. (uri (git-reference
  56. (url "https://github.com/containers/crun")
  57. (commit commit)
  58. (recursive? #t)))
  59. (sha256
  60. (base32 "01yiss2d57kwlxb7zlqzjwlg9fyaf19yjngd1mw9n4hxls3dfj3k"))
  61. (file-name (git-file-name name version))))
  62. (build-system gnu-build-system)
  63. (arguments
  64. `(#:configure-flags '("--disable-systemd")
  65. #:tests? #f ; XXX: needs /sys/fs/cgroup mounted
  66. #:phases
  67. (modify-phases %standard-phases
  68. (add-after 'unpack 'do-not-depend-on-git
  69. (lambda _
  70. (substitute* "autogen.sh"
  71. (("^git submodule update.*")
  72. ""))
  73. (with-output-to-file "git-version.h"
  74. (lambda ()
  75. (display (string-append
  76. "/* autogenerated. */\n#ifndef GIT_VERSION\n# define GIT_VERSION \""
  77. ,commit
  78. "\"\n#endif\n"))))))
  79. (add-after 'unpack 'fix-tests
  80. (lambda _
  81. (substitute* (find-files "tests" "\\.(c|py)")
  82. (("/bin/true") (which "true"))
  83. (("/bin/false") (which "false"))
  84. ; relies on sd_notify which requires systemd?
  85. (("\"sd-notify\" : test_sd_notify,") "")
  86. (("\"sd-notify-file\" : test_sd_notify_file,") "")))))))
  87. (inputs
  88. (list libcap
  89. libseccomp
  90. libyajl))
  91. (native-inputs
  92. (list automake
  93. autoconf
  94. git
  95. libtool
  96. pkg-config
  97. python-3))
  98. (home-page "https://github.com/containers/crun")
  99. (synopsis "Open Container Initiative (OCI) Container runtime")
  100. (description
  101. "crun is a fast and low-memory footprint Open Container Initiative (OCI)
  102. Container Runtime fully written in C.")
  103. (license license:gpl2+))))
  104. (define-public conmon
  105. (package
  106. (name "conmon")
  107. (version "2.0.31")
  108. (source
  109. (origin
  110. (method git-fetch)
  111. (uri (git-reference
  112. (url "https://github.com/containers/conmon")
  113. (commit (string-append "v" version))))
  114. (sha256
  115. (base32 "1cxklcihb2i4ywli0fxafkp2gi1x831r37z7spnigaj6pzj1517w"))
  116. (file-name (git-file-name name version))))
  117. (build-system gnu-build-system)
  118. (arguments
  119. (list #:make-flags
  120. #~(list (string-append "CC=" #$(cc-for-target))
  121. (string-append "PREFIX=" #$output))
  122. ;; XXX: uses `go get` to download 50 packages, runs a ginkgo test suite
  123. ;; then tries to download busybox and use a systemd logging library
  124. ;; see also https://github.com/containers/conmon/blob/main/nix/derivation.nix
  125. #:tests? #f
  126. #:test-target "test"
  127. #:phases
  128. #~(modify-phases %standard-phases
  129. (delete 'configure)
  130. (add-after 'unpack 'set-env
  131. (lambda _
  132. ;; when running go, things fail because
  133. ;; HOME=/homeless-shelter.
  134. (setenv "HOME" "/tmp"))))))
  135. (inputs
  136. (list crun
  137. glib
  138. libseccomp))
  139. (native-inputs
  140. (list git
  141. go
  142. pkg-config))
  143. (home-page "https://github.com/containers/conmon")
  144. (synopsis "Monitoring tool for Open Container Initiative (OCI) runtime")
  145. (description
  146. "Conmon is a monitoring program and communication tool between a container
  147. manager (like Podman or CRI-O) and an Open Container Initiative (OCI)
  148. runtime (like runc or crun) for a single container.")
  149. (license license:asl2.0)))
  150. (define-public libslirp
  151. (package
  152. (name "libslirp")
  153. (version "4.6.1")
  154. (source
  155. (origin
  156. (method git-fetch)
  157. (uri (git-reference
  158. (url "https://gitlab.freedesktop.org/slirp/libslirp")
  159. (commit (string-append "v" version))))
  160. (sha256
  161. (base32 "1b4cn51xvzbrxd63g6w1033prvbxfxsnsn1l0fa5i311xv28vkh0"))
  162. (file-name (git-file-name name version))))
  163. (build-system meson-build-system)
  164. (inputs
  165. (list glib))
  166. (native-inputs
  167. (list pkg-config))
  168. (home-page "https://gitlab.freedesktop.org/slirp/libslirp")
  169. (synopsis "User-mode networking library")
  170. (description
  171. "libslirp is a user-mode networking library used by virtual machines,
  172. containers or various tools.")
  173. (license license:bsd-3)))
  174. (define-public slirp4netns
  175. (package
  176. (name "slirp4netns")
  177. (version "1.1.12")
  178. (source
  179. (origin
  180. (method git-fetch)
  181. (uri (git-reference
  182. (url "https://github.com/rootless-containers/slirp4netns")
  183. (commit (string-append "v" version))))
  184. (sha256
  185. (base32 "03llv4dlf7qqxwz4zdyk926g4bigfj2gb50glm70ciflpvzs8081"))
  186. (file-name (git-file-name name version))))
  187. (build-system gnu-build-system)
  188. (arguments
  189. '(#:tests? #f ; XXX: open("/dev/net/tun"): No such file or directory
  190. #:phases (modify-phases %standard-phases
  191. (add-after 'unpack 'fix-hardcoded-paths
  192. (lambda _
  193. (substitute* (find-files "tests" "\\.sh")
  194. (("ping") "/run/setuid-programs/ping")))))))
  195. (inputs
  196. (list glib
  197. libcap
  198. libseccomp
  199. libslirp))
  200. (native-inputs
  201. (list automake
  202. autoconf
  203. iproute ; iproute, jq, nmap (ncat) and util-linux are for tests
  204. jq
  205. nmap
  206. pkg-config
  207. util-linux))
  208. (home-page "https://github.com/rootless-containers/slirp4netns")
  209. (synopsis "User-mode networking for unprivileged network namespaces")
  210. (description
  211. "slirp4netns provides user-mode networking (\"slirp\") for unprivileged
  212. network namespaces.")
  213. (license license:gpl2+)))
  214. (define-public cni-plugins
  215. (package
  216. (name "cni-plugins")
  217. (version "1.0.1")
  218. (source
  219. (origin
  220. (method git-fetch)
  221. (uri (git-reference
  222. (url "https://github.com/containernetworking/plugins")
  223. (commit (string-append "v" version))))
  224. (sha256
  225. (base32 "1j91in0mg4nblpdccyq63ncbnn2pc2zzjp1fh3jy0bsndllgv0nc"))
  226. (file-name (git-file-name name version))))
  227. (build-system go-build-system)
  228. (arguments
  229. `(#:unpack-path "github.com/containernetworking/plugins"
  230. #:tests? #f ; XXX: see stat /var/run below
  231. #:phases (modify-phases %standard-phases
  232. (replace 'build
  233. (lambda _
  234. (with-directory-excursion
  235. "src/github.com/containernetworking/plugins"
  236. (invoke "./build_linux.sh"))))
  237. (replace 'check
  238. (lambda* (#:key tests? #:allow-other-keys)
  239. ; only pkg/ns tests run without root
  240. (when tests?
  241. (with-directory-excursion
  242. "src/github.com/containernetworking/plugins/pkg/ns"
  243. (invoke "stat" "/var/run") ; XXX: test tries to stat this directory
  244. (invoke "unshare" "-rmn" "go" "test")))))
  245. (add-before 'check 'set-test-environment
  246. (lambda _
  247. (setenv "XDG_RUNTIME_DIR" "/tmp/cni-rootless")))
  248. (replace 'install
  249. (lambda* (#:key outputs #:allow-other-keys)
  250. (copy-recursively
  251. "src/github.com/containernetworking/plugins/bin"
  252. (string-append (assoc-ref outputs "out") "/bin")))))))
  253. (native-inputs
  254. (list util-linux))
  255. (home-page "https://github.com/containernetworking/plugins")
  256. (synopsis "Container Network Interface (CNI) network plugins")
  257. (description
  258. "This package provides Container Network Interface (CNI) plugins to
  259. configure network interfaces in Linux containers.")
  260. (license license:asl2.0)))
  261. ;; For podman to work, the user needs to run
  262. ;; `sudo mount -t cgroup2 none /sys/fs/cgroup`
  263. (define-public podman
  264. (package
  265. (name "podman")
  266. (version "3.4.4")
  267. (source
  268. (origin
  269. (method git-fetch)
  270. (uri (git-reference
  271. (url "https://github.com/containers/podman")
  272. (commit (string-append "v" version))))
  273. (sha256
  274. (base32 "1q09qsl1wwiiy5njvb97n1j5f5jin4ckmzj5xbdfs28czb2kx3g5"))
  275. (file-name (git-file-name name version))))
  276. (build-system gnu-build-system)
  277. (arguments
  278. `(#:make-flags (list ,(string-append "CC=" (cc-for-target))
  279. (string-append "PREFIX=" %output))
  280. #:tests? #f ; /sys/fs/cgroup not set up in guix sandbox
  281. #:test-target "test"
  282. #:phases (modify-phases %standard-phases
  283. (delete 'configure)
  284. (add-after 'unpack 'set-env
  285. (lambda* (#:key inputs #:allow-other-keys)
  286. ;; when running go, things fail because
  287. ;; HOME=/homeless-shelter.
  288. (setenv "HOME" "/tmp")))
  289. (replace 'check
  290. (lambda* (#:key tests? #:allow-other-keys)
  291. (when tests?
  292. ;; (invoke "strace" "-f" "bin/podman" "version")
  293. (invoke "make" "localsystem")
  294. (invoke "make" "remotesystem"))))
  295. (add-after 'unpack 'fix-hardcoded-paths
  296. (lambda _
  297. (substitute* (find-files "libpod" "\\.go")
  298. (("exec.LookPath[(][\"]slirp4netns[\"][)]")
  299. (string-append "exec.LookPath(\""
  300. (which "slirp4netns") "\")")))
  301. (substitute* "hack/install_catatonit.sh"
  302. (("CATATONIT_PATH=\"[^\"]+\"")
  303. (string-append "CATATONIT_PATH=" (which "true"))))
  304. (substitute* "vendor/github.com/containers/common/pkg/config/config_linux.go"
  305. (("/usr/local/libexec/podman")
  306. (string-append (assoc-ref %outputs "out") "/bin")))
  307. (substitute* "vendor/github.com/containers/common/pkg/config/default.go"
  308. (("/usr/libexec/podman/conmon") (which "conmon"))
  309. (("/usr/local/libexec/cni")
  310. (string-append (assoc-ref %build-inputs "cni-plugins")
  311. "/bin"))
  312. (("/usr/bin/crun") (which "crun"))))))))
  313. (inputs
  314. (list btrfs-progs
  315. cni-plugins
  316. conmon
  317. crun
  318. gpgme
  319. go-github-com-go-md2man
  320. iptables
  321. libassuan
  322. libseccomp
  323. libselinux
  324. slirp4netns))
  325. (native-inputs
  326. (list bats
  327. git
  328. go
  329. ; strace ; XXX debug
  330. pkg-config))
  331. (home-page "https://podman.io")
  332. (synopsis "Manage containers, images, pods, and their volumes")
  333. (description
  334. "Podman (the POD MANager) is a tool for managing containers and images,
  335. volumes mounted into those containers, and pods made from groups of
  336. containers.")
  337. (license license:asl2.0)))