aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/README.md
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-24 01:04:21 +0000
committertv <tv@krebsco.de>2026-11-24 01:12:10 +0000
commita021d211906d23c9e3454da974806454e9ec74c2 (patch)
tree8a9186c4bc6b0050b83a89536c458d5c2f497355 /pkgs/populate/README.md
parentba2dc2e941fe3170ccd85d319982d48d78081177 (diff)
populate lib: leave out sources whose types are set to null
A source's type can depend on a condition, e.g. nixpkgs.file = optionalSource local { ... }, which returns the settings if the condition holds, and else null. A source whose types are all null, at least one of them set to null rather than left unset, gets the type null, and evalSource leaves it out. A type left unset, e.g. by lib.mkIf false, still counts as missing, so an empty source stays an error. krops' lib provides optionalSource, too.
Diffstat (limited to 'pkgs/populate/README.md')
-rw-r--r--pkgs/populate/README.md28
1 files changed, 28 insertions, 0 deletions
diff --git a/pkgs/populate/README.md b/pkgs/populate/README.md
index 74181e9..f28598a 100644
--- a/pkgs/populate/README.md
+++ b/pkgs/populate/README.md
@@ -170,6 +170,34 @@ nix-instantiate --eval --strict --json -E '
' | populate --force - root@server
```
+`evalSource` evaluates the sources with the module system, so a list's
+attribute sets get merged, and sources and settings take nixpkgs'
+`lib.mkIf`, `lib.mkMerge`, and the like. A source needs exactly one type
+that isn't null. One whose types are all null, at least one of them set to
+null, gets left out, so a source's type can depend on a condition with
+`optionalSource`, which returns its settings if the condition holds, and
+else null:
+
+```nix
+let
+ inherit (import ./lib {}) evalSource optionalSource;
+ local = false;
+in
+evalSource {
+ nixpkgs.file = optionalSource local { path = "/home/me/nixpkgs"; };
+ nixpkgs.git = optionalSource (!local) {
+ url = "https://github.com/NixOS/nixpkgs";
+ ref = "nixos-26.05";
+ };
+ secrets.passage = optionalSource local "/home/me/secrets";
+}
+```
+
+A type that `lib.mkIf false` leaves unset doesn't count as set to null: a
+source without a type is more likely a mistake, e.g. a forgotten type,
+than meant to be left out. So a source whose types are all unset is an
+error, as is one with more than one type.
+
Store paths in the sources, e.g. of a `file` source that is a derivation,
must exist when populate runs. `nix-instantiate --eval` doesn't build
them; building a file that contains the sources, e.g. with `pkgs.writeText