package-management.scm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 Oleg Pykhalov <go.wigust@gmail.com>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; 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 tests package-management)
  19. #:use-module (gnu packages base)
  20. #:use-module (gnu packages package-management)
  21. #:use-module (gnu services)
  22. #:use-module (gnu services networking)
  23. #:use-module (gnu services nix)
  24. #:use-module (gnu system)
  25. #:use-module (gnu system vm)
  26. #:use-module (gnu tests)
  27. #:use-module (guix gexp)
  28. #:use-module (guix packages)
  29. #:export (%test-nix))
  30. ;;; Commentary:
  31. ;;;
  32. ;;; This module provides a test definition for the nix-daemon
  33. ;;;
  34. ;;; Code:
  35. (define* (run-nix-test name test-os)
  36. "Run tests in TEST-OS, which has nix-daemon running."
  37. (define os
  38. (marionette-operating-system
  39. test-os
  40. #:imported-modules '((gnu services herd))))
  41. (define vm
  42. (virtual-machine
  43. (operating-system os)
  44. (port-forwardings '((8080 . 80)))
  45. (memory-size 1024)))
  46. (define test
  47. (with-imported-modules '((gnu build marionette))
  48. #~(begin
  49. (use-modules (srfi srfi-11)
  50. (srfi srfi-64)
  51. (gnu build marionette)
  52. (web client)
  53. (web response))
  54. (define marionette
  55. (make-marionette (list #$vm)))
  56. (mkdir #$output)
  57. (chdir #$output)
  58. (test-begin #$name)
  59. ;; XXX: Shepherd reads the config file *before* binding its control
  60. ;; socket, so /var/run/shepherd/socket might not exist yet when the
  61. ;; 'marionette' service is started.
  62. (test-assert "shepherd socket ready"
  63. (marionette-eval
  64. `(begin
  65. (use-modules (gnu services herd))
  66. (let loop ((i 10))
  67. (cond ((file-exists? (%shepherd-socket-file))
  68. #t)
  69. ((> i 0)
  70. (sleep 1)
  71. (loop (- i 1)))
  72. (else
  73. 'failure))))
  74. marionette))
  75. (test-assert "Nix daemon running"
  76. (marionette-eval
  77. '(begin
  78. ;; Wait for nix-daemon to be up and running.
  79. (start-service 'nix-daemon)
  80. (with-output-to-file "guix-test.nix"
  81. (lambda ()
  82. (display "\
  83. with import <nix/config.nix>;
  84. derivation {
  85. system = builtins.currentSystem;
  86. name = \"guix-test\";
  87. builder = shell;
  88. args = [\"-c\" \"mkdir $out\\necho FOO > $out/foo\"];
  89. PATH = coreutils;
  90. }
  91. ")))
  92. (zero? (system* (string-append #$nix "/bin/nix-build")
  93. "--substituters" "" "--debug" "--no-out-link"
  94. "guix-test.nix")))
  95. marionette))
  96. (test-end)
  97. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  98. (gexp->derivation (string-append name "-test") test))
  99. (define %nix-os
  100. ;; Return operating system under test.
  101. (let ((base-os
  102. (simple-operating-system
  103. (service nix-service-type)
  104. (service dhcp-client-service-type))))
  105. (operating-system
  106. (inherit base-os)
  107. (packages (cons nix (operating-system-packages base-os))))))
  108. (define %test-nix
  109. (system-test
  110. (name "nix")
  111. (description "Connect to a running nix-daemon")
  112. (value (run-nix-test name %nix-os))))
  113. ;;; package-management.scm ends here