Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify script executed from weird path (even when modify script is not templated) #2934

Closed
2 tasks done
VorpalBlade opened this issue Apr 18, 2023 · 3 comments · Fixed by #3518
Closed
2 tasks done
Labels
support Support request

Comments

@VorpalBlade
Copy link
Contributor

VorpalBlade commented Apr 18, 2023

What exactly are you trying to do?

I was trying to be smart and inspect the path to the modify script (in order to detect an associated data file located relative to it). My modify script is actually a config file being executed by a rust program:

#!/path/to/rust/program

some directives here;
ignore blah;
transform quux;

The idea was that the rust program would inspect the path to this modify_ "script" to locate additional data files. However, when chezmoi actually executes this script the path is something like: /tmp/3306499162.Trolltech.conf.

This would make sense if the modify script was templated (modify_blah.tmpl) as chezmoi would need to replace things in the file. But that is not the case here, it is NOT a template. How do I get the original path to this file? Do I simply have to accept that I can't, and make it a .tmpl and insert something like: source "{{ .chezmoi.sourceDir }}/{{ .chezmoi.sourceFile}}"?

Either way, I can't find where this behaviour is documented.

What have you tried so far?

Scratching my head at this (it is late local time...).

Where else have you checked for solutions?

Output of any commands you've tried with --verbose flag

Irrelevant without the whole setup of my rust program. But if you really want to try it I can setup a test case.

Output of chezmoi doctor

$ chezmoi doctor
RESULT    CHECK                MESSAGE
warning   version              v2.33.1, built at 2023-04-08T07:27:16Z
ok        latest-version       v2.33.1
ok        os-arch              linux/amd64 (Arch Linux)
ok        uname                Linux theseus 6.2.11-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 13 Apr 2023 16:59:24 +0000 x86_64 GNU/Linux
ok        go-version           go1.20.3 (gc)
ok        executable           /usr/bin/chezmoi
ok        config-file          ~/.config/chezmoi/chezmoi.yaml, last modified 2023-04-05T12:45:46+02:00
warning   source-dir           ~/.local/share/chezmoi is a git working tree (dirty)
warning   suspicious-entries   ~/.local/share/chezmoi/.chezmoi_modify_manager.add_hook
warning   working-tree         ~/.local/share/chezmoi is a git working tree (dirty)
ok        dest-dir             ~ is a directory
ok        umask                022
ok        cd-command           found /bin/zsh
ok        cd-args              /bin/zsh
info      diff-command         not set
ok        edit-command         found /usr/bin/code
ok        edit-args            code -w
ok        git-command          found /usr/bin/git, version 2.40.0
ok        merge-command        found /usr/bin/bcompare
ok        shell-command        found /bin/zsh
ok        shell-args           /bin/zsh
info      age-command          age not found in $PATH
ok        gpg-command          found /usr/bin/gpg, version 2.2.41
info      pinentry-command     not set
info      1password-command    op not found in $PATH
info      bitwarden-command    bw not found in $PATH
info      dashlane-command     dcli not found in $PATH
info      gopass-command       gopass not found in $PATH
ok        keepassxc-command    found /usr/bin/keepassxc-cli, version 2.7.4
info      keepassxc-db         not set
info      keeper-command       keeper not found in $PATH
info      lastpass-command     lpass not found in $PATH
info      pass-command         pass not found in $PATH
info      passhole-command     ph not found in $PATH
info      rbw-command          rbw not found in $PATH
info      vault-command        vault not found in $PATH
info      secret-command       not set

Additional context

Add any other context about the problem here.

@VorpalBlade VorpalBlade added the support Support request label Apr 18, 2023
@VorpalBlade
Copy link
Contributor Author

From the manual:

chezmoi sets a number of CHEZMOI* environment variables when running scripts, corresponding to commonly-used template data variables.

That could have been one way (if CHEZMOI_SOURCE_DIR and CHEZMOI_SOURCE_FILE had been set), except none of these appear to be set for modify_ scripts.

@twpayne
Copy link
Owner

twpayne commented Apr 18, 2023

chezmoi copies modify_ scripts to a file in a temporary directory, sets the executable bit on the file, and then executes them. This is needed even if the modify_ script is not a template as the executable bit is not set in the source directory.

How do I get the original path to this file? Do I simply have to accept that I can't, and make it a .tmpl and insert something like: source "{{ .chezmoi.sourceDir }}/{{ .chezmoi.sourceFile}}"?

Right now, you have to accept that you can't. Note that the .chezmoi.sourceFile template variable does not exist.

That could have been one way (if CHEZMOI_SOURCE_DIR and CHEZMOI_SOURCE_FILE had been set), except none of these appear to be set for modify_ scripts.

That was an oversight. Fixed in #2935.

@VorpalBlade
Copy link
Contributor Author

VorpalBlade commented Apr 18, 2023 via email

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
support Support request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants