Hi,
first let me have a meta comment. Your client seems to embed \r characters (0x0D, CR) into your emails. Not sure if that is intentional. reza <r...@housseini.me> writes: > 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? I am not away of reliable way to get "path of the current script", however for use in Guix, there is fairly simple pattern to get a root of your repository. You just need to look for a known file unique to your setup. I am using something similar to the following: --8<---------------cut here---------------start------------->8--- (define %root ;; I am pretty sure this file will not be in any other directory. (dirname (dirname (canonicalize-path (search-path %load-path "my-system/files/channels.scm"))))) --8<---------------cut here---------------end--------------->8--- And then I am just basing everything on %root. Hope this helps, Tomas -- There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.