nix-playgraound/notes/020-package-from-source.md

979 B

Package from Source

This note covers 17-package-from-source/, which packages a selected local source tree and excludes unrelated files from the build input.


1. Why Source Selection Matters

src = ./.; copies the whole example directory into the store. That is fine for small demos, but real packages often need a narrower source tree.

This example uses lib.fileset.toSource so the derivation only sees:

  • src/run.sh, and
  • src/message.txt.

That leaves ignored.txt out of the packaged source on purpose.


2. Why the Check Looks at the Source Path

The check does two things:

  • it runs the packaged binary, and
  • it asserts that the generated source path does not contain ignored.txt.

That keeps the example focused on the real behavior being taught: selecting build inputs, not just producing a runnable script.


3. Commands to Try

cd 17-package-from-source

nix build
./result/bin/source-greet

nix run
nix flake check