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

Is there a way to specify different nixpkgs for different hosts? #51

Open
akavel opened this issue May 7, 2024 · 4 comments
Open

Is there a way to specify different nixpkgs for different hosts? #51

akavel opened this issue May 7, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@akavel
Copy link

akavel commented May 7, 2024

Currently, I am trying to track nixpkgs versions separately for different hosts. My old flake.nix had the following:

{
  inputs = {
    # To update nixpkgs (and thus NixOS), pick the nixos-20.09 rev from
    # https://status.nixos.org/
    # (Or, alternatively, nixos-unstable rev.)
    # 
    # 22.05 @21.11.2022
    nixpkgs.url = "github:nixos/nixpkgs/cf63ade6f74bbc9d2a017290f1b2e33e8fbfa70a";
    # 23.11 @07.05.2024
    nixpkgs2.url = "github:nixos/nixpkgs/27c13997bf450a01219899f5a83bd6ffbfc70d3c";
    nixos-wsl.url = "github:nix-community/NixOS-WSL/main";
  };

  outputs = { self, nixpkgs, nixpkgs2, nixos-wsl }: {
    # choice will be done "automatically" based on hostname
    nixosConfigurations.myhost1 = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [ ./myhost1.nix ];
    };
    nixosConfigurations.myhost2 = nixpkgs2.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        nixos-wsl.nixosModules.default
        ./myhost2.nix
      ];
    };
  };
}

I'm trying to port this config to nixos-flake, to let me unify it with my home-manager configs. However, I noticed that nixos-flake seems to be hardcoded to use inputs.nixpkgs, and inputs are passed via flake-parts.lib.mkFlake { inherit inputs; }, so I don't see a clear way to use different nixpkgs between different nixosConfigurations inside nixos-flake. Do you have any suggestions how I could try doing this? I am ok to try modifying nixos-flake code, but I'd be grateful for suggestions how to try approaching that in such case; currently flake-parts is still quite confusing to me; and also you know nixos-flake better, so may have better ideas what approach could be better suited to it.

@srid
Copy link
Owner

srid commented Jun 5, 2024

@akavel Just wanted to leave a note saying that I'd be happy to satisfy this use case. In fact, I'd need it for myself as well. Just not sure what the best approach is. There is --override-input, but now we are externalizing the nixpkgs dependency outside of flake.nix ...

@srid srid added the enhancement New feature or request label Jun 5, 2024
@akavel
Copy link
Author

akavel commented Jun 8, 2024

@srid I'm afraid both flake-parts and nixos-flake keep being super confusing to me, and it looks like I still have hard time wrapping my head around either 😓 so I only wish I could suggest some solution... The only thing I can try to say is somewhat naively from user perspective; as such, looking e.g. at https://github.com/srid/nixos-config/blob/f1e560296d62c192c6a1a1dd1ca54c237a2cbf96/flake.nix, personally the first idea that comes to my mind, is I'd love if I could e.g. replace line 97-98:

  self.nixos-flake.lib.mkLinuxSystem
    ./systems/ax41.nix;

with something like:

  self.nixos-flake.lib.mkLinuxSystemWith { nixpkgs = inputs.nixpkgs2; }
    ./systems/ax41.nix;

@srid
Copy link
Owner

srid commented Jun 8, 2024

One approach we could adopt is to totally separate out the flakes. Each host gets its own flake.nix, but there's also a common flake (containing modules used by all hosts for example) that gets shared by these flakes. The whole thing can be in a mono repo, so we would need --override-input.

@srid
Copy link
Owner

srid commented Jun 12, 2024

One approach we could adopt is to totally separate out the flakes. Each host gets its own flake.nix, but there's also a common flake (containing modules used by all hosts for example) that gets shared by these flakes. The whole thing can be in a mono repo, so we would need --override-input.

Yup, I am able to get this working! Part of that work involves #54

I will document it all at the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants