11 Commits

Author SHA1 Message Date
Robert Helgesson
527e47b78f files: handle overlapping file targets
The current behavior of `home.file` is inconsistent when handling
recursive file with another, overlapping, non-recursive file.

Specifically, consider a configuration

```nix
home.file = {
  "foo" = { source = ./foo; recursive = true; };
  "foo/bar".text = "some other file";
};
```

where `./foo` is a directory containing a file `bar`. Switching to
this configuration will result in the `./foo` directory being
recursively symlinked while the "foo/bar" entry is ignored. Note,
building the home files derivation does log

> File conflict for file 'foo/bar'

On the other hand, the supposedly equivalent configuration

```nix
home.file = {
  "foo" = { source = ./foo; recursive = true; };
  abc = { target = "foo/bar"; text = "some other file"; };
};
```

results in the `./foo` directory not being recursively symlinked,
i.e., only the file `foo/bar` shows up in the built configuration.
This time the home files build log contains

> File conflict for file 'foo'

This commit makes the behavior more consistent in that we always
handle the file in a unified manner. The conflict resolution is
offered in three flavors, "ignore", "error", and "override" indicating
whether the recursively symlinked file wins, the entire build errors
out, and the regularly symlinked file wins.

The current default is "ignore" since it is the resolution that most
closely matches the current behavior, at least when the file attribute
name is used as the target path.

The other two resolutions can be chosen by setting the
`home.fileOverlapResolution` option, which is set as invisible due to
its experimental nature.
2026-04-07 23:33:05 -05:00
Austin Horstman
cba2f9ce95 treewide: reformat nixfmt-rfc-style
Reformat repository using new nixfmt-rfc-style.
2025-04-08 08:50:05 -07:00
Austin Horstman
439a125afe tests: remove with lib (#6511) 2025-02-21 23:20:07 -06:00
Robert Helgesson
eec2272999 tests: various minor cleanups 2023-05-13 00:09:52 +02:00
Lars Mühmel
7efca2ca18 files: allow disabling creation of a file
PR #3622
2023-01-26 22:31:16 +01:00
Robert Helgesson
2aeaf65e8f files: assert that target files are unique
Fixes #1807
2021-06-27 17:10:45 +02:00
Robert Helgesson
4fe5afa755 files: make sure the target file name is escaped
The previous implementation would allow variables to sneak into the
file names. This commit makes sure the resulting target file path
exactly matches the expected path.
2020-08-29 18:22:03 +02:00
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
Robert Helgesson
45abf3d38a Apply nixfmt on many files 2020-02-02 01:07:28 +01:00
Robert Helgesson
bcfc52cb85 tests: move git and files tests to directories 2019-12-08 21:40:22 +01:00
Robert Helgesson
7c04351a57 files: allow a wider range of source file names
In particular support source files whose name start with `.` or
contain characters not allowed in the nix store, such as spaces.

Also add some test cases for `home.file`.
2019-01-19 12:44:58 +01:00