;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2015 David Thompson ;;; Copyright © 2020 Simon South ;;; Copyright © 2020 Mathieu Othacehe ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see
aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Danny Milosavljevic <dannym@scratchpost.org>
;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages pure)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix utils)
  #:use-module (guix build-system gnu)
  #:use-module (guix gexp)
  #:use-module (gnu packages)
  #:use-module (gnu packages llvm)
  #:use-module (gnu packages multiprecision))

(define-public pure
  (package
    (name "pure")
    (version "0.68")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "https://github.com/agraef/pure-lang/releases/"
                           "download/pure-" version "/"
                           "pure-" version ".tar.gz"))
       (sha256
        (base32
         "0px6x5ivcdbbp2pz5n1r1cwg1syadklhjw8piqhl63n91i4r7iyb"))))
    (build-system gnu-build-system)
    (arguments
     `(#:make-flags (list (string-append "LDFLAGS=-Wl,-rpath="
                                         (assoc-ref %outputs "out")
                                         "/lib"))
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'patch-llvm-lookup
           (lambda _
             (substitute* "configure"
               (("-lLLVM-[$][{]llvm_version[}]")
                "`$LLVMCONF --libs`"))
             #t)))))
    (inputs
     (list gmp llvm-3.5 mpfr))
    (home-page "https://agraef.github.io/pure-lang/")
    (synopsis "Programming Language")
    (description "@code{pure} is a programming language based on term
rewriting.  It offers equational definitions with pattern matching,
full symbolic rewriting capabilities, dynamic typing, eager and lazy
evaluation, lexical closures, built-in list and matrix support and
a C interface.")
    (license license:gpl3+)))
in . out) (match (primitive-fork) (0 (close in) ;; Join the user namespace. (call-with-input-file (user-namespace clone-pid) (lambda (port) (setns (port->fdes port) 0))) (write 'done out) (close out) (primitive-exit 0)) (fork-pid (close out) ;; Wait for the child process to join the namespace. (read in) (let ((result (and (equal? (readlink (user-namespace clone-pid)) (readlink (user-namespace fork-pid)))))) ;; Clean up. (waitpid clone-pid) (waitpid fork-pid) result)))))))) (when (not perform-container-tests?) (test-skip 1)) (test-equal "pivot-root" 'success! (match (socketpair AF_UNIX SOCK_STREAM 0) ((parent . child) (match (clone (logior CLONE_NEWUSER CLONE_NEWNS SIGCHLD)) (0 (dynamic-wind (const #t) (lambda () (close parent) (call-with-temporary-directory (lambda (root) (display "ready\n" child) (read child) ;wait for "go!" (let ((put-old (string-append root "/real-root"))) (mount "none" root "tmpfs") (mkdir put-old) (call-with-output-file (string-append root "/test") (lambda (port) (display "testing\n" port))) (pivot-root root put-old) ;; The test file should now be located inside the root directory. (write (and (file-exists? "/test") 'success!) child) (close child))))) (lambda () (primitive-exit 0)))) (pid (close child) (match (read parent) ('ready ;; Set up the UID/GID mapping so that we can mkdir on the tmpfs: ;; . (call-with-output-file (format #f "/proc/~d/setgroups" pid) (lambda (port) (display "deny" port))) (call-with-output-file (format #f "/proc/~d/uid_map" pid) (lambda (port) (format port "0 ~d 1" (getuid)))) (call-with-output-file (format #f "/proc/~d/gid_map" pid) (lambda (port) (format port "0 ~d 1" (getgid)))) (display "go!\n" parent) (let ((result (read parent))) (close parent) (and (zero? (match (waitpid pid) ((_ . status) (status:exit-val status)))) result))))))))) (test-equal "scandir*, ENOENT" ENOENT (catch 'system-error (lambda () (scandir* "/does/not/exist")) (lambda args (system-error-errno args)))) (test-equal "scandir*, ASCII file names" (scandir (dirname (search-path %load-path "guix/base32.scm")) (const #t) stringprocedure int (dynamic-func "creat" (dynamic-link)) (list '* int)))) (creat (string->pointer (string-append directory "/α") "UTF-8") #o644) (creat (string->pointer (string-append directory "/λ") "UTF-8") #o644) (let ((locale (setlocale LC_ALL))) (dynamic-wind (lambda () ;; Make sure that even in a C locale we get the right result. (setlocale LC_ALL "C")) (lambda () (match (scandir* directory) (((names . properties) ...) names))) (lambda () (setlocale LC_ALL locale)))))))) (test-assert "scandir*, properties" (let ((directory (dirname (search-path %load-path "guix/base32.scm")))) (every (lambda (entry name) (match entry ((name2 . properties) (and (string=? name2 name) (let* ((full (string-append directory "/" name)) (stat (lstat full)) (inode (assoc-ref properties 'inode)) (type (assoc-ref properties 'type))) (and (= inode (stat:ino stat)) (or (eq? type 'unknown) (eq? type (stat:type stat))))))))) (scandir* directory) (scandir directory (const #t) string (termios-input-speed termios) 0) (> (termios-output-speed termios) 0)))) (test-assert "tcsetattr" (let ((first (tcgetattr 0))) (tcsetattr 0 (tcsetattr-action TCSANOW) first) (equal? first (tcgetattr 0)))) (test-assert "terminal-window-size ENOTTY" (call-with-input-file "/dev/null" (lambda (port) (catch 'system-error (lambda () (terminal-window-size port)) (lambda args ;; Accept EINVAL, which some old Linux versions might return. (memv (system-error-errno args) (list ENOTTY EINVAL))))))) (test-assert "terminal-columns" (> (terminal-columns) 0)) (test-assert "terminal-columns non-file port" (> (terminal-columns (open-input-string "Join us now, share the software!")) 0)) (test-assert "terminal-rows" (> (terminal-rows) 0)) (test-assert "openpty" (let ((head inferior (openpty))) (and (integer? head) (integer? inferior) (let ((port (fdopen inferior "r+0"))) (and (isatty? port) (begin (close-port port) (close-fdes head) #t)))))) (test-equal "openpty + login-tty" '(hello world) (let ((head inferior (openpty))) (match (primitive-fork) (0 (dynamic-wind (const #t) (lambda () (setvbuf (current-input-port) 'none) (close-fdes head) (login-tty inferior) (write (read)) (read)) ;this gets EIO when HEAD is closed (lambda () (primitive-_exit 42)))) (pid (close-fdes inferior) (let ((head (fdopen head "r+0"))) (write '(hello world) head) (let ((result (read head))) (close-port head) (waitpid pid) result)))))) (test-assert "utmpx-entries" (match (utmpx-entries) (((? utmpx? entries) ...) (every (lambda (entry) (match (utmpx-user entry) ((? string?) ;; Ensure we have a valid PID for those entries where it ;; makes sense. (or (not (memv (utmpx-login-type entry) (list (login-type INIT_PROCESS) (login-type LOGIN_PROCESS) (login-type USER_PROCESS)))) (> (utmpx-pid entry) 0))) (#f ;might be DEAD_PROCESS #t))) entries)))) (test-assert "read-utmpx, EOF" (eof-object? (read-utmpx (%make-void-port "r")))) (unless (access? "/var/run/utmpx" O_RDONLY) (test-skip 1)) (test-assert "read-utmpx" (let ((result (call-with-input-file "/var/run/utmpx" read-utmpx))) (or (utmpx? result) (eof-object? result)))) (when (zero? (getuid)) (test-skip 1)) (test-equal "add-to-entropy-count" EPERM (call-with-output-file "/dev/urandom" (lambda (port) (catch 'system-error (lambda () (add-to-entropy-count port 77) #f) (lambda args (system-error-errno args)))))) (test-end) (false-if-exception (delete-file temp-file))