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

feat: Pass through individual channel configuration #128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lpchaim
Copy link

@lpchaim lpchaim commented Sep 18, 2024

While looking for a way to achieve per host nixpkgs configurations within snowfall a while ago (see #106), I found out it (very understandably) wasn't a supported use case. I've since familiarized myself some more with both nix and snowfall, so I figured I'd try and give solving that issue cleanly a shot. Hopefully the solution I came up with makes sense!

Essentially, channel-specific configuration is now passed through to flake-utils-plus.mkFlake, allowing channels to have distinct settings and making so individual hosts can have their channel changed. Additionally, the same overlays that were once applied only to the default nixpkgs channel are now also applied to any other user-specified channels automatically.

As a demonstration, the following is a minimal working snippet from my personal flake showcasing how I manage to enable cuda support for my one host with a NVIDIA GPU without affecting the other hosts.

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nixpkgs-cuda.follows = "nixpkgs";
    snowfall-lib.url = "github:snowfallorg/lib";
  };

  outputs = inputs @ {self, ...}:
    snowfallLib.mkFlake {
      inherit inputs;
      src = ./.;

      channels-config = {
        allowUnfree = true;
      };
      channels.nixpkgs-cuda.config = {
        allowUnfree = true;
        cudaSupport = true;
      };

      systems.hosts.desktop.channelName = "nixpkgs-cuda";
    }
}

Channel-specific configuration is now also passed through to
flake-utils-plus.mkFlake, allowing channels to have distinct settings and
allowing for channel selection for individual hosts.
Copy link
Member

@jakehamilton jakehamilton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! One quick question, otherwise this looks good to go pending some testing :)

extra-overlays = full-flake-options.overlays or [];
};
})
({nixpkgs = {};} // channels);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the default nixpkgs here if we are allowing fully dynamic channel configuration? I think it is possible that the user has channels other than one named nixpkgs. The previous version of Snowfall Lib made the assumption that inputs.nixpkgs would always exist, but maybe we don't need to anymore.

Copy link
Author

@lpchaim lpchaim Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say it's still desirable as a fallback. As is, removing it means no inputs are processed at all if the user doesn't go out of their way to configure specific channels, which breaks some valid configurations.

I tried to automatically discover nixpkgs inputs to apply the overlays to all of them out of the box and found some existing solutions but since they tended to feel quite hacky, I went with this because it's backwards compatible with the original behavior while still allowing for user customization. I figured nixpkgs + a handful of oddball channels would fit the vast majority of use cases, so it didn't sound worth the trouble.

@RuRo
Copy link

RuRo commented Nov 26, 2024

Hi @lpchaim I was wondering if you ever managed to make this work?

I think the current implementation mostly works with one minor annoyance - it seems that the pkgs argument that is passed to the modules/nixos/**/default.nix modules is still hardcoded to use the nixpkgs channel here:

pkgs = user-inputs.self.pkgs.${system}.nixpkgs;

It seems that the "correct" version of nixpkgs is available in the channel parameter, but IMHO, pkgs should ideally also refer to the correct instance of nixpkgs.

I am actually not 100% sure, why that line is even needed. I tried commenting it out and the default pkgs (passed by fup? or maybe by lib.nixosSystem? I am not sure) was already seemingly the correct instance of nixpkgs.

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

Successfully merging this pull request may close these issues.

3 participants