twpayne / chezmoi

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

chezmoi apply: "chezmoi: invalid argument" #2647

Closed avh4 closed 1 year ago

avh4 commented 1 year ago

Describe the bug

I'm setting up chezmoi on a new computer. chezmoi init ssh://git@... succeeded, and chezmoi status and chezmoi diff show the correct, expected output. But chezmoi apply immediately dies with "chezmoi: invalid argument".

To reproduce

# Boot new computer and log in as non-root user
chezmoi init ssh://git@myserver/user/dotfiles.git
chezmoi apply

Expected behavior

chezmoi apply should succeed (or print a helpful error message if there is actually something wrong)

Output of command with the --verbose flag

$ chezmoi --verbose --debug apply
2022-12-27T20:16:42-08:00 INF persistentPreRunRootE args=["chezmoi","apply","--debug","--verbose"] goVersion=go1.19.4 version={"builtBy":"nixpkgs","commit":"","date":"","version":"2.28.0"}
2022-12-27T20:16:42-08:00 INF Stat component=system name=/home/user/.config/chezmoi/chezmoistate.boltdb
2022-12-27T20:16:42-08:00 INF Stat component=system name=/home/user/.local/share/chezmoi
2022-12-27T20:16:42-08:00 INF Stat component=system name=/home/user/.local/share/chezmoi/.git
2022-12-27T20:16:42-08:00 ERR ReadFile error="open /home/user/.local/share/chezmoi/.chezmoiroot: no such file or directory" component=system data= name=/home/user/.local/share/chezmoi/.chezmoiroot size=0
2022-12-27T20:16:42-08:00 INF ReadDir component=system name=/home/user/.local/share/chezmoi
2022-12-27T20:16:42-08:00 ERR Mkdir error="mkdir /home/user/.config/chezmoi: file exists" component=system name=/home/user/.config/chezmoi perm=511
2022-12-27T20:16:42-08:00 INF Stat component=system name=/home/user/.config/chezmoi
2022-12-27T20:16:42-08:00 ERR Get error="invalid argument" bucket=configState component=persistentState key=configState value=
chezmoi: invalid argument

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE warning version v2.28.0, built by nixpkgs ok latest-version v2.28.0 ok os-arch linux/amd64 (NixOS 23.05 (Stoat)) ok uname Linux stagingmyhost 5.15.85 #1-NixOS SMP Wed Dec 21 16:36:38 UTC 2022 x86_64 GNU/Linux ok go-version go1.19.4 (gc) ok executable /nix/store/wgywfwi92jf116yxwzadjrryc49ir2jm-chezmoi-2.28.0/bin/chezmoi ok upgrade-method sudo-upgrade-package ok config-file no config file found 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 ok umask 022 ok cd-command found /run/current-system/sw/bin/bash ok cd-args /run/current-system/sw/bin/bash info diff-command not set ok edit-command found /run/current-system/sw/bin/nano ok edit-args /run/current-system/sw/bin/nano ok git-command found /run/current-system/sw/bin/git, version 2.38.1 warning merge-command vimdiff not found in $PATH ok shell-command found /run/current-system/sw/bin/bash ok shell-args /run/current-system/sw/bin/bash info age-command age not found in $PATH 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 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 ```

Additional context

twpayne commented 1 year ago

The "invalid argument" error is likely occurring when chezmoi tries to open its persistent state file. This uses BoltDB, which requires a filesystem that supports locking.

What's the output of mount? Is there anything non-standard about your machine?

avh4 commented 1 year ago

Ah, thanks, that solves it! I'm doing some trial runs of the install, and currently have /home mounted as a shared drive.

For reference, mount includes:

$ mount
...
staging-home on /home type 9p (rw,relatime,sync,dirsync,access=client,msize=16384,trans=virtio)

If I mount a different fs over ./config/chezmoi, then everything works :white_check_mark:

If the error had included something like "unable to acquire lock for ./config/chezmoi/chezmoistate.boltdb" that would have been helpful.