From patchwork Tue Jun 25 23:00:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pkill9 X-Patchwork-Id: 14390 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 487A117165; Wed, 26 Jun 2019 00:01:28 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id F022517163 for ; Wed, 26 Jun 2019 00:01:26 +0100 (BST) Received: from localhost ([::1]:35676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfuRI-0005Bw-C8 for patchwork@mira.cbaines.net; Tue, 25 Jun 2019 19:01:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55796) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfuQy-0005Bd-Vv for guix-patches@gnu.org; Tue, 25 Jun 2019 19:01:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfuQw-00085a-HX for guix-patches@gnu.org; Tue, 25 Jun 2019 19:01:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:48510) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hfuQw-000857-C6 for guix-patches@gnu.org; Tue, 25 Jun 2019 19:01:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hfuQw-0001CJ-8x for guix-patches@gnu.org; Tue, 25 Jun 2019 19:01:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#36382] A service for adding support for running portable binaries built for most linux distributions that use the filesystem hierarchy standard Resent-From: Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 25 Jun 2019 23:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 36382 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 36382@debbugs.gnu.org X-Debbugs-Original-To: "guix-patches" Received: via spool by submit@debbugs.gnu.org id=B.15615036524078 (code B ref -1); Tue, 25 Jun 2019 23:01:02 +0000 Received: (at submit) by debbugs.gnu.org; 25 Jun 2019 23:00:52 +0000 Received: from localhost ([127.0.0.1]:33821 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hfuQl-00013F-Ue for submit@debbugs.gnu.org; Tue, 25 Jun 2019 19:00:52 -0400 Received: from lists.gnu.org ([209.51.188.17]:53532) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hfuQi-00010D-IQ for submit@debbugs.gnu.org; Tue, 25 Jun 2019 19:00:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55255) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfuQg-0005B8-Ly for guix-patches@gnu.org; Tue, 25 Jun 2019 19:00:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfuQe-0007Nw-MB for guix-patches@gnu.org; Tue, 25 Jun 2019 19:00:46 -0400 Received: from aibo.runbox.com ([91.220.196.211]:57044) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hfuQd-0007Gt-Tl for guix-patches@gnu.org; Tue, 25 Jun 2019 19:00:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=rbselector1; h=Message-Id:Content-Type:Date:Subject:To:From:MIME-Version; bh=FgUPxMnTy/PfLWtQaaHYWRAlsteGZhz9Kx70gohXupM=; b=o54uezfFXbJ79gBU9bjNIL9NC Oc5Li4iKMwvMYCQJLZZteEM7x1K1gc+6Ib9yxejBYGo1QqnLq02LVhSGgXhrP3r+URyX/9WoDx1mY aOvx8ySqDttXgcXc99TtqwVBShqwbXoVmLfUDj8w7/VR9mdi2x14rJMs2IzQR4i6NGuBixS2mZzVP a6nOPX2Yy4k017EiNTYXXXypCcLhTcvdO57K97xXTPIBc1vBf4kJfPCbhTLpj26T7SywrTpRWzBCq IRfvNSrEuIeTgnmdAC+LnwzNJLPSsSX/yOQiuydxGAP0J1yk3Q9pK+Zy7ReBXi3N53qaUs1GP+eku KapkzU37w==; Received: from [10.9.9.128] (helo=rmmprod06.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1hfuQY-0007Z7-8L for guix-patches@gnu.org; Wed, 26 Jun 2019 01:00:38 +0200 Received: from mail by rmmprod06.runbox with local (Exim 4.86_2) (envelope-from ) id 1hfuQY-00072D-74 for guix-patches@gnu.org; Wed, 26 Jun 2019 01:00:38 +0200 MIME-Version: 1.0 Received: from [Authenticated alias (780724)] by runbox.com with http (RMM6); for ; Tue, 25 Jun 2019 23:00:38 GMT From: Date: Wed, 26 Jun 2019 00:00:38 +0100 (BST) X-Mailer: RMM6 Message-Id: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Hi Guix, for a while now I have been using a service I wrote that allows you to run portable binaries, such as AppImages, which expect to be run on distros that respect the filesystem hierarchy standard i.e store required libraries in /usr, /lib, etc, which is most distros. I think it could be a valuable tool to have in Guix, as it allows you to run software that hasn't yet been packaged in Guix that is distributed as binaries by the author. Also, if builds are failing in Guix, it's useful to have the alternative - for example, calibre currently can't be built due to build failure of a dependency (qtwebkit), so I use the Calibre tar bundle distributed by the website for now. This still requires some work before it's ready for inclusion in Guix - decisions on how it's implemented need to be made, and the code needs cleanup. But if I don't submit it in it's imperfect state, i won't get anything done on it. I've done a little writeup on how it works here: http://miha.info/2019/June/24/guix-fhs-service I've attached a patch for it. To build a guix system with it, add to the guix system services: (service fhs-binaries-compatibility-service-type (fhs-configuration (lib-packages ) (additional-special-files ) (additional-profile-packages ))) The additional-special-files and additional-profile-packages are functionally exactly the same as using special-files-service-type and profile-service-type separately, it's purely for organising the config so the admin knows why those special files and profile packages were added. diff --git a/gnu/services/fhs.scm b/gnu/services/fhs.scm new file mode 100644 index 0000000..9ca6ab9 --- /dev/null +++ b/gnu/services/fhs.scm @@ -0,0 +1,140 @@ +(define-module (gnu services fhs) + #:use-module (ice-9 ftw) ;; for creating recursive list of directories of libs for FHS #:use-module (guix download) + #:use-module (srfi srfi-1) ;; For filter-map + #:use-module (guix records) ;; For defining record types + #:use-module (guix profiles) ;; for manifest-entries + #:use-module (gnu services) ;; For defining services + #:use-module (guix gexp) ;; For computed-file and other things + #:use-module (guix packages) ;; For package + #:use-module (gnu packages) ;; For specifications->manifest + #:use-module (gnu packages base) ;; For glibc + + #:export (fhs-binaries-compatibility-service-type + fhs-binaries-compatibility-service + fhs-configuration)) + +(define (32bit-package pkg) + (package (inherit pkg) + (name (string-append (package-name pkg) "-i686-linux")) + (arguments + `(#:system "i686-linux" + ,@(package-arguments pkg))))) + +(define glibc-for-fhs + (package (inherit glibc) + (name "glibc-for-fhs") ;; Maybe rename this to "glibc-with-ldconfig-for-fhs" + (source (origin + (inherit (package-source glibc)) + (snippet #f))))) ;; Re-enable ldconfig + + +(define (packages->ld.so.conf packages) + (computed-file + "ld.so.conf" + (with-imported-modules + `((guix build union) + (guix build utils)) + #~(begin + (use-modules (guix build union) + (guix build utils)) + (let* ((packages '#$packages) ;; Need to quote "#$packages" as #$packages tries to "apply" the first item to the rest, like a procedure. + (find-lib-directories-in-single-package + (lambda (package) + (find-files (string-append package "/lib") + (lambda (file stat) + ;; setting keyword "stat" to "stat" means it will follow + ;; symlinks, unlike what it's set to by default ("lstat"). + (eq? 'directory (stat:type stat))) + #:stat stat + #:directories? #t))) + (find-lib-directories-in-all-packages + (lambda (packages) + (apply append ;; Concatenate the directory lists from "map" into one list + (map (lambda (package) + (find-lib-directories-in-single-package package)) + packages)))) + (fhs-lib-dirs + (find-lib-directories-in-all-packages packages))) + (with-output-to-file + #$output + (lambda _ + (format #t + (string-join fhs-lib-dirs "\n")) + #$output))))))) + +(define (ld.so.conf->ld.so.cache ld-conf) + (computed-file "ld.so.cache" + (with-imported-modules `((guix build utils)) + #~(begin + (use-modules (guix build utils)) + (let* ((ldconfig (string-append #$glibc-for-fhs "/sbin/ldconfig"))) + (invoke ldconfig + "-X" ;; Don't update symbolic links + "-f" #$ld-conf ;; Use #$configuration as configuration file + "-C" #$output)))))) ;; Use #$output as cache file + +(define (packages->ld.so.cache packages) + (ld.so.conf->ld.so.cache (packages->ld.so.conf packages))) + +(define-record-type* + fhs-configuration + make-fhs-configuration + fhs-configuration? + (lib-packages fhs-configuration-lib-packages + (default '())) + (additional-profile-packages fhs-configuration-additional-profile-packages ;; For putting programs in $PATH and for share data + (default '())) + (additional-special-files fhs-configuration-additional-special-files + (default '()))) + +(define* (union name packages #:key options) + (computed-file name + (with-imported-modules `((guix build union)) + #~(begin + (use-modules (guix build union)) + (union-build #$output '#$packages))) + #:options options)) + +(define* (fhs-libs-union packages #:key system) + (let* ((name (if system + (string-append "fhs-libs-" system) + "fhs-libs"))) + (union name + packages + #:options `(#:system ,system)))) + +(define (fhs-special-files-service config) + "Return the list of special files for the fhs service" + (let* ((fhs-lib-packages (fhs-configuration-lib-packages config)) + (fhs-lib-package-unions (append fhs-lib-packages + `(,(fhs-libs-union fhs-lib-packages #:system "i686-linux")))) + (fhs-glibc-special-files + `(("/etc/ld.so.cache" ,(packages->ld.so.cache fhs-lib-package-unions)) + ("/etc/ld.so.conf" ,(packages->ld.so.conf fhs-lib-package-unions)) ;;Not needed to function, but put it here anyway for debugging purposes + ("/lib64/ld-linux-x86-64.so.2" ,(file-append (canonical-package glibc-for-fhs) "/lib/ld-linux-x86-64.so.2")) + ("/lib/ld-linux.so.2" ,(file-append (canonical-package (32bit-package glibc-for-fhs)) "/lib/ld-linux.so.2")))) + ;; ("/fhs/libs" ,(file-append (canonical-package fhs-libs-64) "/lib")) + (fhs-additional-special-files (fhs-configuration-additional-special-files config))) + (append fhs-glibc-special-files + fhs-additional-special-files))) + +(define (fhs-profile-service config) + "Return the list of packages to add to the system profile" + ;; Get list of packages from config to add to system profile and return them + (fhs-configuration-additional-profile-packages config)) + + +(define fhs-binaries-compatibility-service-type + (service-type (name 'fhs-compatibility-service) + (extensions + (list (service-extension special-files-service-type + fhs-special-files-service) + (service-extension profile-service-type + fhs-profile-service) + )) + (description + "Support binaries compiled for the filesystem hierarchy standard.") + (default-value (fhs-configuration)))) + +(define fhs-binaries-compatibility-service + (service fhs-binaries-compatibility-service-type))