@@ -41,6 +41,10 @@ let
4141 build-chroot-dirs = ${toString cfg.chrootDirs} /bin/sh=${sh} $(echo $extraPaths)
4242 binary-caches = ${toString cfg.binaryCaches}
4343 trusted-binary-caches = ${toString cfg.trustedBinaryCaches}
44+ binary-cache-public-keys = ${toString cfg.binaryCachePublicKeys}
45+ ${optionalString cfg.requireSignedBinaryCaches ''
46+ signed-binary-caches = *
47+ ''}
4448 $extraOptions
4549 END
4650 '';
@@ -244,6 +248,33 @@ in
244248 '';
245249 };
246250
251+ requireSignedBinaryCaches = mkOption {
252+ type = types.bool;
253+ default = false;
254+ description = ''
255+ If enabled, Nix will only download binaries from binary
256+ caches if they are cryptographically signed with any of the
257+ keys listed in
258+ <option>nix.binaryCachePublicKeys</option>. If disabled (the
259+ default), signatures are neither required nor checked, so
260+ it's strongly recommended that you use only trustworthy
261+ caches and https to prevent man-in-the-middle attacks.
262+ '';
263+ };
264+
265+ binaryCachePublicKeys = mkOption {
266+ type = types.listOf types.str;
267+ example = [ "hydra.nixos.org-1:CNHJZBh9K4tP3EKF6FkkgeVYsS3ohTl+oS0Qa8bezVs=" ];
268+ description = ''
269+ List of public keys used to sign binary caches. If
270+ <option>nix.requireSignedBinaryCaches</option> is enabled,
271+ then Nix will use a binary from a binary cache if and only
272+ if it is signed by <emphasis>any</emphasis> of the keys
273+ listed here. By default, only the key for
274+ <uri>cache.nixos.org</uri> is included.
275+ '';
276+ };
277+
247278 };
248279
249280 };
@@ -253,6 +284,8 @@ in
253284
254285 config = {
255286
287+ nix.binaryCachePublicKeys = [ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" ];
288+
256289 environment.etc."nix/nix.conf".source = nixConf;
257290
258291 # List of machines for distributed Nix builds in the format