Skip to content

Conversation

@MattSturgeon
Copy link
Member

Summary

This PR refines the extraFiles option to support directory sources, ensure deterministic conflict detection, and expand the test suite. This makes extraFiles more predictable, more flexible, and less wasteful in the Nix store.


Key improvements

1. Directory support

extraFiles entries may now specify a directory as their source.
The directory is symlinked into the final output as-is, allowing structured layouts without requiring users use builtins.readDir.

2. Deterministic conflict detection

The build now validates the merged set of targets and reports conflicts early.

It detects:

  • Duplicate targets

    • Allowed only when all definitions resolve to the same store path.
    • Differing duplicates produce an explicit error.
  • File vs directory conflicts

    • Both directions (filedirectory and directoryfile) are rejected.
  • Prefix conflicts

    • e.g. defining foo and foo/bar simultaneously.

This ensures module merges behave consistently regardless of evaluation order.

3. Store-efficient output

Sources are now installed using symlinks rather than copying.
This avoids unnecessary Nix store duplication and matches current behaviour in the NixOS /etc module.

4. Expanded and consolidated tests

The test suite now includes coverage for:

  • Basic file installation
  • Nested paths
  • Directory sources
  • Unicode filenames and content
  • Empty and whitespace-only files
  • Expected failures:
    • mismatching duplicates
    • file–directory conflicts
    • prefix conflicts

Fixes #3992
cc @daniellaing

Instead of copying source files to the target, use a symlink.

This reduces nix store redundancy and enables using entire directories
as sources.

To support this, additional validation is done on file targets to
prevent unexpected conflicts.
@daniellaing
Copy link
Member

Excellent stuff, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] extraFiles fails when source is a directory

2 participants