Skip to content
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

Should nixpkgs/overlays.nix contain an overlay referring to the pinned nixpkgs? #1

Closed
bzm3r opened this issue Dec 5, 2023 · 7 comments

Comments

@bzm3r
Copy link

bzm3r commented Dec 5, 2023

I (roughly) understand that the configuration's builder will know to look for the appropriate nixpkgs based on work done by the rebuild script to set NIX_PATH appropriately.

Therefore, there should not be the need to add the following to nixpkgs/overlays.nix:

  (
    let
      sources = ./niv/source.json;
    in
    self: _super: {
      inherit (sources) nixpkgs;
    }
  )

But I'm wondering if this is useful regardless? For example: if for some reason, NIX_PATH changes between when rebuild sets it, and the configuration is built, then the configuration will still end up using the right nixpkgs imported by npins/niv/etc., rather than whatever is pointed to by NIX_PATH?

Also, I'm wondering if there is a way to obviate NIX_PATH entirely....will have to look into how it is read currently in the nixpkgs repo, but it would be nice if we could point it to read from a file instead...

Some way to fix the NIX_PATH env var, essentially, and make it "immutable".

(One really silly/sad idea that comes to mind is a systemd unit that monitors changes to NIX_PATH...)

@infinisil
Copy link
Owner

I (roughly) understand that the configuration's builder will know to look for the appropriate nixpkgs based on work done by the rebuild script to set NIX_PATH appropriately.

Therefore, there should not be the need to add the following to nixpkgs/overlays.nix:

  (
    let
      sources = ./niv/source.json;
    in
    self: _super: {
      inherit (sources) nixpkgs;
    }
  )

I'm not a fan of this because it's a bit recursive/backwards. The top level is the default.nix, which imports Nixpkgs, configures it with overlays, and declares a NixOS system. If the Nixpkgs is set in overlays themselves, there can be cases where the recursive nature of that gives trouble. For example if you try to use

{ pkgs, ... }: {
  imports = [
    (pkgs.nixpkgs + "/nixos/modules/...")
  ];
}

This would fail because of how modules themselves can change pkgs.

Or what if you override nixpkgs to break overlays entirely? Would it still work then because you're using overlays themselves to define it?

@bzm3r
Copy link
Author

bzm3r commented Dec 6, 2023

Yes, I think I understand. I missed the recursive aspect of it! 😅

@infinisil
Copy link
Owner

Also, I'm wondering if there is a way to obviate NIX_PATH entirely....will have to look into how it is read currently in the nixpkgs repo, but it would be nice if we could point it to read from a file instead...

At least it can be "avoided" in the rebuild script by just using -I instead, which I just did: 37b7f37

But really underneath nixos-rebuild is hardcoded to use <nixpkgs/nixos> with non-Flakes: https://github.com/NixOS/nixpkgs/blob/49cd2f2d1f1aeff17376d3ab52d4fc6e4caa7ed9/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh#L603

To avoid that we need some standardised way to configure Nixpkgs, and yes, Flakes is one way to do that.

@infinisil
Copy link
Owner

Oh and regarding the hosts NIX_PATH in

sanix/root.nix

Lines 19 to 23 in 37b7f37

nix.nixPath = [
"nixpkgs=${pkgs.path}"
"nixos-config=${toString ./root.nix}"
"nixpkgs-overlays=${toString ./nixpkgs/overlays.nix}"
];

This is there so commands work by default. Flakes got "rid" of that by introducing the Flakes registry, which is just a glorified version of the same impure NIX_PATH, see also NixOS/nix#7422

@bzm3r
Copy link
Author

bzm3r commented Dec 9, 2023

Also, I'm wondering if there is a way to obviate NIX_PATH entirely....will have to look into how it is read currently in the nixpkgs repo, but it would be nice if we could point it to read from a file instead...

At least it can be "avoided" in the rebuild script by just using -I instead, which I just did: 37b7f37

But really underneath nixos-rebuild is hardcoded to use <nixpkgs/nixos> with non-Flakes: https://github.com/NixOS/nixpkgs/blob/49cd2f2d1f1aeff17376d3ab52d4fc6e4caa7ed9/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh#L603

To avoid that we need some standardised way to configure Nixpkgs, and yes, Flakes is one way to do that.

As far as sanix is considered, this standardized way would be niv or npins, right?

@infinisil
Copy link
Owner

Indeed :)

@bzm3r
Copy link
Author

bzm3r commented Dec 12, 2023

Okay! I think this is all clear to me, and I'm happy with the updated setup. Thank you!

@bzm3r bzm3r closed this as completed Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants