From 9809055707de8c518e928e09ea76dd10fbc19a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Mon, 11 Jun 2012 21:50:17 +0200 Subject: Add a `%current-system' fluid. * guix/utils.scm (gnu-triplet->nix-system): New procedure. (%current-system): New variable. * tests/utils.scm ("gnu-triplet->nix-system"): New test. * tests/derivations.scm (%current-system): Remove. Update users to use (%current-system) instead. --- guix/utils.scm | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'guix/utils.scm') diff --git a/guix/utils.scm b/guix/utils.scm index 77ed9ce6ee..5415ab9e63 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -26,6 +26,7 @@ #:use-module (ice-9 format) #:autoload (ice-9 popen) (open-pipe*) #:autoload (ice-9 rdelim) (read-line) + #:use-module (ice-9 regex) #:use-module ((chop hash) #:select (bytevector-hash hash-method/sha256)) @@ -41,7 +42,9 @@ %nixpkgs-directory nixpkgs-derivation - memoize)) + memoize + gnu-triplet->nix-system + %current-system)) ;;; @@ -400,3 +403,29 @@ starting from the right of S." list))) (hash-set! cache args results) (apply values results))))))) + +(define (gnu-triplet->nix-system triplet) + "Return the Nix system type corresponding to TRIPLET, a GNU triplet as +returned by `config.guess'." + (let ((triplet (cond ((string-match "^i[345]86-(.*)$" triplet) + => + (lambda (m) + (string-append "i686-" (match:substring m 1)))) + (else triplet)))) + (cond ((string-match "^([^-]+)-([^-]+-)?linux-gnu.*" triplet) + => + (lambda (m) + ;; Nix omits `-gnu' for GNU/Linux. + (string-append (match:substring m 1) "-linux"))) + ((string-match "^([^-]+)-([^-]+-)?([[:alpha:]]+)([0-9]+\\.?)*$" triplet) + => + (lambda (m) + ;; Nix strip the version number from names such as `gnu0.3', + ;; `darwin10.2.0', etc., and always strips the vendor part. + (string-append (match:substring m 1) "-" + (match:substring m 3)))) + (else triplet)))) + +(define %current-system + ;; System type as expected by Nix, usually ARCHITECTURE-KERNEL. + (make-parameter (gnu-triplet->nix-system %host-type))) -- cgit v1.2.3