yadm-dev / yadm

Yet Another Dotfiles Manager
https://yadm.io/
GNU General Public License v3.0
5.15k stars 177 forks source link

Unable to track system level files #407

Closed bound-variable closed 2 years ago

bound-variable commented 2 years ago

Describe the bug

Following the docs doesn't lead to effective results.

To reproduce

Steps to reproduce the behavior:

  1. Add alias in shell config: alias syadm="sudo yadm -Y /etc/yadm"
  2. Run alias as: syadm init -w /etc
  3. Receive error:
    ERROR: Git repo already exists. [/home/USER/.local/share/yadm/repo.git]
    Use '-f' if you want to force it to be overwritten.

    Expected behavior

Running yadm as sudo shouldn't ask to overwrite extant repo.

Environment

TheLocehiliosan commented 2 years ago

These instructions seem to be from a time before the data directory was managed outside of the standard yadm directory. The documentation should be updated. The alias should probably look like this instead:

alias syadm="sudo yadm --yadm-dir /etc/yadm --yadm-data /etc/yadm/data"

Can you give that a try and let me know if this works better for you? It should result in all of the "syadm" data being stored in /etc/yadm.

bound-variable commented 2 years ago

Yes, I was able to run the syadm alias, add files, and commit them. But I wasn't able to push this to the same repo I use for files under $HOME. I guess that's to be expected? So do I need to create another remote repo to host the files under /etc?

TheLocehiliosan commented 2 years ago

Yes, a cloned Git repo can only have a single worktree configured, so the system-level files and your own dotfiles would need to be in separate repos. I can clarify this in documentation too.

If you want, you could specify the worktree as / (with yadm init -w /) instead, and maintain ALL of your files in a single repo. But your home directory would need to use the same fully qualified path on all hosts. All of the tracked files for a repo must be under the work tree, so by using / you could track any file on a system. (that isn't a typical use-case though)

bound-variable commented 2 years ago

I've set it up with the alias and the command above: sudo yadm --yadm-dir /etc/yadm --yadm-data /etc/yadm/data init -w /

I can add and commit files under $HOME, but not under /etc. For example, if I enter /etc/zsh and add the files in there, there's no error, but there's also nothing to commit. Running sudo yadm ... commit -a prints initial commit. Running sudo yadm ... status prints no commits yet.

TheLocehiliosan commented 2 years ago

When you don't specify yadm-dir and yadm-data, you're using the default locations (for your user).

You would need to continue to specify those overridden directories each time you run yadm.

sudo yadm --yadm-dir /etc/yadm --yadm-data /etc/yadm/data add <file> sudo yadm --yadm-dir /etc/yadm --yadm-data /etc/yadm/data commit

Some people create an alias to make running those commands simpler.

bound-variable commented 2 years ago

Sorry, I was implying that I was using the alias. That's what the ellipsis was for. I should have been clearer I suppose.

Yadm wasn't working for my system files. I couldn't figure it out. So I went ahead and learned about Git and bare repos. I'm using the basic method (just git) and it works with both my system files and user files.

You can close this issue of you like.

TheLocehiliosan commented 2 years ago

OK, I just tried it again myself, and it the alias below is working for me.

alias syadm="sudo yadm --yadm-dir /etc/yadm --yadm-data /etc/yadm/data"

I'm very happy you have a solution that's working for you though.

I'll keep this issue open, to track getting the FAQ updated with the necessary parameters.

Animeshz commented 2 years ago

Another way I'm using is to use a simple script syncfiles and call that with a file/folder (incl relative path too), it'll create a absolute path structure and keep the file there at ~/.config/yadm/files. Later on at bootstrapping step we can just rsync -avP it to /.

The only thing missing is that we've to keep track if the file is changed by ourselves there's no git status.

markstos commented 2 years ago

@Animeshz I'm thinking of using a similar approach, except of copying system files from my home directory, they would be symlink'ed. This solves the problem of detecting if the file is changed. So the approach might look like:

  1. Store custom versions of system files at ~/.config/system/. For example /etc/resolv.conf at ~/.config/system/etc/resolv.conf.
  2. Manage these files normally with YADM.
  3. Have a tool which symlinks everything under ~/.config/system to /etc/. This tool needs to be run at bootstrap time. This could be Ansible or a simple script.

The kind of solution seems like it could make sense on a single-user system where the /home directory is available at boot time. It wouldn't work if the home directory has an additional layer of encryption, but it could work if only full-disk encryption is used.

Am I missing a downside to this approach?

Animeshz commented 2 years ago

Oh hey, I forgot to tell, I also added -S option that will sync all the previously synced files back.

syncfiles /etc/cron.weekly
cd /etc
syncfiles resolv.conf

syncfiles -S  # syncs both of them, as added previously

Never had a problem till now!