diff options
Diffstat (limited to 'pkgs/populate/README.md')
| -rw-r--r-- | pkgs/populate/README.md | 28 |
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 |
