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

Cannot apply my dotfiles on Termux #4268

Closed
3 tasks done
fleetingbytes opened this issue Feb 11, 2025 · 10 comments
Closed
3 tasks done

Cannot apply my dotfiles on Termux #4268

fleetingbytes opened this issue Feb 11, 2025 · 10 comments
Labels
support Support request

Comments

@fleetingbytes
Copy link
Contributor

fleetingbytes commented Feb 11, 2025

What exactly are you trying to do?

Using Termux in Android. I have cloned my dotfiles in ~/.local/share/chezmoi. I have run chezmoi init. When I run chezmoi --debug --verbose apply, I get this error:

time=2025-02-10T20:57:16.456Z level=INFO msg=persistentPreRunRootE version.version=2.59.1 version.commit=ca8fe5bfcb148741d2763d93ce0d562e04fa3ae3 version.date=2025-02-07T22:13:25Z version.builtBy=goreleaser args="[.local/bin/chezmoi --verbose --debug apply]" goVersion=go1.23.6
time=2025-02-10T20:57:16.456Z level=INFO msg=Stat component=system name=/data/data/com.termux/files/home/.config/chezmoi/chezmoistate.boltdb
time=2025-02-10T20:57:16.456Z level=INFO msg=Stat component=system name=/data/data/com.termux/files/home/.local/share/chezmoi
time=2025-02-10T20:57:16.456Z level=INFO msg=Stat component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/.git
time=2025-02-10T20:57:16.456Z level=INFO msg=chezmoi.OSRelease err="file does not exist"
time=2025-02-10T20:57:16.456Z level=INFO msg=ReadFile component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/.chezmoiroot size=5 data="home\n"
time=2025-02-10T20:57:16.458Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home
time=2025-02-10T20:57:16.458Z level=INFO msg=ReadFile component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/.chezmoi.toml.tmpl size=177 data="encryption = \"age\"\n\n[add]\n    secrets = \"error\"\n\n[age]\n    ident..."
time=2025-02-10T20:57:16.458Z level=ERROR msg=Mkdir component=system err="mkdir /data/data/com.termux/files/home/.config/chezmoi: file exists" name=/data/data/com.termux/files/home/.config/chezmoi perm=511
time=2025-02-10T20:57:16.458Z level=INFO msg=Stat component=system name=/data/data/com.termux/files/home/.config/chezmoi
time=2025-02-10T20:57:16.458Z level=INFO msg=Get component=persistentState bucket=configState key=configState value="{\n  \"configTemplateContentsSHA256\": \"61ae74048b54e78fab25a08226ab23572f3747a302443ed168803e42e9d74847\"\n}\n"
time=2025-02-10T20:57:16.458Z level=ERROR msg=ReadFile component=system err="open /data/data/com.termux/files/home/.local/share/chezmoi/.chezmoiversion: no such file or directory" name=/data/data/com.termux/files/home/.local/share/chezmoi/.chezmoiversion size=0 data=""
time=2025-02-10T20:57:16.458Z level=INFO msg=Stat component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home
time=2025-02-10T20:57:16.458Z level=INFO msg=Stat component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home
time=2025-02-10T20:57:16.458Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home
time=2025-02-10T20:57:16.458Z level=INFO msg=ReadFile component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/.chezmoiversion size=7 data="2.48.0\n"
time=2025-02-10T20:57:16.459Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/.chezmoidata
time=2025-02-10T20:57:16.459Z level=INFO msg=ReadFile component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/.chezmoidata/dynamic_configuration.toml size=22 data="dynconfig = \"default\"\n"
time=2025-02-10T20:57:16.459Z level=INFO msg=ReadFile component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/.chezmoiexternal.toml size=332 data="[\".vim/autoload/plug.vim\"]\n    type = \"file\"\n    url = \"https://..."
time=2025-02-10T20:57:16.461Z level=INFO msg=ReadFile component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/.chezmoiignore size=18 data="_*\n./**/README.md\n"
time=2025-02-10T20:57:16.463Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/.chezmoiscripts
time=2025-02-10T20:57:16.464Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/dot_config
time=2025-02-10T20:57:16.465Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/dot_config/bat
time=2025-02-10T20:57:16.465Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/dot_config/exact_git
time=2025-02-10T20:57:16.467Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/dot_config/yt-dlp
time=2025-02-10T20:57:16.467Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/dot_config/zdotdir
time=2025-02-10T20:57:16.468Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/dot_config/zdotdir/startup
time=2025-02-10T20:57:16.469Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/dot_local
time=2025-02-10T20:57:16.469Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/dot_local/bin
time=2025-02-10T20:57:16.469Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/dot_vim
time=2025-02-10T20:57:16.470Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/private_dot_ssh
time=2025-02-10T20:57:16.476Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/private_dot_ssh/github_deploy_keys
time=2025-02-10T20:57:16.502Z level=INFO msg=ReadDir component=system name=/data/data/com.termux/files/home/.config/git
time=2025-02-10T20:57:16.503Z level=ERROR msg=Lstat component=system err="lstat /data/data/com.termux/files/home/.local/share/zap: no such file or directory" name=/data/data/com.termux/files/home/.local/share/zap
time=2025-02-10T20:57:16.508Z level=INFO msg=ReadFile component=system name=/data/data/com.termux/files/home/.local/share/chezmoi/home/.chezmoiscripts/run_before_10_generate_dynamic_template.sh.tmpl size=385 data="#!/usr/bin/env sh\n\nconfiguration={{ .dynconfig | quote }}\ncfg_di..."
time=2025-02-10T20:57:16.532Z level=ERROR msg=Lstat component=system err="lstat /data/data/com.termux/files/home/.chezmoiscripts/10_generate_dynamic_template.sh: no such file or directory" name=/data/data/com.termux/files/home/.chezmoiscripts/10_generate_dynamic_template.sh
time=2025-02-10T20:57:16.532Z level=INFO msg=Get component=persistentState bucket=entryState key=/data/data/com.termux/files/home/.chezmoiscripts/10_generate_dynamic_template.sh value=""
time=2025-02-10T20:57:16.532Z level=INFO msg=defaultPreApplyFunc targetRelPath=.chezmoiscripts/10_generate_dynamic_template.sh targetEntryState.Type=script targetEntryState.Mode=0 targetEntryState.ContentsSHA256=97a8e2154a893d016215734b19ed8f322961864356fe352a762bf22b3b9458c3 lastWrittenEntryState=<nil> actualEntryState.Type=remove actualEntryState.Mode=0 actualEntryState.ContentsSHA256=""
diff --git a/.chezmoiscripts/10_generate_dynamic_template.sh b/.chezmoiscripts/10_generate_dynamic_template.sh
new file mode 100755
index 0000000000000000000000000000000000000000..1ffeb6b3ac006eee98409589c17420a9ac3fc326
--- /dev/null
+++ b/.chezmoiscripts/10_generate_dynamic_template.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env sh
+
+configuration="default"
+cfg_dir="/data/data/com.termux/files/home/.local/share/chezmoi/home/_dynamic"
+script="${cfg_dir}/configurator.py"
+input_file="${cfg_dir}/$configuration"
+output_file="${cfg_dir}/dyn_config.json"
+
+# The existence of python on the target system is ensured by bootstrap repository
+# and its `deploy_dotfiles.sh` script
+python "$script" "$input_file" "$output_file"
time=2025-02-10T20:57:16.554Z level=ERROR msg=Run err="fork/exec /data/data/com.termux/files/usr/tmp/1130146752.10_generate_dynamic_template.sh: no such file or directory" cmd=/data/data/com.termux/files/usr/tmp/1130146752.10_generate_dynamic_template.sh duration=3.33823ms err="fork/exec /data/data/com.termux/files/usr/tmp/1130146752.10_generate_dynamic_template.sh: no such file or directory"
time=2025-02-10T20:57:16.555Z level=ERROR msg=RunScript component=system err="fork/exec /data/data/com.termux/files/usr/tmp/1130146752.10_generate_dynamic_template.sh: no such file or directory" scriptName=.chezmoiscripts/10_generate_dynamic_template.sh dir=/data/data/com.termux/files/home/.chezmoiscripts data="#!/usr/bin/env sh\n\nconfiguration=\"default\"\ncfg_dir=\"/data/data/c..." interpreter="LogValue panicked\ncalled from runtime.panicmem (/opt/hostedtoolcache/go/1.23.6/x64/src/runtime/panic.go:262)\ncalled from runtime.sigpanic (/opt/hostedtoolcache/go/1.23.6/x64/src/runtime/signal_unix.go:917)\ncalled from github.com/twpayne/chezmoi/v2/internal/chezmoi.(*Interpreter).LogValue (/home/runner/work/chezmoi/chezmoi/internal/chezmoi/interpreter.go:30)\ncalled from log/slog.Value.Resolve (/opt/hostedtoolcache/go/1.23.6/x64/src/log/slog/value.go:512)\ncalled from log/slog.(*handleState).appendAttr (/opt/hostedtoolcache/go/1.23.6/x64/src/log/slog/handler.go:468)\n(rest of stack elided)\n" condition=always err="fork/exec /data/data/com.termux/files/usr/tmp/1130146752.10_generate_dynamic_template.sh: no such file or directory"
time=2025-02-10T20:57:16.556Z level=INFO msg=Close component=persistentState
chezmoi: .chezmoiscripts/10_generate_dynamic_template.sh: fork/exec /data/data/com.termux/files/usr/tmp/1130146752.10_generate_dynamic_template.sh: no such file or directory

Chezmoi doctor says:

RESULT    CHECK                       MESSAGE
ok        version                     v2.59.1, commit ca8fe5bfcb148741d2763d93ce0d562e04fa3ae3, built at 2025-02-07T22:13:25Z, built by goreleaser
failed    latest-version              Get "https://api.github.com/repos/twpayne/chezmoi/releases/latest": dial tcp: lookup api.github.com on [::1]:53: read udp [::1]:39480->[::1]:53: read: connection refused
ok        os-arch                     android/arm64
ok        uname                       Linux localhost 4.4.302-lineageos-g712f45433f52 #1 SMP PREEMPT Thu Feb 10 17:31:43 EST 2022 aarch64 Android
ok        go-version                  go1.23.6 (gc)
ok        executable                  ~/.local/bin/chezmoi
ok        upgrade-method              replace-executable
ok        config-file                 found ~/.config/chezmoi/chezmoi.toml, last modified 2025-02-10T20:14:43Z
ok        source-dir                  ~/.local/share/chezmoi is a git working tree (clean)
ok        suspicious-entries          no suspicious entries
ok        working-tree                ~/.local/share/chezmoi is a git working tree (clean)
ok        dest-dir                    ~ is a directory
warning   umask                       077
ok        cd-command                  found /data/data/com.termux/files/usr/bin/bash
ok        cd-args                     /data/data/com.termux/files/usr/bin/bash
info      diff-command                not set
ok        edit-command                found /data/data/com.termux/files/usr/bin/vi
ok        edit-args                   /data/data/com.termux/files/usr/bin/vi
ok        git-command                 found /data/data/com.termux/files/usr/bin/git, version 2.48.1
ok        merge-command               found /data/data/com.termux/files/usr/bin/vimdiff
ok        shell-command               found /data/data/com.termux/files/usr/bin/bash
ok        shell-args                  /data/data/com.termux/files/usr/bin/bash
warning   age-command                 found /data/data/com.termux/files/usr/bin/age, cannot parse version from (devel)
info      gpg-command                 gpg not found in $PATH
info      pinentry-command            not set
info      1password-command           op not found in $PATH
info      bitwarden-command           bw not found in $PATH
info      bitwarden-secrets-command   bws not found in $PATH
info      dashlane-command            dcli not found in $PATH
info      doppler-command             doppler not found in $PATH
info      gopass-command              gopass not found in $PATH
info      keepassxc-command           keepassxc-cli not found in $PATH
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      vlt-command                 vlt not found in $PATH
info      secret-command              not set

What have you tried so far?

I have tried to run termux-chroot which makes Termux behave as if it had classical Linux File Hierarchy System (FHS) (i.e. /bin, /usr, /tmp, /etc, ...). See here. This is useful for programs which require the classical Linux directories. This helps. With the Linux FHS I can apply my dotfiles, but in my case this later causes interoperability problems with other Termux software I use.

I was suspicious that the problem might be in the shebang of my script. So I created a test script with the same shebang (#!/usr/bin/env sh). It turns out the shebang is not the problem. Newer versions of Termux handle shebangs like this all right.

Then I was thinking that it does not find python, but this also is ok, python is available and found

Where else have you checked for solutions?

@fleetingbytes fleetingbytes added the support Support request label Feb 11, 2025
@bradenhilton
Copy link
Collaborator

Is dynconfig defined in your chezmoi data? Does it have the correct value? Are you able to manually execute the template of the script with execute-template? If that works, what happens if you save that result to a temporary script and run that outside of chezmoi?

@fleetingbytes
Copy link
Contributor Author

fleetingbytes commented Feb 11, 2025

dynconfig is correctly defined in .chezmoidata:

~/.../home/.chezmoidata $ eza --absolute
/data/data/com.termux/files/home/.local/share/chezmoi/home/.chezmoidata/dynamic_configuration.toml
~/.../home/.chezmoidata $ cat dynamic_configuration.toml
dynconfig = "default"

Executing any template at this moment is difficult, as all of my templates depend on the _dynamic/dyn_config.json being present. That's why the home/.chezmoiscripts/run_before_10_generate_dynamic_template.sh.tmpl needs to be executed at the beginning of the apply process.

But the template to generate the shell script which is run to generate the dyn_config.json can be executed. In fact it has been executed, as the x_trace shows. But here goes my manual template execution anyway:

~ $ .local/bin/chezmoi execute-template < ./.local/share/chezmoi/home/.chezmoiscripts/run_before_10_generate_dynamic_template.sh.tmpl
#!/usr/bin/env sh

configuration="default"
cfg_dir="/data/data/com.termux/files/home/.local/share/chezmoi/home/_dynamic"
script="${cfg_dir}/configurator.py"
input_file="${cfg_dir}/$configuration"
output_file="${cfg_dir}/dyn_config.json"

# The existence of python on the target system is ensured by bootstrap repository
# and its `deploy_dotfiles.sh` script
python "$script" "$input_file" "$output_file"

@fleetingbytes
Copy link
Contributor Author

fleetingbytes commented Feb 11, 2025

To address your other question:

I saved the script generated from the template in a tempfile.sh and executed it manually. It works. The tempfile.sh is populated with the correct values, it runs the python command which writes the file dyn_config.json which pretty much all my other templates depend on.

~ $ .local/bin/chezmoi execute-template < ./.local/share/chezmoi/home/.chezmoiscripts/run_before_10_generate_dynamic_template.sh.tmpl > tempfile.sh
~ $ chmod +x tempfile.sh
~ $ ./tempfile.sh
~ $ echo $?
0
~ $ cat .local/share/chezmoi/home/_dynamic/dyn_config.json
{
    "greeting": "Hello Sven",
    "config_name": "default",
    "env": "/data/data/com.termux/files/home/envs",
    "src": "/data/data/com.termux/files/home/src",
    "bootstrap_path": "/data/data/com.termux/files/home/src/bootstrap"
}

I believe the mechanics of my dynamic configuration generation procedure in the run_before script to be sound and not really the cause of the error here.

I have successfully deployed and applied these dotfiles on my FreeBSD desktop, on Raspberry Pi, on my Debian Linux work laptop, but it cannot be done in Termux on my mobile phone. Unless I fake the Linux FHS.

@fleetingbytes
Copy link
Contributor Author

On my FreeBSD machine the chezmoi --debug --verbose apply does not error out at that point:

time=2025-02-11T12:56:06.435+01:00 level=INFO msg=Run cmd=/tmp/3965898543.10_generate_dynamic_template.sh duration=40.935437ms err=<nil>
time=2025-02-11T12:56:06.435+01:00 level=INFO msg=RunScript component=system scriptName=.chezmoiscripts/10_generate_dynamic_template.sh dir=/home/tejul/.chezmoiscripts data="#!/usr/bin/env sh\n\nconfiguration=\"default\"\ncfg_dir=\"/home/tejul/..." interpreter="LogValue panicked\ncalled from runtime.panicmem (/opt/hostedtoolcache/go/1.23.4/x64/src/runtime/panic.go:262)\ncalled from runtime.sigpanic (/opt/hostedtoolcache/go/1.23.4/x64/src/runtime/signal_unix.go:917)\ncalled from github.com/twpayne/chezmoi/v2/internal/chezmoi.(*Interpreter).LogValue (/home/runner/work/chezmoi/chezmoi/internal/chezmoi/interpreter.go:30)\ncalled from log/slog.Value.Resolve (/opt/hostedtoolcache/go/1.23.4/x64/src/log/slog/value.go:512)\ncalled from log/slog.(*handleState).appendAttr (/opt/hostedtoolcache/go/1.23.4/x64/src/log/slog/handler.go:468)\n(rest of stack elided)\n" condition=always err=<nil>
time=2025-02-11T12:56:06.437+01:00 level=INFO msg=Set component=persistentState bucket=scriptState key=5837797faa6c2e5d5dcf5473cd2304f7adf346bab522da5a57ad582e1ad19aac value="{\n  \"name\": \".chezmoiscripts/10_generate_dynamic_template.sh\",\n  \"runAt\": \"2025-02-11T11:56:06.392841811Z\"\n}\n"
...

@twpayne
Copy link
Owner

twpayne commented Feb 11, 2025

chezmoi: .chezmoiscripts/10_generate_dynamic_template.sh: fork/exec /data/data/com.termux/files/usr/tmp/1130146752.10_generate_dynamic_template.sh: no such file or directory

https://www.chezmoi.io/user-guide/frequently-asked-questions/troubleshooting/#chezmoi-reports-forkexec-no-such-file-or-directory-when-running-scripts-on-nix-or-termux

@bradenhilton
Copy link
Collaborator

@twpayne is that already addressed by this in the initial post?

I was suspicious that the problem might be in the shebang of my script. So I created a test script with the same shebang (#!/usr/bin/env sh). It turns out the shebang is not the problem. Newer versions of Termux handle shebangs like this all right.

@twpayne
Copy link
Owner

twpayne commented Feb 11, 2025

@twpayne is that already addressed by this in the initial post?

I don't think so. I suspect that the problem is that Termux doesn't have sh, only bash.

@bradenhilton
Copy link
Collaborator

Ah, I see now. I was aware of this issue but I thought something might have changed as I haven't done anything with Termux for a while.

The shebang works:

$ cat hello.sh
#!/usr/bin/env sh

echo "hello"
$ ./hello.sh
hello

But it doesn't work when used in a run_ script:

$ mv hello.sh .local/share/chezmoi/run_hello.sh
$ chezmoi apply
chezmoi: hello.sh: fork/exec /data/data/com.termux/files/usr/tmp/1663789932.hello.sh: no such file or directory
$ mv .local/share/chezmoi/run_hello.sh .local/share/chezmoi/run_hello.sh.tmpl
$ sed -i '1s|^#!/usr/bin/env sh|#!{{ lookPath "sh" }}|' .local/share/chezmoi/run_hello.sh.tmpl
$ chezmoi apply
hello

@twpayne
Copy link
Owner

twpayne commented Feb 11, 2025

But it doesn't work when used in a run_ script:

#2345 (comment)

@fleetingbytes
Copy link
Contributor Author

Thank you very much. The lookPath solution works perfectly.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 19, 2025
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

No branches or pull requests

3 participants