diff options
author | Ludovic Courtès <ludo@gnu.org> | 2012-06-11 21:50:17 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2012-06-11 21:50:17 +0200 |
commit | 9809055707de8c518e928e09ea76dd10fbc19a6a (patch) | |
tree | e8a1f8d619ee8bae7074f9f0561e39929ca4ca90 /guix/utils.scm | |
parent | b37eb5ede67f8f26dcbbb0d9c60050db10b63d00 (diff) | |
download | gnu-guix-9809055707de8c518e928e09ea76dd10fbc19a6a.tar gnu-guix-9809055707de8c518e928e09ea76dd10fbc19a6a.tar.gz |
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.
Diffstat (limited to 'guix/utils.scm')
-rw-r--r-- | guix/utils.scm | 31 |
1 files changed, 30 insertions, 1 deletions
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))) |