TheLocehiliosan / yadm

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

Some files configured to be encrypted aren't encrypted #388

Closed jluttine closed 2 years ago

jluttine commented 2 years ago

Describe the bug

Some of the files that are supposed to be encrypted aren't encrypted.

To reproduce

Not sure how to reproduce this in general - I can think about it if needed - but here's what happens on my machine:

[jluttine@nipsu:/etc/nixos]$ cat .yadm/config/encrypt 
passwords/ddclient-account.nix
passwords/default.nix##*
passwords/radicale-passwords

[jluttine@nipsu:/etc/nixos]$ ls -l passwords/
total 20
-rw------- 1 jluttine wheel  90 Nov 22 19:13 ddclient-account.nix
lrwxrwxrwx 1 jluttine wheel  27 Jan 23  2021 default.nix -> default.nix##hostname.nipsu
-rw------- 1 jluttine wheel 246 Oct 25  2017 default.nix##hostname.leevi
-rw------- 1 jluttine wheel 236 Apr 22  2017 default.nix##hostname.martta
-rw------- 1 jluttine wheel 234 Jun 15  2017 default.nix##hostname.nipsu
-rw------- 1 jluttine wheel 208 Nov 18  2017 radicale-passwords

[jluttine@nipsu:/etc/nixos]$ yadm --yadm-dir /etc/nixos/.yadm/config --yadm-data /etc/nixos/.yadm/data encrypt
Encrypting the following files:
passwords/default.nix##hostname.leevi
passwords/default.nix##hostname.martta
passwords/default.nix##hostname.nipsu

Enter passphrase: 

Expected behavior

The list of encrypted files should have included also passwords/ddclient-account.nix and passwords/radicale-passwords.

Most likely I'm just missing something obvious..

Environment

TheLocehiliosan commented 2 years ago

I see that you appear to be using an alternate worktree? or perhaps are trying to? The passwords are at /etc/nixos/passwords. The encryption will happen for the passwords/ directory relative to the work tree. Can you share the output of:

yadm gitconfig --get core.worktree
jluttine commented 2 years ago
$ yadm gitconfig --get core.worktree

**WARNING**
  Legacy paths have been detected.

  With version 3.0.0, yadm uses the XDG Base Directory Specification
  to find its configurations and data. Read more about these changes here:

    https://yadm.io/docs/upgrade_from_2
    https://yadm.io/docs/upgrade_from_1

  In your environment, the data directory has been resolved to:

    /home/jluttine/.local/share/yadm

  To remove this warning do one of the following:
    * Run "yadm upgrade" to move the yadm data to the new paths. (RECOMMENDED)
    * Manually move yadm data to new default paths and reinit any submodules.
    * Specify your preferred paths with --yadm-data and --yadm-archive each execution.

  Legacy paths detected:
    * /home/jluttine/.config/yadm/repo.git
    * /home/jluttine/.config/yadm/files.gpg

***********

ERROR: Git repo does not exist. did you forget to run 'init' or 'clone'?

Or did you mean:

$ yadm --yadm-dir /etc/nixos/.yadm/config --yadm-data /etc/nixos/.yadm/data gitconfig --get core.worktree
fatal: not a git repository: '/etc/nixos/.yadm/data/repo.git'

Ok, repo.git seems to be in the wrong place... I moved it from /etc/nixos/.yadm/repo.git to /etc/nixos/.yadm/data/repo.git, and now the encrypt command seems to do the right thing:

$ yadm --yadm-dir /etc/nixos/.yadm/config --yadm-data /etc/nixos/.yadm/data encrypt
Encrypting the following files:
passwords/ddclient-account.nix
passwords/default.nix##hostname.leevi
passwords/default.nix##hostname.martta
passwords/default.nix##hostname.nipsu
passwords/radicale-passwords

A really weird that the symptom of having repo.git in the wrong place was not an error message but that only some of the files were going to be encrypted..

Also, I don't know why repo.git was in the wrong place. Probably I've tried to manually put things in right places after upgrading yadm but got that wrong..

By the way, it would be nice if yadm worked similarly to git: It searches for .yadm directory in the current directory and then its parent directories (recursively) until it finds .yadm directory. Then, it would use that directory by default. If not found, then it would default to using the home directory locations. Now I need to always give those --yadm-dir and --yadm-data options which makes using yadm quite painful in practice.. I could of course define an alias.

Anyway, thanks for the help!