mirror of
https://github.com/nix-community/home-manager
synced 2024-12-24 10:49:48 +01:00
parent
f4998f0adc
commit
2aeaf65e8f
3 changed files with 58 additions and 0 deletions
|
@ -39,6 +39,28 @@ in
|
|||
};
|
||||
|
||||
config = {
|
||||
assertions = [(
|
||||
let
|
||||
dups =
|
||||
attrNames
|
||||
(filterAttrs (n: v: v > 1)
|
||||
(foldAttrs (acc: v: acc + v) 0
|
||||
(mapAttrsToList (n: v: { ${v.target} = 1; }) cfg)));
|
||||
dupsStr = concatStringsSep ", " dups;
|
||||
in {
|
||||
assertion = dups == [];
|
||||
message = ''
|
||||
Conflicting managed target files: ${dupsStr}
|
||||
|
||||
This may happen, for example, if you have a configuration similar to
|
||||
|
||||
home.file = {
|
||||
conflict1 = { source = ./foo.nix; target = "baz"; };
|
||||
conflict2 = { source = ./bar.nix; target = "baz"; };
|
||||
}'';
|
||||
})
|
||||
];
|
||||
|
||||
lib.file.mkOutOfStoreSymlink = path:
|
||||
let
|
||||
pathStr = toString path;
|
||||
|
@ -283,6 +305,15 @@ in
|
|||
local executable="$3"
|
||||
local recursive="$4"
|
||||
|
||||
# If the target already exists then we have a collision. Note, this
|
||||
# should not happen due to the assertion found in the 'files' module.
|
||||
# We therefore simply log the conflict and otherwise ignore it, mainly
|
||||
# to make the `files-target-config` test work as expected.
|
||||
if [[ -e "$realOut/$relTarget" ]]; then
|
||||
echo "File conflict for file '$relTarget'" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
# Figure out the real absolute path to the target.
|
||||
local target
|
||||
target="$(realpath -m "$realOut/$relTarget")"
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
files-hidden-source = ./hidden-source.nix;
|
||||
files-out-of-store-symlink = ./out-of-store-symlink.nix;
|
||||
files-source-with-spaces = ./source-with-spaces.nix;
|
||||
files-target-conflict = ./target-conflict.nix;
|
||||
files-target-with-shellvar = ./target-with-shellvar.nix;
|
||||
files-text = ./text.nix;
|
||||
}
|
||||
|
|
26
tests/modules/files/target-conflict.nix
Normal file
26
tests/modules/files/target-conflict.nix
Normal file
|
@ -0,0 +1,26 @@
|
|||
{ ... }:
|
||||
|
||||
{
|
||||
config = {
|
||||
home.file = {
|
||||
conflict1 = {
|
||||
text = "";
|
||||
target = "baz";
|
||||
};
|
||||
conflict2 = {
|
||||
source = ./target-conflict.nix;
|
||||
target = "baz";
|
||||
};
|
||||
};
|
||||
|
||||
test.asserts.assertions.expected = [''
|
||||
Conflicting managed target files: baz
|
||||
|
||||
This may happen, for example, if you have a configuration similar to
|
||||
|
||||
home.file = {
|
||||
conflict1 = { source = ./foo.nix; target = "baz"; };
|
||||
conflict2 = { source = ./bar.nix; target = "baz"; };
|
||||
}''];
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue