Binary Cache: Difference between revisions
imported>Epetousis m Fix outdated nixConfig syntax |
m Removed extra-substituters as not available since 22.05, Added Signing Existing Packages, Added Command Line Options |
||
| Line 114: | Line 114: | ||
== Using a binary cache == | == Using a binary cache == | ||
To configure Nix to use a certain binary cache, refer to the Nix manual.<ref group="cf.">[https://nixos.org/nix/manual/#ch-files Nix Manual, 21. Files]</ref> Add the binary cache as substituter (see the | To configure Nix to use a certain binary cache, refer to the Nix manual.<ref group="cf.">[https://nixos.org/nix/manual/#ch-files Nix Manual, 21. Files]</ref> Add the binary cache as substituter (see the option {{ic|substituters}}) and the public key to the trusted keys (see {{ic|trusted-public-keys}}). | ||
Permanent use of binary cache: | Permanent use of binary cache: | ||
| Line 134: | Line 134: | ||
}; | }; | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight>As described on [https://search.nixos.org/options?show=nix.settings.substituters&type=packages&query=substituters search.nixos.org] by default <nowiki>https://cache.nixos.org/</nowiki> is added to the substituters. You may need to use lib.mkForce to override this and ensure your substituter is the primary choice.<syntaxhighlight> | ||
# /etc/nixos/configuration.nix | |||
{{Warning|Keys that are entered incorrectly or are otherwise invalid, aside from preventing you from benefiting from the cached derivations, may also prevent you from rebuilding your system. This is most likely to occur after garbage collection (e.g., via <code>nix-collect-garbage -d</code>). Consult [https://github.com/NixOS/nix/issues/8271 NixOS/nix#8271] for additional details and a workaround.}} | { config, lib, pkgs, ... }: | ||
{ | |||
nix = { | |||
settings = { | |||
substituters = lib.mkForce [ | |||
"http://binarycache.example.com" | |||
]; | |||
trusted-public-keys = [ | |||
"binarycache.example.com-1:dsafdafDFW123fdasfa123124FADSAD" | |||
]; | |||
}; | |||
}; | |||
} | |||
</syntaxhighlight>{{Warning|Keys that are entered incorrectly or are otherwise invalid, aside from preventing you from benefiting from the cached derivations, may also prevent you from rebuilding your system. This is most likely to occur after garbage collection (e.g., via <code>nix-collect-garbage -d</code>). Consult [https://github.com/NixOS/nix/issues/8271 NixOS/nix#8271] for additional details and a workaround.}} | |||
Temporary use of binary cache: | Temporary use of binary cache: | ||
| Line 201: | Line 217: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
For details see the [https://nixos.org/manual/nix/stable/package-management/sharing-packages.html Sharing Packages Between Machines] in the Nix manual. | For details see the [https://nixos.org/manual/nix/stable/package-management/sharing-packages.html Sharing Packages Between Machines] in the Nix manual. | ||
== Signing Existing Packages == | |||
It is also possible to sign all the packages that already exist in the nix store of the machine serving the binary cache to make them immediately available. | |||
<code>$ nix store sign --extra-experimental-features nix-command --all --key-file /var/cache-priv-key.pem</code> | |||
Note : As of NixOS 24.05 {{ic|--extra-experimental-features nix-command}} is required for {{ic|store sign}} if this is not in your configuration.nix. | |||
== Hosted binary cache == | == Hosted binary cache == | ||
| Line 245: | Line 266: | ||
curl https://cache.nixos.org/$(readlink -f $(which bash) | cut -c12-43).narinfo | curl https://cache.nixos.org/$(readlink -f $(which bash) | cut -c12-43).narinfo | ||
</pre> | </pre> | ||
== Command Line Options == | |||
It is also possible to pass {{ic|substituters}} and {{ic|trusted-public-keys}} on the command line if they are not in {{ic|configuration.nix}} or you want to use a particular binary cache server. | |||
$ nix-build --option substituters "<nowiki>http://binarycache.example.com</nowiki>" --option trusted-public-keys "binarycache.example.com-1:dsafdafDFW123fdasfa123124FADSAD" '<nixpkgs>' -A pkgs.PACKAGE | |||
$ nixos-rebuild --option substituters "<nowiki>http://binarycache.example.com</nowiki>" --option trusted-public-keys "binarycache.example.com-1:dsafdafDFW123fdasfa123124FADSAD" switch | |||
To do an offline install (providing your binary cache contains all the packages required); | |||
$ nixos-install --option substituters "<nowiki>http://binarycache.example.com</nowiki>" --option trusted-public-keys "binarycache.example.com-1:dsafdafDFW123fdasfa123124FADSAD" | |||
== See also == | == See also == | ||
<references group="cf."/> | <references group="cf."/> | ||