From mboxrd@z Thu Jan 1 00:00:00 1970 From: Georgi Kirilov Subject: Re: A postinst equivalent in Guix? Date: Sat, 21 Jan 2017 16:39:23 +0200 Message-ID: <20170121143923.vdmmljvc3ngksuze@gmail.com> References: <87efzxakmi.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="3dj3oyita3embapq" Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cUwpM-00085J-2B for guix-devel@gnu.org; Sat, 21 Jan 2017 09:39:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cUwpJ-0000si-0Q for guix-devel@gnu.org; Sat, 21 Jan 2017 09:39:36 -0500 Content-Disposition: inline In-Reply-To: <87efzxakmi.fsf@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel@gnu.org --3dj3oyita3embapq Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit On Fri, Jan 20, 2017 at 03:09:25PM +0100, Ludovic Courtès wrote: > >> A program in a package I created is trying to access /var, but has no >> permissions. (Well, /gnu/store/.../var) > >First, you probably need to pass --localstatedir=/var to this package’s >configure state, since at run time it won’t be able to write to >/gnu/store/…/var anyway. > >Second, it will try and fail to create /var. The way to address that is >by simply commenting out or patching out the offending commands. See >for instance ‘avahi-localstatedir.patch’ or ‘mcron-install.patch’. That's what happened indeed. When I removed the writes to /var the build passed. But the programs in the package couldn't write to the system /var directory, since they expect /var/lib// to exist and be writable. Besides, writing to /var on a foreign distro may interfere with the same package installed natively there (if it is installed). >> is there anything in Guix that can do things at install time, like postinst >> scripts in Debian? > >No. There are “profile hooks” in (guix profiles) that are used to a >similar effect, for instance to assemble the ‘dir’ file that contains >pointers to Info documentation. This looks to me much better than the system-wide /var. It is not only user-specific, but generation-specific. Really nice mechanism. I tried to write a new hook, to scan the installed packages and if they have a /var/lib// inside, to create a writable copy in the user's profile, so the programs can write to it without interfering with anything on the system. It didn't work because the hook's output turned out to be immutable... Whatever chmod or chown I tried inside the hook, the files always ended up '-r--r--r-- root root' Why are these customizations immutable? I'm probably missing something, but nothing seems to depend on them. If there was a way to create a writable customization, that would be the perfect place to put /var directories. -- Regards, Georgi --3dj3oyita3embapq Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="var-lib-package.patch" --- profiles.scm 2017-01-21 16:30:02.436621423 +0200 +++ bak/profiles.scm 2017-01-21 16:29:06.631019582 +0200 @@ -516,6 +516,34 @@ (anym %store-monad entry-lookup-package (manifest-entries manifest))) +(define (var-lib-package manifest) + (define build + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils) + (srfi srfi-1) (srfi srfi-26) + (ice-9 ftw)) + (define profile-var-lib (string-append #$output "/var/lib")) + (define (package-var-libs top) + (let ((varlibdir (string-append top "/var/lib"))) + (map (cut string-append varlibdir "/" <>) + (or (scandir varlibdir (lambda (file) + (not (member file '("." ".."))))) '())))) + (define (install-var dir) + (copy-recursively dir profile-var-lib) + ;; the file mode ends up being overwritten: + ;; (chmod dir #o777) + ;; guixbuilder* users can't do chown: + ;; (chown dir 1000 100) + ) + (mkdir-p profile-var-lib) + (exit (every install-var + (append-map package-var-libs + '#$(manifest-inputs manifest))))))) + (gexp->derivation "var-lib" build + #:local-build? #t + #:substitutable? #f)) + (define (info-dir-file manifest) "Return a derivation that builds the 'dir' file for all the entries of MANIFEST." @@ -909,6 +937,7 @@ ;; This is the list of derivation-returning procedures that are called by ;; default when making a non-empty profile. (list info-dir-file + var-lib-package fonts-dir-file ghc-package-cache-file ca-certificate-bundle --3dj3oyita3embapq--