From mboxrd@z Thu Jan 1 00:00:00 1970 From: Timothy Sample Subject: Re: Help defining a trivial package. Date: Thu, 29 Aug 2019 11:26:25 -0400 Message-ID: <87v9ug2dsu.fsf@ngyro.com> References: <87sgppfnha.fsf@ngyro.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:54691) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3MJh-0003Bu-0C for help-guix@gnu.org; Thu, 29 Aug 2019 11:26:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3MJf-0003tP-Cn for help-guix@gnu.org; Thu, 29 Aug 2019 11:26:28 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:35527) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i3MJf-0003sy-4b for help-guix@gnu.org; Thu, 29 Aug 2019 11:26:27 -0400 In-Reply-To: (Pierre-Henry F.'s message of "Thu, 29 Aug 2019 11:23:26 +0000") List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-guix-bounces+gcggh-help-guix=m.gmane.org@gnu.org Sender: "Help-Guix" To: "Pierre-Henry F." Cc: "help-guix@gnu.org" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Pierre, "Pierre-Henry F." writes: > So, we have, in ~bash~: > > $ lzip --decompress release_3.tar.lz > $ tar xf release_3.tar > $ cd blog/ # coming from the preceding line. > $ tree > . > =E2=94=9C=E2=94=80=E2=94=80 bin > =E2=94=82 =E2=94=94=E2=94=80=E2=94=80 program > =E2=94=94=E2=94=80=E2=94=80 src > =E2=94=94=E2=94=80=E2=94=80 hello_world.py > > $ cat src/hello_world.py > print("Hello world!") > > $ cat bin/program > #! /usr/bin/env bash > > script_path=3D"${BASH_SOURCE[0]}" > script_dir=3D"$(dirname $script_path)" > python3 "$script_dir/../src/hello_world.py" > > That's it. > > The idea is to build a Guix package that does exactly that. > Expected outcome: > > $ guix package -s blog > # fetch release_3.tar.lz > # uncompress ... > # ... > > $ program > Hello World! > > > My question: how to build that Guix package? I try to get something work= ing using > the docs. This is how the package looks to far: > > (use-modules > (guix packages) > (guix download) > (guix build-system trivial) > (guix licenses) > (guix gexp) > (gnu packages base) > (gnu packages python)) > > > ;; The "derivation" i.e. low level sequence of instructions that the bu= ild deamon is > ;; supposed to execute on the behalf of the user. > (define build-drv > (gexp->derivation > "the-thing" > #~(begin > (mkdir #$output) > (chdir #$output) > (symlink (string-append #$coreutils "/bin/ls") > "list-files")))) > > > (package > (name "blog") > (version "3") > (source > (origin > (method url-fetch) > (uri (string-append "/home/phf/programs/blog/releases/release_" v= ersion ".tar.lz")) > (sha256 > (base32 > "1y819b53ksyas6asldysr0r8p73n5i8ipbpmbgjrfx8qz8cy2zsx")))) > (build-system trivial-build-system) > (arguments `(#:builder ,build-drv)) > > (inputs `(("python" ,python))) > (synopsis "Guix 'hello world' to learn about Guix") > (description "Guess what GNU Hello prints!") > (home-page "http://www.gnu.org/software/hello/") > (license gpl3+)) > > Assuming everything else is correct, would you please help refine ~build-= drv~ until > it matches the ~bash~ above ? > > This is what the execution trace looks like: > > phf@f02c:~/tools/guix/packages$ guix build --keep-failed --verbosity=3D= 2 --file=3D./blog.scm > substitute: updating substitutes from 'https://ci.guix.gnu.org'... 100.= 0% > building /gnu/store/8b0gyazhgmc9rkrxir7vxpav0x28xk3d-blog-3.drv... > ERROR: In procedure primitive-load: > In procedure scm_lreadr: /gnu/store/zlbf2x6n4084v0cpw2rh9dydqmi5b2rn-bl= og-3-guile-builder:1:10: Unknown # object: #\< This error is because you can=E2=80=99t pass a derivation object as the =E2=80=9C#:builder=E2=80=9D argument. It has to be some quoted Scheme code= that can run in the build environment. I took a little time and wrote a package definition that matches your example. There are some things you could do to change your source code to make it more in-line with what Guix expects, but I didn=E2=80=99t do tha= t. I hope that an example dealing with what you have will be more helpful. I=E2=80=99ve attached the package definition I came up with (note that I ch= anged the URL of the tarball). --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=phf.scm Content-Description: phf.scm (use-modules ((gnu packages base) #:select (tar)) ((gnu packages bash) #:select (bash-minimal)) ((gnu packages compression) #:select (lzip)) ((gnu packages python) #:select (python)) (guix) (guix build-system trivial)) (package (name "blog") (version "3") (source (origin (method url-fetch) (uri (string-append "file:///tmp/phf/release_" version ".tar.lz")) (sha256 (base32 "1y819b53ksyas6asldysr0r8p73n5i8ipbpmbgjrfx8qz8cy2zsx")))) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) ;; Unpack (let ((source (assoc-ref %build-inputs "source")) (tar (assoc-ref %build-inputs "tar")) (lzip (assoc-ref %build-inputs "lzip"))) (setenv "PATH" (string-append tar "/bin" ":" lzip "/bin")) (invoke "tar" "--lzip" "-xvf" source)) ;; Configure (let ((bash (assoc-ref %build-inputs "bash")) (python (assoc-ref %build-inputs "python"))) (substitute* "blog/bin/program" (("/usr/bin/env bash") (string-append bash "/bin/bash")) (("python3") (string-append python "/bin/python3")))) ;; Install (let ((out (assoc-ref %outputs "out"))) (chmod "blog/bin/program" #o775) (copy-recursively "blog" out))))) (inputs `(("bash" ,bash-minimal) ("python" ,python))) (native-inputs `(("lzip" ,lzip) ("tar" ,tar))) (synopsis #f) (description #f) (home-page #f) (license #f)) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable The builder code imports the =E2=80=9C(guix build utils)=E2=80=9D module, w= hich has some really handy shell-like functions like =E2=80=9Cinvoke=E2=80=9D for running= programs, =E2=80=9Csubstitute*=E2=80=9D which is like =E2=80=9Csed -i=E2=80=9D, and = =E2=80=9Ccopy-recursively=E2=80=9D, which is like =E2=80=9Ccp -r=E2=80=9D. The =E2=80=9CUnpack=E2=80=9D section sets up the =E2=80=9CPATH=E2=80=9D var= iable for Tar, and then invokes =E2=80=9Ctar=E2=80=9D to unpack the tarball. The =E2=80=9CConfigure=E2=80=9D section replaces the references to Bash and= Python with their absolute paths in the Guix store. The =E2=80=9CInstall=E2=80=9D section makes the =E2=80=9Cprogram=E2=80=9D f= ile executable then copies the code into the Guix-provided output directory. I hope that makes sense and good luck! -- Tim --=-=-=--