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

chezmoi doctor reports config-file as failed if chezmoi is an alias #4181

Open
lyderic opened this issue Jan 4, 2025 · 7 comments · May be fixed by #4182
Open

chezmoi doctor reports config-file as failed if chezmoi is an alias #4181

lyderic opened this issue Jan 4, 2025 · 7 comments · May be fixed by #4182
Labels
bug Something isn't working

Comments

@lyderic
Copy link

lyderic commented Jan 4, 2025

Describe the bug

I have set up an alias to run chezmoi in a non-default location.

When I run the doctor command, the config-file is reported as failed.

To reproduce

  1. Set up an alias called che as follows:
$ export DIR="${HOME}/.second"
$ alias che='chezmoi --config "${DIR}/config/che.yaml" --cache "${DIR}/cache" --destination "${HOME}" --persistent-state "${DIR}/config/chestate.boltdb" --source "${DIR}/source"'
  1. Run the doctor command:
$ che doctor | grep failed
 failed    config-file                 found ~/.config/chezmoi/chezmoi.yaml, expected ~/.second/config/che.yaml

Please note that both config files exist:

$ chezmoi cat-config 
data:
  workstation: false
$ che cat-config
format: yaml

The chezmoi (unaliased) command is fine:

$ chezmoi doctor | grep config-file
ok        config-file                 ~/.config/chezmoi/chezmoi.yaml, last modified 2025-01-04T16:57:16Z

Expected behavior

I would expect the output of the alias to be similar as without the alias, i.e.:

$ che doctor | grep config-file
ok        config-file                 ~/.second/config/che.yaml, last modified 2025-01-04T16:57:16Z

Output of command with the --verbose flag

$ che doctor --verbose
RESULT    CHECK                       MESSAGE
warning   version                     v2.57.0, built at 2024-12-30T19:49:18Z
ok        latest-version              v2.57.0
ok        os-arch                     linux/amd64 (Arch Linux)
ok        uname                       Linux czbug 6.12.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 27 Dec 2024 14:24:37 +0000 x86_64 GNU/Linux
ok        go-version                  go1.23.4 (gc)
ok        executable                  /usr/bin/chezmoi
failed    config-file                 found ~/.config/chezmoi/chezmoi.yaml, expected ~/.second/config/che.yaml
ok        source-dir                  ~/.second/source is a git working tree (clean)
ok        suspicious-entries          no suspicious entries
ok        working-tree                ~/.second/source is a git working tree (clean)
ok        dest-dir                    ~ is a directory
ok        umask                       022
ok        cd-command                  found /bin/bash
ok        cd-args                     /bin/bash
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.47.1
ok        merge-command               found /usr/bin/vimdiff
ok        shell-command               found /bin/bash
ok        shell-args                  /bin/bash
info      age-command                 age not found in $PATH
ok        gpg-command                 found /usr/bin/gpg, version 2.4.7
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

Output of chezmoi doctor

RESULT    CHECK                       MESSAGE
warning   version                     v2.57.0, built at 2024-12-30T19:49:18Z
ok        latest-version              v2.57.0
ok        os-arch                     linux/amd64 (Arch Linux)
ok        uname                       Linux czbug 6.12.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 27 Dec 2024 14:24:37 +0000 x86_64 GNU/Linux
ok        go-version                  go1.23.4 (gc)
ok        executable                  /usr/bin/chezmoi
ok        config-file                 ~/.config/chezmoi/chezmoi.yaml, last modified 2025-01-04T16:57:16Z
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 /bin/bash
ok        cd-args                     /bin/bash
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.47.1
ok        merge-command               found /usr/bin/vimdiff
ok        shell-command               found /bin/bash
ok        shell-args                  /bin/bash
info      age-command                 age not found in $PATH
ok        gpg-command                 found /usr/bin/gpg, version 2.4.7
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

Additional context

Apart from this minor issue, it looks like the alias works well. It is very handy as it allows me to have two different sources for different purposes.

@halostatue
Copy link
Collaborator

halostatue commented Jan 4, 2025

Have you tried running doctor directly?

chezmoi \
  --config "$HOME/.second/config/che.yaml" \
  --cache "$HOME/.second/cache" \
  --destination "$HOME"
  --persistent-state "$HOME/config/chestate.boltdb" 
  --source "$HOME/.second/source" doctor

@twpayne twpayne added the bug Something isn't working label Jan 4, 2025
@twpayne twpayne linked a pull request Jan 4, 2025 that will close this issue
@twpayne
Copy link
Owner

twpayne commented Jan 4, 2025

Thanks for reporting this. This has nothing do with the alias, but is instead due to the --config flag. #4182 is an initial fix, but I need to carefully consider the implications of this.

@lyderic
Copy link
Author

lyderic commented Jan 5, 2025

Yes, this is not a problem with the alias indeed. I ran the command as halostatue suggested and I confirm I have the same behaviour.

I saw the changes you did in #1482. Although there are many of them, it looks like the --config flag works, only the reporting by doctor fails. However, now I am not sure I can use chezmoi with my alias as it's not "doctor approved" ;-) Do you reckon there's a risk of something breaking as some point because --config is unreliable?

More generally, is it possible (supported?) to run two chezmoi stacks on the same machine? If yes, is an alias the preferred solution?

Many thanks for looking into this.

@lyderic
Copy link
Author

lyderic commented Jan 5, 2025

FWIW, the other commands I could find that report the config file location are not faulty:

$ che data | grep configFile:
    configFile: /home/unix/.second/config/che.yaml
$ che cd
$ echo $CHEZMOI_CONFIG_FILE 
/home/unix/.second/config/che.yaml

@twpayne
Copy link
Owner

twpayne commented Jan 6, 2025

However, now I am not sure I can use chezmoi with my alias as it's not "doctor approved" ;-) Do you reckon there's a risk of something breaking as some point because --config is unreliable?

#4182 should make --config reliable.

There are corner cases related to #3127, #3486, and #3489 that I need to check before #4182 is merged.

More generally, is it possible (supported?) to run two chezmoi stacks on the same machine? If yes, is an alias the preferred solution?

It's possible and supported within reason, but if you're running two chezmoi stacks then you're holding chezmoi wrong and will likely run into problems. See this FAQ entry: https://www.chezmoi.io/user-guide/frequently-asked-questions/design/#can-chezmoi-support-multiple-sources-or-multiple-source-states

@lyderic
Copy link
Author

lyderic commented Jan 6, 2025

Hi,

Thank you for getting back to me. Somehow, I missed the FAQ entry you mentioned, so my question may have seemed a bit dumb. I apologize for that.

I completely understand your "supported within reason" caveat, and it makes total sense to me.

For context: I have dozens of servers, VPSes, and LXC containers. On each of these (often ephemeral, throwaway) machines, I run "normal" chezmoi with default source, destination, config, etc., to install my base dotfiles (essentially ~/.vim*, ~/.bash*, and the like).

Then, I have a couple of machines to remotely access this armada. On these machines, I install things like ~/.ssh, ~/.gnupg, etc. For this, I use my che alias by sourcing this script:

alias che='chezmoi --config "~/.second/config/che.yaml" --cache "~/.second/cache" --destination "${HOME}" --persistent-state "~/.second/config/chestate.boltdb" --source "~/.second/source"'
type __start_chezmoi > /dev/null 2>&1 && complete -o default -o nospace -F __start_chezmoi che

To me, it doesn't make sense to deploy all my SSH and GPG keys everywhere, even if there are passphrase-protected, even if they are also encrypted. Moreover, they are stored on a different, private git server whereas my "normal" chezmoi stuff is public on github.

That said, I take great care to ensure that there is absolutely no crossover between the files managed by chezmoi et the ones managed by che.

@twpayne
Copy link
Owner

twpayne commented Jan 6, 2025

To me, it doesn't make sense to deploy all my SSH and GPG keys everywhere, even if there are passphrase-protected, even if they are also encrypted. Moreover, they are stored on a different, private git server whereas my "normal" chezmoi stuff is public on github.

For this, personally I store all my secrets in my password manager. On my ephemeral, throwaway machines I don't install my password manager and I use .chezmoiignore and templates to skip files or parts of files that require secrets.

This way I have a single dotfiles repo which is public on GitHub, does not contain any secrets (not even encrypted), can be deployed to ephemeral machines, and I only need to install my password manager on machines that require secrets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants