unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Find location of installed package in /gnu/store
@ 2021-05-15  2:28 Phil Beadling
  2021-05-15  8:28 ` Edouard Klein
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Phil Beadling @ 2021-05-15  2:28 UTC (permalink / raw)
  To: help-guix

Hi,

Given a package definition, eg icedtea-8's JDK, how can can I determine the
location of the installed package in my /gnu/store?

There doesn't seem to be anything on the package module itself, presumably
because this is static data, and what I need is something to calculate the
hash of the resulting install specific to my Guix?

eg
scheme@(guix-user) [3]> (package-outputs icedtea-8)
$8 = ("out" "jdk" "doc")
scheme@(guix-user) [3]>

I'd like to return this location using the package name or definition as an
input:
/gnu/store/i3vf1a49m0abcjqza19mb4mkjmc6k60n-icedtea-3.7.0-jdk/

The aim is to use this to derivive the JDK include directories in a generic
way for some scripts I'm writing, such that I don't need to update them
each time the JDK hash changes after a guix pull.

Cheers,
Phil.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Find location of installed package in /gnu/store
  2021-05-15  2:28 Find location of installed package in /gnu/store Phil Beadling
@ 2021-05-15  8:28 ` Edouard Klein
  2021-05-15 16:27   ` Phil Beadling
  2021-05-15  9:17 ` Björn Höfling
  2021-05-16  2:58 ` Maxim Cournoyer
  2 siblings, 1 reply; 5+ messages in thread
From: Edouard Klein @ 2021-05-15  8:28 UTC (permalink / raw)
  To: Phil Beadling; +Cc: help-guix

Hi !

This is where G-expressions will help you :)

Basically the path you need does not exist in the same "strata" as the
code of the package.

The following code will define a build-gexp function that evaluates a
G-expression and prints the resulting directory in the store. You can
try it in "guix repl" or with "guix build -f FILE"

https://guix.gnu.org/manual/en/guix.html#G_002dExpressions

A G-exp begins with #~ and withing the following expr, any piece of code
prefixed by #$ is recursively replaced by its value, but only if this
value is a primitive value (string, int,...) or a package.

If it is a package, it gets replaced by the path in the store of that
package.

So to give a short answer, run the following into the REPL to get your
path:
  (use-modules
     (guix gexp)
     (guix store)
     (guix derivations)
     (gnu packages java))
    (define (build-gexp gexp)
      "Build GEXP using the local daemon."
      (let ((derivation 
             (run-with-store (open-connection)
               (gexp->derivation
                "noname"
                gexp))))
        (build-derivations
         (open-connection)
         (list derivation))
        (derivation-output-path (assoc-ref (derivation-outputs derivation) "out"))))

(build-gexp
 (with-imported-modules '((guix build utils))
   #~(begin
       (use-modules (guix build utils))
       (mkdir-p  (string-append #$output "/bin"))
       (with-output-to-file (string-append #$output "/bin/helloworld.sh")
         (lambda _
           (display (string-append "Iced tea lives at:" #$icedtea-8)))))))


This wil output a path, in my case
/gnu/store/vv5sc5l488xxysyz88aadjj3fwnqr2xa-noname

and in it you'll have the file:
/gnu/store/vv5sc5l488xxysyz88aadjj3fwnqr2xa-noname/bin/helloworld.sh

which contains
Iced tea lives at:/gnu/store/vaqdvsqdv5mads38dp6pc5827pdgnmb3-icedtea-3.7.0

Given your stated use case, you may be interested in the following
upcoming patch:
https://issues.guix.gnu.org/48277

It will let you wrap any executable in the appropriate env vars, so I
guess you will be able to do something like
#$(wrap-in-search-paths #~(string-append #$output "/bin/your-script")
(list icedtea-8))

Hopefully icedtea-8 sets the correct search paths, but I believe it
does.

Cheers,

Edouard.

Phil Beadling writes:

> Hi,
>
> Given a package definition, eg icedtea-8's JDK, how can can I determine the
> location of the installed package in my /gnu/store?
>
> There doesn't seem to be anything on the package module itself, presumably
> because this is static data, and what I need is something to calculate the
> hash of the resulting install specific to my Guix?
>
> eg
> scheme@(guix-user) [3]> (package-outputs icedtea-8)
> $8 = ("out" "jdk" "doc")
> scheme@(guix-user) [3]>
>
> I'd like to return this location using the package name or definition as an
> input:
> /gnu/store/i3vf1a49m0abcjqza19mb4mkjmc6k60n-icedtea-3.7.0-jdk/
>
> The aim is to use this to derivive the JDK include directories in a generic
> way for some scripts I'm writing, such that I don't need to update them
> each time the JDK hash changes after a guix pull.
>
> Cheers,
> Phil.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Find location of installed package in /gnu/store
  2021-05-15  2:28 Find location of installed package in /gnu/store Phil Beadling
  2021-05-15  8:28 ` Edouard Klein
@ 2021-05-15  9:17 ` Björn Höfling
  2021-05-16  2:58 ` Maxim Cournoyer
  2 siblings, 0 replies; 5+ messages in thread
From: Björn Höfling @ 2021-05-15  9:17 UTC (permalink / raw)
  To: Phil Beadling; +Cc: help-guix

[-- Attachment #1: Type: text/plain, Size: 1486 bytes --]

On Sat, 15 May 2021 03:28:01 +0100
Phil Beadling <phil@beadling.co.uk> wrote:

> Given a package definition, eg icedtea-8's JDK, how can can I
> determine the location of the installed package in my /gnu/store?

[..]

> The aim is to use this to derivive the JDK include directories in a
> generic way for some scripts I'm writing, such that I don't need to
> update them each time the JDK hash changes after a guix pull.

In your store, there will be probably many icedtea-8's lying around,
because you or another user on your system updated it several times or
even compiled it with different sources.

Even when you say you want to to get the hash of what "guix pull"
currently has (see Edouard's answer), that might be different from what
is in your current profile, because you haven't executed yet a "guix
package -u", or you have several profiles around with different
versions/states.

From a practical perspective, what I have for the JDK: I put different
versions in different profiles, like:

guix package -i icedtea@3:jdk -p ~/extra-profiles/jdk8
guix package -i openjdk@11:jdk -p ~/extra-profiles/jdk11

(if you want to have the profile in your path, source it as the
command-output tells you, or at it to your bashrc)

Then I can set the JAVA_HOME variable to

JAVA_HOME=~/extra-profiles/jdk11

to use JDK 11. Also in Eclipse in the preferences, you can add
different installed JREs. I use this to point to my extra-profile.

Björn

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Find location of installed package in /gnu/store
  2021-05-15  8:28 ` Edouard Klein
@ 2021-05-15 16:27   ` Phil Beadling
  0 siblings, 0 replies; 5+ messages in thread
From: Phil Beadling @ 2021-05-15 16:27 UTC (permalink / raw)
  To: Edouard Klein, bjoern.hoefling; +Cc: help-guix

>
> Thanks for both answers on this - it's been an interesting rabbit hole.
> Edouard's script gave me the version of icedtea-8 exactly as sourced by:
>
guix environment --ad-hoc icedtea:jdk

I managed to simplify the script down to a one-liner - giving the same
version as Edourard's:
(display (run-with-store (open-connection) (package-file icedtea-8 #:output
"jdk")))

Bjoern was correct that this was not the version I was looking for - but
having rethought my dependency issue - I managed to solve it a different
way using substitute* to patch the relevent files at build-time.

Still, I learnt quite a bit about the gexps, the store, and patching - so
time well spent - thanks again :-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Find location of installed package in /gnu/store
  2021-05-15  2:28 Find location of installed package in /gnu/store Phil Beadling
  2021-05-15  8:28 ` Edouard Klein
  2021-05-15  9:17 ` Björn Höfling
@ 2021-05-16  2:58 ` Maxim Cournoyer
  2 siblings, 0 replies; 5+ messages in thread
From: Maxim Cournoyer @ 2021-05-16  2:58 UTC (permalink / raw)
  To: Phil Beadling; +Cc: help-guix

Hello Phil,

Phil Beadling <phil@beadling.co.uk> writes:

> Hi,
>
> Given a package definition, eg icedtea-8's JDK, how can can I determine the
> location of the installed package in my /gnu/store?
>
> There doesn't seem to be anything on the package module itself, presumably
> because this is static data, and what I need is something to calculate the
> hash of the resulting install specific to my Guix?

From the command line API, the way to retrieve a package's store file
name is by doing:

$ guix build package

> The aim is to use this to derivive the JDK include directories in a generic
> way for some scripts I'm writing, such that I don't need to update them
> each time the JDK hash changes after a guix pull.

If you prefer to use the Guix API from Guile, you could use something
like:

--8<---------------cut here---------------start------------->8---
(use-modules (guix derivations)
             (guix gexp)
             (guix store)
             (gnu packages base))

(let* ((hello-drv (with-store store
                    (run-with-store store (lower-object hello))))
       (hello-store-path (derivation->output-path hello-drv)))

  (format #t "~a~%" hello-store-path)
  hello-store-path)
--8<---------------cut here---------------end--------------->8---

HTH!

Maxim


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-16  2:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-15  2:28 Find location of installed package in /gnu/store Phil Beadling
2021-05-15  8:28 ` Edouard Klein
2021-05-15 16:27   ` Phil Beadling
2021-05-15  9:17 ` Björn Höfling
2021-05-16  2:58 ` Maxim Cournoyer

unofficial mirror of help-guix@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guix-user/0 guix-user/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guix-user guix-user/ https://yhetil.org/guix-user \
		help-guix@gnu.org
	public-inbox-index guix-user

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.gnu.guix.user
	nntp://news.gmane.io/gmane.comp.gnu.guix.user


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git