emmanuelrosa / erosanix

My main NixOS/Nix Flakes repository
MIT License
78 stars 4 forks source link

mkWindowsApp - fileMap only works if the base name of both components is the same #14

Closed Niols closed 2 months ago

Niols commented 3 months ago

In some cases, fileMap only works if the base name of both components is the same. For instance, if the map looks like:

fileMap = {
  "$HOME/.config/A" = "drive_c/users/$USER/AppData/Roaming/B";
};

and B is a directory, then loading A into the temporary Wine directory B works fine (and, the very first time, does nothing). However, persisting B into A does not work and the files will be persisted to $HOME/.config/B instead. The culprit is the function persist_file:

https://github.com/emmanuelrosa/erosanix/blob/90f5e8e345d940d74cad215b0b59eb2f83682383/pkgs/mkwindowsapp/default.nix#L189-L206

When the source $s is a directory (line 202), then we run cp -v -r -n "$s" "$base_dir", where base_dir=$(dirname "$d"). In the example:

$s == "$WINEPREFIX/drive_c/users/$USER/AppData/Roaming/B"
$d == "$HOME/.config/A"
$base_dir == "$HOME/.config/"

so we run:

cp -v -r -n "$WINEPREFIX/drive_c/users/$USER/AppData/Roaming/B" "$HOME/.config/"

which indeed creates $HOME/.config/B instead of $HOME/.config/A.

A mitigation is of course to ensure A == B, and this is what I use for now.

Thank you for this app, by the way — it's amazing!

emmanuelrosa commented 3 months ago

You're welcome! I hope you find it useful.

I've known about this issue for a while, but I haven't found a solution. I use the same work-around ;)

The only way I've been able to address this is with a reimplementation of the mapping code. I believe I used rsync. I probably still have that code in a branch, but I've been hesitant to merge it, even after writing unit tests.

I'll have to revisit this.

Niols commented 2 months ago

If you bring back this code, I'll happily have another look myself. I am not an rsync expert but it does look like the right tool for a job like this. I could otherwise suggest a modification to the current mapping code that should do it, but that would be yet again more code, and I'm not sure that this is the right way to proceed.

emmanuelrosa commented 2 months ago

Fixed in 87641eed8d937b196d33a87bcde05ec4f2d3025f

Niols commented 2 months ago

Indeed, looks great!