unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Cookbook recipe from "The Repository as a Channel" section does not work for Guix with properly configured GUILE_LOAD_PATH
@ 2024-08-13 12:45 Nigko Yerden
  2024-08-13 14:38 ` pelzflorian (Florian Pelz)
  2024-08-14 14:00 ` Attila Lendvai
  0 siblings, 2 replies; 30+ messages in thread
From: Nigko Yerden @ 2024-08-13 12:45 UTC (permalink / raw)
  To: guix-devel

Hello Guix!,

Consider a minimal test git repository [1] created in line with Cookbook
recommendations [2]. It has the following file structure:
      .
      ├── content
      ├── .guix-channel
      ├── guix.scm → .guix/modules/test-repo-package.scm
      └── .guix
          └── modules
             └── test-repo-package.scm

Here 'content' is a text file. '.guix-channel' includes
-----------------begin------------------------------------------------------------
(channel
   (version 0)
   (directory ".guix/modules"))
-----------------end--------------------------------------------------------------

and '.guix/modules/test-repo-package.scm' provides a package definition:
-----------------begin------------------------------------------------------------
(define-module (test-repo-package)
   #:use-module (guix packages)
   #:use-module (guix gexp)
   #:use-module (guix utils)
   #:use-module (guix git-download)
   #:use-module (guix build-system copy)
   #:use-module (guix licenses))

(define vcs-file?
   ;; Return true if the given file is under version control.
   (or (git-predicate (dirname (dirname (current-source-directory))))
       (const #t)))

(define-public test-repo
   (package
     (name "test-repo")
     (version "1.0")
     (source (local-file "../.." "test-repo-checkout"
			#:recursive? #t
			#:select? vcs-file?))
     (build-system copy-build-system)
     (arguments
      (list #:install-plan #~'(("content" "share/"))))
     (synopsis "Example: git repo as a package")
     (description "Example: git repo as a package")
     (home-page "https://example.com")
     (license gpl3+)))

test-repo
-----------------end--------------------------------------------------------------

All what this package does is to install 'content' file to
'/gnu/store/..../share/content' path. 'guix build -f guix.scm' command works as
expected. However, if we add the repository to the list of channels in
~/.config/guix/channels.scm file:
-----------------begin------------------------------------------------------------
(list ....
  (channel
   (name 'test-channel)
   (url "https://gitlab.com/anigko/test-channel.git")
   (branch "main")))
-----------------end--------------------------------------------------------------

and run 'guix pull', the command 'guix build test-repo' will fail with an error
message "No such file or directory 'content'" unless your GUILE_LOAD_PATH does
not include '~/.config/guix/current/share/guile/site/3.0/' path (this is the
path where a symlink to 'test-repo-package.scm' is installed by 'guix pull').

Normally GUILE_LOAD_PATH does include above-mentioned path. Indeed,
the GUIX System installer injects the following snippet
-----------------begin------------------------------------------------------------
eval "$(guix package --search-paths \
-p $HOME/.config/guix/current \
-p $HOME/.guix-profile \
-p /run/current-system/profile)"
-----------------end--------------------------------------------------------------
into '~/.bash_profile' file, setting many environment variables, and GUILE_LOAD_PATH
in particular. In this case '(local-file "../.." "test-repo-checkout" ...)' expression
is run from '~/.config/guix/current/share/guile/site/3.0/test-repo-package.scm' file,
which is a symlink. But '(local-file "../.." ...)' does not follow this symlink,
and the 'source' field of 'test-repo' package is evaluated to
'~/.config/guix/current/share/guile/site/', which is wrong of course.


Here is a workaround for this behavior. From the definition of 'local-file' in
guix/gexp.scm one can deduce that the executed relevant code is:

(absolute-file-name "../.." (current-source-directory))

Here '(current-source-directory)' evaluates to '~/.config/guix/current/share/guile/site/3.0/'.
However, if the symlink in '3.0/' directory would not target a file but another directory,
say 'test-repo', containing a file 'package.scm' with the package definition,
then '(current-source-directory)' will follow the symlink, that is what we want.

The branch 'alt' of [1] provides a realization of the workaround:
      .
      ├── content
      ├── .guix-channel
      ├── guix.scm → .guix/modules/test-repo/package.scm
      └── .guix
          └── modules
             └── test-repo
               └── package.scm

In comparison with 'test-repo-package.scm' file from 'main' branch, the 'package.scm'
file contains three modifications:

1.
(define-module (test-repo package)

2.
(define vcs-file?
   ;; Return true if the given file is under version control.
   (or (git-predicate (dirname (dirname (dirname (current-source-directory)))))
       (const #t)))

3.
     (source (local-file "../../.." "test-repo-checkout"
			#:recursive? #t
			#:select? vcs-file?))

Thus defined repository ensures that 'test-repo' package is built without errors on
systems with and without properly configured GUILE_LOAD_PATH.

Regards,
Nigko

[1] https://gitlab.com/anigko/test-channel.git
[2] https://guix.gnu.org/en/cookbook/en/html_node/The-Repository-as-a-Channel.html


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

end of thread, other threads:[~2024-08-29  6:17 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-13 12:45 Cookbook recipe from "The Repository as a Channel" section does not work for Guix with properly configured GUILE_LOAD_PATH Nigko Yerden
2024-08-13 14:38 ` pelzflorian (Florian Pelz)
2024-08-13 15:06   ` Nigko Yerden
2024-08-13 17:25     ` pelzflorian (Florian Pelz)
2024-08-13 17:49       ` Nigko Yerden
2024-08-14 15:35         ` pelzflorian (Florian Pelz)
2024-08-14 16:40           ` pelzflorian (Florian Pelz)
2024-08-14 19:29           ` pelzflorian (Florian Pelz)
2024-08-15  4:11             ` Nigko Yerden
2024-08-18 21:33               ` pelzflorian (Florian Pelz)
2024-08-19  7:43                 ` Nigko Yerden
2024-08-19 19:28                   ` pelzflorian (Florian Pelz)
2024-08-20  7:18                     ` Nigko Yerden
2024-08-20 16:49                       ` pelzflorian (Florian Pelz)
2024-08-22  4:45                         ` pelzflorian (Florian Pelz)
2024-08-22  9:53                           ` Nigko Yerden
2024-08-22 13:22                             ` Nigko Yerden
2024-08-22 16:00                             ` pelzflorian (Florian Pelz)
2024-08-23  5:07                               ` Nigko Yerden
2024-08-23 15:47                                 ` pelzflorian (Florian Pelz)
2024-08-23 16:25                                   ` pelzflorian (Florian Pelz)
2024-08-24 14:47                                   ` Nigko Yerden
2024-08-26  8:50                                     ` pelzflorian (Florian Pelz)
2024-08-28 12:36                                       ` Nigko Yerden
2024-08-28 16:40                                         ` pelzflorian (Florian Pelz)
2024-08-29  6:17                                           ` Nigko Yerden
2024-08-19  9:30                 ` Nigko Yerden
2024-08-19 16:17                 ` Nigko Yerden
2024-08-14 14:00 ` Attila Lendvai
2024-08-15 16:34   ` Nigko Yerden

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).