From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Pierre-Henry F." Subject: Re: Help defining a trivial package. Date: Wed, 04 Sep 2019 11:21:41 +0000 Message-ID: References: <87sgppfnha.fsf@ngyro.com> <87v9ug2dsu.fsf@ngyro.com> <87woeqywbx.fsf@ngyro.com> Reply-To: "Pierre-Henry F." Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="b1_f070f26daea0ab84378010dbb796ed53" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:36746) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5TMH-0007nE-Lj for help-guix@gnu.org; Wed, 04 Sep 2019 07:21:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5TMF-0007s2-8C for help-guix@gnu.org; Wed, 04 Sep 2019 07:21:53 -0400 Received: from mail4.protonmail.ch ([185.70.40.27]:42025) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i5TME-0007nR-Mv for help-guix@gnu.org; Wed, 04 Sep 2019 07:21:51 -0400 In-Reply-To: <87woeqywbx.fsf@ngyro.com> 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: Timothy Sample Cc: "help-guix@gnu.org" This is a multi-part message in MIME format. --b1_f070f26daea0ab84378010dbb796ed53 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable > import os, shutil, stat, subprocess, guix.build.utils > > # Unpack > source =3D _build_inputs["source"] > tar =3D _build_inputs["tar"] > lzip =3D _build_inputs["lzip"] > os.putenv("PATH", ":".join([tar + "/bin", lzip + "/bin"])) > subprocess.run(["tar", "--lzip", "-xvf", source]) > > # Configure > bash =3D _build_inputs["bash"] > python =3D _build_inputs["python"] > guix.build.utils.substitute("blog/bin/program", > [["/usr/bin/bash", bash + "/bin/bash"], > ["python3", python + "/bin/python3"]]) > > # Install > out =3D _outputs["out"] > os.chmod("blog/bin/program", 0o755) > shutil.copytree("blog", out) Excellent! It's exactly how I understand the thing now (same approach to understanding= as in SICP and CTM :-) ) I rebuild the package (Attachment: blog_v2.scm) you gave me and added trace= s so it gives this when you execute the thing: phf@f02c:~/programs/blog/guix$ guix build --keep-failed --verbosity=3D2= --file=3D./blog_v2.scm substitute: updating substitutes from 'https://ci.guix.gnu.org'... 100.= 0% building /gnu/store/yhmlzaa07rp324nkc888rbacw7yfarsc-blog-3.drv... blog/bin/ blog/bin/program blog/src/ blog/src/hello_world.py Start of build expression execution Show inputs %build-inputs =3D ( (lzip . /gnu/store/2kwysbg8f175gmqmsd5kjggmy6hvxi5k-lzip-1.20) (tar . /gnu/store/ipx79bfj2mrc8npj7s3qi3zri11jfhaw-tar-1.30) (source . /gnu/store/4xcgzx85274qy4k7yxzadnb7rrq4hfnd-release_3.tar= .lz) (bash . /gnu/store/y2c5x3xwfbdigdlbxzfbk2g15ayy56cx-bash-minimal-4.= 4.23) (python . /gnu/store/b7fqhszxl02g6pfm3vw6b3cjz472qrly-python-3.7.0)= ) Show outputs %outputs =3D ((out . /gnu/store/4s8ij47drq8avldf5fq7inpicrz8dasn-blog= -3)) Unpack source Reference interpreters available in the build Make executable available to the host system `blog/src/hello_world.py' -> `/gnu/store/4s8ij47drq8avldf5fq7inpicrz8da= sn-blog-3/src/hello_world.py' `blog/bin/program' -> `/gnu/store/4s8ij47drq8avldf5fq7inpicrz8dasn-blog= -3/bin/program' End of build expression execution successfully built /gnu/store/yhmlzaa07rp324nkc888rbacw7yfarsc-blog-3.d= rv The following graft will be made: /gnu/store/w90x2vyymw4ny4n1ii840s1iqw7xjf9h-blog-3.drv applying 1 graft for /gnu/store/w90x2vyymw4ny4n1ii840s1iqw7xjf9h-blog-3= .drv... grafting '/gnu/store/4s8ij47drq8avldf5fq7inpicrz8dasn-blog-3' -> '/gnu/= store/n4q3ppdqvpppfpm5glhq3cbfhybk1hs9-blog-3'... successfully built /gnu/store/w90x2vyymw4ny4n1ii840s1iqw7xjf9h-blog-3.d= rv /gnu/store/n4q3ppdqvpppfpm5glhq3cbfhybk1hs9-blog-3 It helped me bind the package spec and the execution. So, I'm trying to integrate Guix in my workflow and hopefully propagate tha= t to others. This is what I'm trying to achieve at minima: Assume: phf@f02c:~/programs/blog$ tree . =E2=94=9C=E2=94=80=E2=94=80 bin =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80 make_release =E2=94=82 =E2=94=94=E2=94=80=E2=94=80 program =E2=94=9C=E2=94=80=E2=94=80 guix =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80 blog.scm =E2=94=82 =E2=94=94=E2=94=80=E2=94=80 manifest.scm =E2=94=9C=E2=94=80=E2=94=80 notes =E2=94=82 =E2=94=94=E2=94=80=E2=94=80 guix_refcard.pdf =E2=94=9C=E2=94=80=E2=94=80 notes.org =E2=94=9C=E2=94=80=E2=94=80 releases =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80 release_1.tar.lz =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80 release_2.tar.lz =E2=94=82 =E2=94=94=E2=94=80=E2=94=80 release_3.tar.lz =E2=94=94=E2=94=80=E2=94=80 src =E2=94=94=E2=94=80=E2=94=80 hello_world.py Development: $ guix environment --manifest=3D./guix/manifest.scm --pure --container $ # Develop things. Add dependencies at will in manifest.scm Build release: $ ./deployment/make_release Built release: release_4.tar.lz Deployment: $ guix build --keep-failed --verbosity=3D2 --file=3D./blog.scm =E2=80=A6 /gnu/store/=E2=80=A6-blog-4 Test: $ /gnu/store/=E2=80=A6-blog-4/bin/program Hello world! What would be very helpful: - Define blog.scm such that ~$ guix environment blog~ has the same effe= ct as ~$ guix environment --manifest=3D./guix/manifest.scm --pure --contain= er~ - Define a package ~blog_executable.scm~ derived from ~blog.scm~ such t= hat ~$ guix package -i blog_executable~ has the same effect has ~$ guix build --file=3D./blog_v2.scm~, but actually install the thing= . ~blog_executable.scm~ is essentially ~blog.scm~ but stripped down to = the bare minimum to get the executable working. If all the above is true then I hope that we (multiple devs) can have the g= uarantee to have the same dev environment and a simple deployment build that's just = the development environment minus dev dependencies. With these things in place, a deployment should be deterministic and as sim= ple as a: $ guix package -i blog_executable To sum up, here are the questions I try to answer: - How to define ~blog.scm~ such that ~$ guix environment blog~ works? - How to define ~blog_executable.scm~ such that ~$ guix package -i blog= _executable~ works? Thanks! PHF PS: Python + quasiquotes =3D> I'm trying to replace Python with Racket when= ever I can :-) =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Original Me= ssage =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 On Tuesday, September 3, 2019 3:58 AM, Timothy Sample w= rote: > Hello, > > "Pierre-Henry F." contact@phfrohring.com writes: > > > Hello Tim ! > > I'm using a couple of hours here an there to try to rebuild the package= you gave me (Thank you for that :-) ). > > So far, I've built a very stupid but "working" package (see below if yo= u really want to ;-) ). > > Looks good so far! > > > Will answer on the mailing list for others to benefit from this exchang= e. > > I=E2=80=99ve added the mailing list back in, then. ;) > > > Needless to say, it's not exactly obvious to figure these things out /a= priori/. > > For sure. By using the trivial build system, you=E2=80=99re working at a = pretty > low level. It=E2=80=99s especially tough to learn both Guix and Guile at = the > same time. For your reference, here=E2=80=99s a sketch of what the = =E2=80=9C#:builder=E2=80=9D > code would look like if it were Python: > > import os, shutil, stat, subprocess, guix.build.utils > > # Unpack > source =3D _build_inputs["source"] > tar =3D _build_inputs["tar"] > lzip =3D _build_inputs["lzip"] > os.putenv("PATH", ":".join([tar + "/bin", lzip + "/bin"])) > subprocess.run(["tar", "--lzip", "-xvf", source]) > > # Configure > bash =3D _build_inputs["bash"] > python =3D _build_inputs["python"] > guix.build.utils.substitute("blog/bin/program", > [["/usr/bin/bash", bash + "/bin/bash"], > ["python3", python + "/bin/python3"]]) > > # Install > out =3D _outputs["out"] > os.chmod("blog/bin/program", 0o755) > shutil.copytree("blog", out) > > Here, =E2=80=9C_build_inputs=E2=80=9D and =E2=80=9C_outputs=E2=80=9D are = set by Guix, and are > dictionaries. For =E2=80=9C_build_inputs=E2=80=9D, the keys are the strin= gs you put in > the =E2=80=9Cinputs=E2=80=9D part of the package, and the values are the = paths where the > packages are installed. So, =E2=80=9C_build_inputs["python"]=E2=80=9D poi= nts to the > directory in the store where Python is installed. We usually only have > one output, which is called =E2=80=9Cout=E2=80=9D. This is the path in th= e store where > we install the package being built. > > The only other thing is that =E2=80=9Cguix.build.utils.substitute= =E2=80=9D is basically > just find-and-replace. It takes the name of a file and a list of > two-element lists and replaces all the occurrences of the first elements > in the file with their corresponding second elements. > > Obviously the Guile interfaces are a little different, but hopefully > this Rosetta Stone makes it easier to see what=E2=80=99s going on. > > As an aside, ever since I learned that there=E2=80=99s a way to do quasiq= uotes > in Python [1], I=E2=80=99ve wondered how strange it would be if Guix were > written in Python. Pretty strange! :) > > [1] https://macropy3.readthedocs.io/en/latest/reference.html#quasiquote > > > Anyway, thanks! > > You=E2=80=99re welcome! > > -- Tim --b1_f070f26daea0ab84378010dbb796ed53 Content-Type: text/x-scheme; name="blog_v2.scm" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=blog_v2.scm KHVzZS1tb2R1bGVzICgoZ251IHBhY2thZ2VzIGJhc2UpICM6c2VsZWN0ICh0YXIpKQogICgoZ251 IHBhY2thZ2VzIGJhc2gpICM6c2VsZWN0IChiYXNoLW1pbmltYWwpKQogICgoZ251IHBhY2thZ2Vz IGNvbXByZXNzaW9uKSAjOnNlbGVjdCAobHppcCkpCiAgKChnbnUgcGFja2FnZXMgcHl0aG9uKSAj OnNlbGVjdCAocHl0aG9uKSkKICAoZ3VpeCkKICAoZ3VpeCBidWlsZC1zeXN0ZW0gdHJpdmlhbCkp CgoKCgoocGFja2FnZQogIChuYW1lICJibG9nIikKICAodmVyc2lvbiAiMyIpCiAgKHNvdXJjZQog ICAgKG9yaWdpbgogICAgICAobWV0aG9kIHVybC1mZXRjaCkKICAgICAgKHVyaSAoc3RyaW5nLWFw cGVuZCAiZmlsZTovLy9ob21lL3BoZi9wcm9ncmFtcy9ibG9nL3JlbGVhc2VzL3JlbGVhc2VfIiB2 ZXJzaW9uICIudGFyLmx6IikpCiAgICAgIChzaGEyNTYKICAgICAgICAoYmFzZTMyCiAgICAgICAg ICAiMXk4MTliNTNrc3lhczZhc2xkeXNyMHI4cDczbjVpOGlwYnBtYmdqcmZ4OHF6OGN5MnpzeCIp KSkpCiAgKGJ1aWxkLXN5c3RlbSB0cml2aWFsLWJ1aWxkLXN5c3RlbSkKICAoYXJndW1lbnRzCiAg ICBgKCM6bW9kdWxlcyAoKGd1aXggYnVpbGQgdXRpbHMpKQogICAgICAgIzpidWlsZGVyCiAgICAg ICAoYmVnaW4KCiAgICAgICAgICh1c2UtbW9kdWxlcyAoZ3VpeCBidWlsZCB1dGlscykpCgoKICAg ICAgICAgKG5ld2xpbmUpCiAgICAgICAgIChkaXNwbGF5ICJTdGFydCBvZiBidWlsZCBleHByZXNz aW9uIGV4ZWN1dGlvbiIpCiAgICAgICAgIChuZXdsaW5lKQogICAgICAgICAobmV3bGluZSkKCgoK ICAgICAgICAgKGRpc3BsYXkgIlNob3cgaW5wdXRzIikKICAgICAgICAgKG5ld2xpbmUpCiAgICAg ICAgICgobGFtYmRhIChuYW1lIHZhbHVlKQogICAgICAgICAgICAoZGlzcGxheSAoc3RyaW5nLWpv aW4gKGxpc3QgbmFtZSAiPSIgKGZvcm1hdCAjZiAifmEiIHZhbHVlKSAiXG4iKSkpKQogICAgICAg ICAgICIgICVidWlsZC1pbnB1dHMiICVidWlsZC1pbnB1dHMpCgoKCiAgICAgICAgIChuZXdsaW5l KQogICAgICAgICAoZGlzcGxheSAiU2hvdyBvdXRwdXRzIikKICAgICAgICAgKG5ld2xpbmUpCiAg ICAgICAgICgobGFtYmRhIChuYW1lIHZhbHVlKQogICAgICAgICAgICAoZGlzcGxheSAoc3RyaW5n LWpvaW4gKGxpc3QgbmFtZSAiPSIgKGZvcm1hdCAjZiAifmEiIHZhbHVlKSAiXG4iKSkpKQogICAg ICAgICAgICIgICVvdXRwdXRzIiAlb3V0cHV0cykKCgoKICAgICAgICAgKG5ld2xpbmUpCiAgICAg ICAgIChkaXNwbGF5ICJVbnBhY2sgc291cmNlIikKICAgICAgICAgKG5ld2xpbmUpCiAgICAgICAg IChsZXQgKChzb3VyY2UgKGFzc29jLXJlZiAlYnVpbGQtaW5wdXRzICJzb3VyY2UiKSkKICAgICAg ICAgICAgICAgICh0YXIgKGFzc29jLXJlZiAlYnVpbGQtaW5wdXRzICJ0YXIiKSkKICAgICAgICAg ICAgICAgIChsemlwIChhc3NvYy1yZWYgJWJ1aWxkLWlucHV0cyAibHppcCIpKSkKCiAgICAgICAg ICAgKHNldGVudiAiUEFUSCIgKHN0cmluZy1hcHBlbmQKICAgICAgICAgICAgICAgICAgICAgICAg ICAgIHRhciAiL2JpbiIKICAgICAgICAgICAgICAgICAgICAgICAgICAgICI6IgogICAgICAgICAg ICAgICAgICAgICAgICAgICAgbHppcCAiL2JpbiIpKQoKICAgICAgICAgICAoaW52b2tlICJ0YXIi ICItLWx6aXAiICIteHZmIiBzb3VyY2UpKQoKCiAgICAgICAgIChuZXdsaW5lKQogICAgICAgICAo ZGlzcGxheSAiUmVmZXJlbmNlIGludGVycHJldGVycyBhdmFpbGFibGUgaW4gdGhlIGJ1aWxkIikK ICAgICAgICAgKG5ld2xpbmUpCiAgICAgICAgIChsZXQgKChiYXNoIChhc3NvYy1yZWYgJWJ1aWxk LWlucHV0cyAiYmFzaCIpKQogICAgICAgICAgICAgICAgKHB5dGhvbiAoYXNzb2MtcmVmICVidWls ZC1pbnB1dHMgInB5dGhvbiIpKSkKICAgICAgICAgICAoc3Vic3RpdHV0ZSogImJsb2cvYmluL3By b2dyYW0iCiAgICAgICAgICAgICAoKCIvdXNyL2Jpbi9lbnYgYmFzaCIpIChzdHJpbmctYXBwZW5k IGJhc2ggIi9iaW4vYmFzaCIpKQogICAgICAgICAgICAgKCgicHl0aG9uMyIpIChzdHJpbmctYXBw ZW5kIHB5dGhvbiAiL2Jpbi9weXRob24zIikpKSkKCgoKICAgICAgICAgKG5ld2xpbmUpCiAgICAg ICAgIChkaXNwbGF5ICJNYWtlIGV4ZWN1dGFibGUgYXZhaWxhYmxlIHRvIHRoZSBob3N0IHN5c3Rl bSIpCiAgICAgICAgIChuZXdsaW5lKQogICAgICAgICAobGV0ICgob3V0IChhc3NvYy1yZWYgJW91 dHB1dHMgIm91dCIpKSkKICAgICAgICAgICAoY2htb2QgImJsb2cvYmluL3Byb2dyYW0iICNvNzc1 KQogICAgICAgICAgIChjb3B5LXJlY3Vyc2l2ZWx5ICJibG9nIiBvdXQpKQogICAgICAgICAobmV3 bGluZSkKCgoKICAgICAgICAgKG5ld2xpbmUpCiAgICAgICAgIChkaXNwbGF5ICJFbmQgb2YgYnVp bGQgZXhwcmVzc2lvbiBleGVjdXRpb24iKQogICAgICAgICAobmV3bGluZSkKICAgICAgICAgKG5l d2xpbmUpCiAgICAgICAgICkpKQoKICAoaW5wdXRzCiAgICBgKCgiYmFzaCIgLGJhc2gtbWluaW1h bCkKICAgICAgICgicHl0aG9uIiAscHl0aG9uKSkpCgogIChuYXRpdmUtaW5wdXRzCiAgICBgKCgi bHppcCIgLGx6aXApCiAgICAgICAoInRhciIgLHRhcikpKQoKICAoc3lub3BzaXMgI2YpCiAgKGRl c2NyaXB0aW9uICNmKQogIChob21lLXBhZ2UgI2YpCiAgKGxpY2Vuc2UgI2YpKQo= --b1_f070f26daea0ab84378010dbb796ed53--