Hi Guix
I have problems of finding a reliable way to access the current
directory from a guile script.
My setup is the following: I have a channels.scm file and a manifest.scm
file at my project root directory. Additionally I have
.guix/modules/my-package.scm file describing my package, which I
reference in my manifest file like
(package->development-manifest (load "guix.scm"))
where guix.scm is a symlink to .guix/modules/my-package.scm.
Now in .guix/modules/my-package.scm I want to have the absolute path of
my project root. I used to use
(define %source-dir (string-append (current-source-directory) "/../.."))
which works fine until you call something like this:
guix time-machine -C channels.scm -- repl manifest.scm
in the project root. This fails because current-source-directory returns
the path to the manifest.scm file. Now I started to use
(define %source-dir (canonicalize-path (dirname (dirname (dirname
(current-filename))))))
and this seemed to work fine until I included the package as a
dependency into another package where it fails with the (not helpful at
all) error message
In procedure scm_to_utf8_stringn: Wrong type argument in position 1
(expecting string): #f
which seems to stem from the factthat current-filename resolved to #f
and dirname threw an exception
Now I am using
(define %source-dir (or (canonicalize-path (dirname (dirname (dirname
(current-filename)))))
(string-append (current-source-directory)
"/../..")))
which covers my two needs, but it just feels ridiculously. Is there no
easy and reliable way to get the path of the current script in guile?
Best,
Reza