FAQ/Pinning Nixpkgs: Difference between revisions
imported>Milahu add note: still need a nix-channel for nixos |
Drop pre nix 2.0, warn about negatives of pinning |
||
| (9 intermediate revisions by 6 users not shown) | |||
| Line 1: | Line 1: | ||
{{FAQ/breadcrumb}} | |||
It is possible (and indeed, fairly easy) to pin a specific version of | It is possible (and indeed, fairly easy) to pin a specific version of | ||
Nixpkgs. This can be used to upgrade individual applications | Nixpkgs. This can be used to upgrade individual applications | ||
separately on their own terms, and to ensure their deployability is | separately on their own terms, and to ensure their deployability is | ||
not impacted by other systems' requirements. | not impacted by other systems' requirements. | ||
Another reason why one would want to pin nixpkgs is to get older versions of a specific software. [https://lazamar.co.uk/nix-versions/ This site] can show you all the versions a package went through, and what nixpkgs revision to use to get your specific version. | |||
Note: You can <code>sudo nix-channel --remove nixpkgs</code>, but you still need a nix-channel for nixos | Note: You can <code>sudo nix-channel --remove nixpkgs</code>, but you still need a nix-channel for nixos | ||
Be aware that this also pins all dependencies of the application which often causes issues for GUI applications and also brings in back outdated and potentially vulnerable dependencies. | |||
<pre> | <pre> | ||
| Line 10: | Line 15: | ||
nixos https://nixos.org/channels/nixos-21.05 | nixos https://nixos.org/channels/nixos-21.05 | ||
</pre> | </pre> | ||
Nix 2.0 introduces new builtins, <code>fetchTarball</code> and <code>fetchGit</code>, which make it possible to fetch a specific version of nixpkgs without depending on an existing one: | Nix 2.0 introduces new builtins, <code>fetchTarball</code> and <code>fetchGit</code>, which make it possible to fetch a specific version of nixpkgs without depending on an existing one: | ||
| Line 26: | Line 29: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Or, to use git for fetching | Or, to use git for fetching: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 48: | Line 51: | ||
while evaluating anonymous function at /nix/store/b93cq865x6qxpn4dw9ivrk3yjcsm8r97-nixos-19.09/pkgs/stdenv/generic/make-derivation.nix:142:17, called from undefined position: | while evaluating anonymous function at /nix/store/b93cq865x6qxpn4dw9ivrk3yjcsm8r97-nixos-19.09/pkgs/stdenv/generic/make-derivation.nix:142:17, called from undefined position: | ||
program 'git' failed with exit code 128 | program 'git' failed with exit code 128 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 155: | Line 56: | ||
How to upgrade a single package and service to an unstable version | How to upgrade a single package and service to an unstable version | ||
There is probably a better way, especially once flakes | There is probably a better way, especially once flakes come around. Some packages let you specify which <code>package</code> to run as an option but most don't. The following is a generic way that also works for those which don't. | ||
add to configuration.nix a set allowing unstable packages. | add to configuration.nix a set allowing unstable packages. | ||
| Line 181: | Line 82: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
environment.systemPackages = with pkgs; [ | |||
unstable.bind | |||
unstable.dnsutils | |||
vim | |||
]; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 193: | Line 94: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
services.bind.enable = true; | |||
... | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 202: | Line 103: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
users.users.named = { | |||
uid = config.ids.uids.bind; | |||
description = "BIND daemon user"; | |||
}; | |||
systemd.services.mybind = { | |||
description = "BIND Domain Name Server"; | |||
unitConfig.Documentation = "man:named(8)"; | |||
after = [ "network.target" ]; | |||
wantedBy = [ "multi-user.target" ]; | |||
preStart = '' | |||
mkdir -m 0755 -p /etc/bind | |||
if ! [ -f "/etc/bind/rndc.key" ]; then | |||
${pkgs.unstable.bind.out}/sbin/rndc-confgen -c /etc/bind/rndc.key -u named -a -A hmac-sha256 2>/dev/null | |||
fi | |||
${pkgs.coreutils}/bin/mkdir -p /run/named | |||
chown named /run/named | |||
''; | |||
serviceConfig = { | |||
ExecStart = "${pkgs.unstable.bind.out}/sbin/named -u named -4 -c /etc/bind/named.conf -f"; | |||
ExecReload = "${pkgs.unstable.bind.out}/sbin/rndc -k '/etc/bind/rndc.key' reload"; | |||
ExecStop = "${pkgs.unstable.bind.out}/sbin/rndc -k '/etc/bind/rndc.key' stop"; | |||
}; | |||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 230: | Line 130: | ||
where all the stuff just comes from the bind services definition(which you can get from the source link on the nixos options page.) | where all the stuff just comes from the bind services definition(which you can get from the source link on the nixos options page.) | ||
Just replace named variables, and replace <code>${pkgs.bind.out</code> with <code>${pkgs.unstable.bind.out}</code> | Just replace named variables, and replace <code>${pkgs.bind.out</code> with <code>${pkgs.unstable.bind.out}</code> | ||
== See also == | |||
* [https://nix.dev/reference/pinning-nixpkgs Pinning Nixpkgs] | |||
* [https://nix.dev/tutorials/first-steps/towards-reproducibility-pinning-nixpkgs Towards Reproducibility: Pinning Nixpkgs] | |||
* [https://nix.dev/guides/recipes/dependency-management.html Dependency Management] | |||