;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013 Nikita Karetnikov ;;; ;;; 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 . (define-module (wrap-program) #:use-module (guix packages) #:use-module (guix store) #:use-module (srfi srfi-26) #:export (store-location wrap-program)) (define (store-location package output rest) "Return a PACKAGE-related location." (string-append (package-output (open-connection) package output) rest)) (define (wrap-program program prefix? variable var-dir) "Copy PROGRAM to .PROGRAM-real and make PROGRAM a wrapper." (let* ((bin-location (store-location program "out" (string-append "/bin"))) ; not safe (program-name (package-name program)) (old (string-append bin-location "/" program-name)) (new (string-append bin-location "/." program-name "-real")) (tmp (string-append bin-location "/." program-name "-tmp"))) (define (change-variable) ;; Prepend VAR-DIR to VARIABLE or return VAR-DIR. (if prefix? (string-append var-dir ":$" variable) var-dir)) (copy-file old new) (call-with-output-file tmp (cut format <> "#!/bin/sh~%export ~a=\"~a\"~%exec ./~a \"address@hidden"~%" variable (change-variable) (basename new))) (chmod tmp #o755) (rename-file tmp old)))