1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-09 12:49:44 +01:00
home-manager/tests/modules/files/out-of-store-symlink.nix
Robert Helgesson 91551c09d4
files: add helper function mkOutOfStoreSymlink
Using this function it is possible to make `home.file` create a
symlink to a path outside the Nix store. For example, a Home Manager
configuration containing

    home.file."foo".source = config.lib.file.mkOutOfStoreSymlink ./bar;

would upon activation create a symlink `~/foo` that points to the
absolute path of the `bar` file relative the configuration file.

PR #1211
2020-05-02 01:22:14 +02:00

29 lines
675 B
Nix

{ config, lib, ... }:
with lib;
let
filePath = ./. + "/source with spaces!";
in {
config = {
home.file."oos".source = config.lib.file.mkOutOfStoreSymlink filePath;
nmt.script = ''
assertLinkExists "home-files/oos"
storePath="$(readlink $TESTED/home-files/oos)"
if [[ ! -L $storePath ]]; then
fail "Expected $storePath to be a symbolic link, but it was not."
fi
actual="$(readlink "$storePath")"
expected="${toString filePath}"
if [[ $actual != $expected ]]; then
fail "Symlink home-files/oos should point to $expected via the Nix store, but it actually points to $actual."
fi
'';
};
}