package-management.scm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. (test-runner-current (system-test-runner #$output))
  57. (test-begin #$name)
  58. ;; XXX: Shepherd reads the config file *before* binding its control
  59. ;; socket, so /var/run/shepherd/socket might not exist yet when the
  60. ;; 'marionette' service is started.
  61. (test-assert "shepherd socket ready"
  62. (marionette-eval
  63. `(begin
  64. (use-modules (gnu services herd))
  65. (let loop ((i 10))
  66. (cond ((file-exists? (%shepherd-socket-file))
  67. #t)
  68. ((> i 0)
  69. (sleep 1)
  70. (loop (- i 1)))
  71. (else
  72. 'failure))))
  73. marionette))
  74. (test-assert "Nix daemon running"
  75. (marionette-eval
  76. '(begin
  77. ;; Wait for nix-daemon to be up and running.
  78. (start-service 'nix-daemon)
  79. (with-output-to-file "guix-test.nix"
  80. (lambda ()
  81. (display "\
  82. with import <nix/config.nix>;
  83. derivation {
  84. system = builtins.currentSystem;
  85. name = \"guix-test\";
  86. builder = shell;
  87. args = [\"-c\" \"mkdir $out\\necho FOO > $out/foo\"];
  88. PATH = coreutils;
  89. }
  90. ")))
  91. (zero? (system* (string-append #$nix "/bin/nix-build")
  92. "--substituters" "" "--debug" "--no-out-link"
  93. "guix-test.nix")))
  94. marionette))
  95. (test-end))))
  96. (gexp->derivation (string-append name "-test") test))
  97. (define %nix-os
  98. ;; Return operating system under test.
  99. (let ((base-os
  100. (simple-operating-system
  101. (service nix-service-type)
  102. (service dhcp-client-service-type))))
  103. (operating-system
  104. (inherit base-os)
  105. (packages (cons nix (operating-system-packages base-os))))))
  106. (define %test-nix
  107. (system-test
  108. (name "nix")
  109. (description "Connect to a running nix-daemon")
  110. (value (run-nix-test name %nix-os))))
  111. ;;; package-management.scm ends here