twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.85k stars 477 forks source link

chezmoi on snap doesn't support redirecting stdin and stdout #2486

Closed marcobox closed 1 year ago

marcobox commented 1 year ago

Describe the bug

The snap version of chezmoi (v2.25.0) has no access to stdin and stdout. This seems the same issue as #2364 unfortunately I couldn't reopen the bug.

To reproduce

$ which chezmoi
/snap/bin/chezmoi

$ chezmoi --version
chezmoi version v2.25.0, commit b3a8879e30a20134c9bef48646055e57aa78d8c5, built at 2022-10-13T14:01:32Z, built by goreleaser

$ cat .local/share/chezmoi/.chezmoi.yaml.tmpl
data:
  env_type: {{"test" | quote}}

$ ls  -la .local/share/chezmoi/.chezmoi.yaml.tmpl
-rw-rw-r-- 1 myuser myuser 117 Oct 23 23:37 .local/share/chezmoi/.chezmoi.yaml.tmpl

$ chezmoi --verbose execute-template --init < .local/share/chezmoi/.chezmoi.yaml.tmpl
chezmoi: read /dev/stdin: permission denied

If piping the input using cat it works:

$ cat .local/share/chezmoi/.chezmoi.yaml.tmpl | chezmoi execute-template --init
data:
  env_type: "test"

stdout is also affected:

$ chezmoi completion bash > test.txt
chezmoi: write /dev/stdout: permission denied

Expected behavior

Piping to files should work without the need to using cat.

Output of command with the --verbose flag

reported above

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.25.0, commit b3a8879e30a20134c9bef48646055e57aa78d8c5, built at 2022-10-13T14:01:32Z, built by goreleaser ok latest-version v2.25.0 ok os-arch linux/amd64 (Ubuntu 22.10 (Kinetic Kudu)) ok uname Linux valinor 5.19.0-23-generic #24-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct 14 15:39:57 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux ok go-version go1.19.2 (gc) ok executable /snap/chezmoi/533/chezmoi ok upgrade-method snap-refresh ok config-file no config file found warning source-dir ~/.local/share/chezmoi is a git working tree (dirty) ok suspicious-entries no suspicious entries 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 /usr/bin/zsh ok cd-args /usr/bin/zsh info diff-command not set ok edit-command found /usr/bin/vim ok edit-args /usr/bin/vim ok git-command found /usr/bin/git, version 2.37.2 ok merge-command found /usr/bin/vimdiff ok shell-command found /usr/bin/zsh ok shell-args /usr/bin/zsh info age-command age not found in $PATH ok gpg-command found /usr/bin/gpg, version 2.2.35 info pinentry-command not set info 1password-command op not found in $PATH info bitwarden-command bw 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 vault-command vault not found in $PATH info secret-command not set ```
twpayne commented 1 year ago

Sadly I think this is a problem with snap, and I'm not aware of anything that chezmoi can do about this. If you have any ideas, please say.

The only fix seems to be to use a different installation method to snap. There are many to chose from.

twpayne commented 1 year ago

Note that for this example:

stdout is also affected:

$ chezmoi completion bash > test.txt
chezmoi: write /dev/stdout: permission denied

You can use:

$ chezmoi completion bash -o test.txt
twpayne commented 1 year ago

On further investigation, this is a long-standing bug in snap. See https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1849753.

I'll add an FAQ entry.