Re: Module unavailable on build side

2024-01-14 Thread Attila Lendvai
this may help:

https://github.com/attila-lendvai/guix-crypto/blob/main/src/guix-crypto/service-utils.scm#L56

and you should grep for its use in that repo.

w-i-m ensures that the GEXP's that are instantiated in its dynamic extent will 
"capture" these modules as their dependencies, and i think it also inserts the 
appropriate use-modules forms at the head of the GEXP's.

but take this all with a grain of salt, because what i understand i decoded on 
my own from the guix codebase, and the names of these abstractions are rather 
misleading.

also, i'm using these in the service code that gets compiled for shepherd to be 
loaded. the environment surrounding the building of packages may behave 
differently.

HTH,

-- 
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“There is no difference between living and learning […] it is impossible and 
misleading and harmful to think of them as being separate.”
— John Holt (1923–1985)




Re: Module unavailable on build side

2024-01-14 Thread Tomas Volf
Hi,

On 2024-01-13 20:12:38 -0800, Felix Lechner via Development of GNU Guix and the 
GNU System distribution. wrote:
> Hi,
> 
> How may I make code from a channel available inside 'modify-phases',
> please?
> 
> I tried #:modules, but it says "no code for (x y z)." Thanks!

Based on some quick experimentation `source-module-closure' seems to be the way.
Package definition importing a (nonguix licenses) module follows:

(use-modules (guix build-system gnu)
 (guix gexp)
 (guix modules)
 (guix packages)
 (nongnu packages linux))

(package
  (name "test")
  (version "1")
  (source #f)
  (build-system gnu-build-system)
  (arguments
   (list #:imported-modules
 (source-module-closure `((nonguix licenses)
  ,@%gnu-build-system-modules)
#:select? (λ (m)
(or (guix-module-name? m)
(eq? (car m) 'nonguix
 #:phases
 #~(modify-phases %standard-phases
 (add-before 'unpack 'foo
   (λ _
 (use-modules (nonguix licenses))
 (error nonfree))
  (home-page #f)
  (synopsis #f)
  (description #f)
  (license #f))

This does "build" resulting in the expected error:

ice-9/boot-9.scm:1685:16: In procedure raise-exception:
#

However it took me a while to find a module that actually works.  Due to the web
of dependencies, it can get complex quickly and you would need to properly
manage the #:select? value.  Just putting (const #t) in there sadly does not
work.

Not sure, maybe there is a better way.  If there is, I hope someone will tell me
(us).

In the mean time, I hope this helps to some degree.

Have a nice day,
Tomas Volf

PS: My understanding it that #:modules is equivalent to (use-modules), that is
why I used #:imported-modules to add them into the build environment first.

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.


signature.asc
Description: PGP signature