-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pinning nixpkgs in configuration.nix? #62832
Comments
You probably want to use On my local setup the pinning looks like this: # ~/nixos-config/nixos.nix
{ config, ... }:
let
nixpkgs = builtins.fetchTarball {
url = https://github.com/NixOS/nixpkgs/archive/hash-of-the-commit-to-pin.tar.gz;
sha256 = "checksum";
};
in {
# no need to inject `nixpkgs.overlays` here, this will be done by NixOS
nixpkgs.pkgs = import "${nixpkgs}" {
inherit (config.nixpkgs) config;
};
nix.nixPath = [ "nixpkgs=${nixpkgs}" ];
} More information can be found at Does this help? |
Thanks! That'll probably improve the solution, but as far as I understand, the latter shortcoming still exists.. That is, for instance, |
Yeah, forgot to mention that, sorry. The problem is that we now need some sort of option which overrides the entire module system including the code which evaluates the module system and I'm not sure if that's even possible atm. I'm pretty sure that right now you have to (1) incorporate a new nixpkgs rev and rebuild and (2) modify the config accordingly and rebuild. In case you run into some kind of edge case where even that breaks, you could still work around with |
There might be some unsafe eval hacks but I think creating your own script that will call Related: #35411 (comment) |
According to man page, nixos-rebuild doesn't take If pinning nixpkgs in configuration.nix isn't currently possible, I think it is something that should be implemented. Is there something that makes it difficult/impossible or is it just something nobody has bothered to do yet (or is there some solution already)? |
It does support the flag. I guess the following line refers to that:
The issue with defining |
I'm pretty sure as well. But it seems as this sentence can be missed easily, so I'll open a PR later which adds some more helpful nix flags to the man page.
That's an interesting approach! But may I ask how you update your Nix path then?
That's basically what I tried to explain in #62832 (comment). From my point of view it's not really worth to make the module system even more complex to achieve this, I'm using the approach with two rebuilds for a new nixpkgs for at least a year and it works pretty great here, however we should improve the documentation (either in the manual or in the wiki) before closing this issue. |
You would update it in the file as outlined in #35411 (comment) Or you can combine it with the hashing: #!/bin/sh
nixpkgs=$(nix-build --no-out-link -E '(builtins.fetchTarball {
url = https://github.com/NixOS/nixpkgs/archive/hash-of-the-commit-to-pin.tar.gz;
sha256 = "checksum";
})')
nixos-rebuild -I nixos-config=configuration.nix -I nixpkgs=$nixpkgs "$@" or store the hash and url in a separate file and import it to the script through |
Oh... of course... with But @jluttine is this sufficient for you? In that case I'd prepare a PR to update the docs accordingly next week. |
I suppose that'll work, thanks! But I would still love to see some better built-in support for pinning the nixpkgs commit.. In that example:
How about this: Could I pin nixpkgs with
And mynixpkgs.nix would be something like:
Then, changing nixpkgs commit would require modiyfying mynixpkgs.nix, calling nix-channel and then I can run any nixos-rebuild or nix-shell or anything consistently. Does this make sense? |
Only if you set
You might want that if you want other Nix commands to use that pinned repo. Probably something like the following might work. nix.nixPath = [ "nixpkgs=${<nixpkgs>}" ];
No,
You could use Your solution might work but I am not familiar enough with |
{ pkgs, ... }: {
nixpkgs.pkgs = import (builtins.fetchTarball https://nixos.org/channels/nixos-19.03/nixexprs.tar.xz);
nix.nixPath = ["nixpkgs=${pkgs.path}"];
}
Just realised that this has the same problem as mentioned before. |
mumble, mumble, cough, NixOS/rfcs#49 |
I think it was a mistake to make nixpkgs configurable from NixOS (eg: nixpkgs.overlays). Without that option it would be possible to spawn multiple nixos configurations with a nixpkgs function: But since we make it configurable from inside the configuration.nix, it means that nixpkgs is forced to be re-evaluated entirely for each machine. This means that deploying multiple machines becomes a O(N) operation in terms of time and memory instead of something closer to O(log(N)). |
Just wondering if it would still be possible to add overlays (I mean, the package set consists of overlays with a fixpoint, so in theory it would be possible to allow something like this, however I'm not sure if that's actually a good idea and even possible as it's a while ago since I had to dig into this part of nixpkgs internals :) ). I mainly bring this up because I actually consider it a good thing to allow configurations to add e.g. patches (not all modules have a But do you have any idea/plan on how it would be possible to migrate to such an approach? I'm not sure if such a change is possible atm, but I guess I'd be interested in something like this :) But unless there's anything further to discuss, I'd propose to close this as this issue is merely a question and it seems as everything needed was said :) |
Ok we're getting out of topic :) Just to answer your question, one possibility might be to introduce a /etc/nixos/default.nix: let
nixpkgs = <nixpkgs>; # pin nixpkgs here if you want
pkgs = import nixpkgs {
config = {}; # potentially override the system config here
overlays = []; # <- set your overlays here
};
in
pkgs.mkNixOS (import ./configuration.nix) The overlays are not configurable from nixos modules anymore but that might be a bad idea anyways. |
I have sort of hacked my way though this. It's more complicated than "just pinning nixpkgs in nixos-configuration.nix" but it works. https://github.com/colemickens/nixcfg I actually have my imports and overlays effectively pinned as well, along with a (It looks like I still have nixPath set inside, but it's effectively not used, anywhere I do rebuilds you'll see that I unset |
@zimbatm i want to build an ISO using the configuration. When i use pinning like you described, i get this error:
Do i have to do it differently? It would be great to have a working example documented! |
Sorry that was a hypothetical example! Your best bet for now is to use the nixos-generators project right now. |
@zimbatm how does it help with pinning? I see no option for that. When it's just a hypothetical example, can the issue be reopened until a solution is implemented? |
It is now possible after this is implemented: nix-community/nixos-generators#31 Using For example i build an ISO image using an unmerged PR (branch on my fork):
|
This example is not hypothetical, since
let
nixos = <nixpkgs/nixos>; # pin NixOS here if you want
configuration = /path/to/config.nix; # no need for `NIXOS_CONFIG`
in
import nixos { inherit configuration; } Then call Note though that it will break the fallback cases when For convenience I would add a wrapper to { config, pkgs, ...}:
let
nixos-rebuild = pkgs.writeScriptBin "nixos-rebuild" ''
#!${pkgs.stdenv.shell}
exec ${config.system.build.nixos-rebuild}/bin/nixos-rebuild -I $PREFIX $@
'';
in
{
config.environment.systemPackages = [ nixos-rebuild ];
} When using I would like to stress for clarification that we really want to pin a While the OS distribution and the package collection are two distinct things, right now they live in the same repository "for consistency" (whatever that means). So the way of specifying the dependency is a bit obfuscated, and although that is not essential, it was misleading me when working this out. In hindsight, the warning on |
see <NixOS/nixpkgs#62832> for ideas.
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/pinning-nixpkgs-for-nixos-rebuild/6473/1 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/pinning-nixpkgs-for-nixos-rebuild/6473/3 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/pinning-nixpkgs-for-nixos-rebuild/6473/5 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
From the Nix flakes proposal:
|
I am reopening this issue because this question continues to be asked by new NixOS users. Acceptance criteria to close:
Current methods that I personally know work, which should be documented with pros and cons in the manual:
|
We have a module that includes the nixpkgs used to build the system in the system's closure, links it to
|
@nh2 asked me to contribute what I use: This is in the
And this is in my aliases file:
|
what functions return a set accepted as an entry in
|
@cxandru replying this myself: |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/confused-about-how-vscode-extensions-versioning-works-in-nixos/17608/6 |
Could this be made much simpler if |
@jluttine the current Flakes support of |
Haven't really used flakes, I have preferred using plain nix/NixOS stuff.. For the record, my current solution in let
nixpkgs = builtins.fetchTarball {
name = "nixpkgs-2023-01-10";
# nixos-unstable branch Jan 10, 2023
url = "https://github.com/NixOS/nixpkgs/archive/c07552f6f7d4eead7806645ec03f7f1eb71ba6bd.tar.gz";
sha256 = "sha256:1lw6wa6akj16ia6jjqb9dhq0yx6rkxzzqsb2bjh3r3f7s138bl0q";
};
in {
environment.etc = {
nixpkgs = {
source = nixpkgs;
};
};
nix.nixPath = ["nixpkgs=/etc/nixpkgs"];
} Then, whenever I need to modify nixpkgs version, I do it in two steps:
So, instead of thinking that "I need to run |
see <NixOS/nixpkgs#62832> for ideas.
Edit by @nh2: I turned this into an issue to track missing manual documentation, with acceptance criteria for closing in #62832 (comment)
Issue description
I searched for information on how to pin system-wide nixpkgs in configuration.nix, but I couldn't find. I found a lot of information on how to pin nixpkgs for nix-shell or nix-build though. I'm probably just missing something obvious because I'm expecting this to be something very trivial..
The point is that I want to specify nixpkgs commit in
configuration.nix
because the configuration is quite tightly tied to nixpkgs version. For instance, module options might change, packages might be removed/added/renamed. Also, for easier reproducability, it'd be great ifconfiguration.nix
contained all the relevant information so that when passing the file to someone, I don't need to also specify the nixpkgs version and the receiver doesn't have to figure out how to get that nixpkgs version. They would just put the file in place and runnixos-rebuild switch
, and that's it.I tried:
But this has two shortcomings:
builtins.fetchTarball
, so no real problem here.nixos-rebuild switch
twice for it to take effect. The first call updates my system wide nixpkgs and the second call updates my system with this new nixpkgs. As far as I understand, this is a bit problematic:configuration.nix
isn't compatible with the nixpkgs version that is currently active in the system? Then the build fails and one cannot upgrade the system by just callingnixos-rebuild switch
althoughconfiguration.nix
would build just fine with the nixpkgs it specifies itself.nixos-rebuild boot
ornixos-rebuild build
wouldn't use nixpkgs specified inconfiguration.nix
but what is currently active in the system.So what is the correct way of specifying nixpkgs commit in
configuration.nix
?The text was updated successfully, but these errors were encountered: