With --ignore-fail-on-non-empty, non-emptiness is the only failure
that gets ignored by rmdir. In the case that rmdir reaches $HOME and
considers deleting it, it will detect insufficient permissions and
subsequently exit with an error, even if $HOME is not empty.
Prevent this by calling rmdir with a relative path that excludes
$HOME.
We must only follow the symbolic link once (i.e., not use the `-e`
option) since otherwise the pattern will not match when
`home.file.xyz.source` is a directory.
Problem
-------
We resolve symlinks from inside `/nix/store/HASH-home-manager-files`
into the nix store as `/nix/store/HASH-DRVNAME` which does not match
the pattern.
This happened to me because I pull in some repos in via `home.file`.
The `home-manager-files` derivation links to the repo's derivation in
the nix store. For example:
let nanorcs = fetchFromGitHub {
owner = "scopatz";
repo = "nanorc";
…
}; in [
{
target = ".nano";
source = nanorcs;
}
{
target = ".nanorc";
source = "${nanorcs}/nanorc";
}
]
Solution
--------
Call `readlink` without `-e` to obtain only the first redirection from
`~` to `/nix/store/HASH-home-manager-files`.
When a file has disappeared between the previous and the next
generations then its symlink in `$HOME` is typically deleted. With
this commit we refuse to delete the path unless we are reasonably
certain it is a symlink into a Home Manager generation.
In the activation script we expect to use the tools provided by GNU
Core Utilities and GNU Bash. This commit therefore explicitly add
these first in the `PATH` environment variable.
This should reduce the risk of overwriting an existing file in the
user's home directory. A file will only be replaced if it is a link
pointing to a home-manager tree inside the Nix store.
If an existing file is detected an error is written indicating the
file's path and the activation will terminate before any mutation
occurs.
Fixes#6
Previously the home files were not linked if the generation hadn't
changed. Unfortunately, this would mean that, if a file link was
removed for some reason it would not be recreated by running a switch
command.
For example, with these settings Bash will complain if uninitialized
variables are used. Some code has been improved to run cleanly with
these settings.
Nix does not allow files whose name start with a '.' in the Nix store.
This commit makes a not of this fact in the `home.file.source` option
and also adds an assertion verifying that no such file is given.
Closes#4
If no files should be installed into the home directory then an error
would occur since the directory holding the files would never be
created. With this change the directory is unconditionally created.