Skip to content

Allow configuration of the Nixpkgs instance on a per-system basis #1892

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

Merged
merged 7 commits into from
Jun 5, 2025

Conversation

ndam-hexagon
Copy link
Contributor

@ndam-hexagon ndam-hexagon commented May 19, 2025

Description

This PR aims to allow setting some of the attribute of the config attribute set that is normally passed as argument when importing Nixpkgs.

An example that is currently not supported (but would be after this PR):

{
  pkgs = import nixpkgs {
    inherit system;
    overlays = [ ... ];
    config = {
      allowUnfree = true;
      allowBroken = true;
      cudaSupport = true;
      cudaCapabilities = [
        "7.5"
        "8.6"
        "8.9"
      ];
    };
  };
}

Context

We have a project where we work with CUDA and override various packages (e.g. OpenCV) to have CUDA support enabled. Currently, we are using devenv with the flake integration, but would like to now migrate to using the devenv command and devenv.yaml/devenv.nix to benefit from faster load times.

We also have the added complexity of supporting 2 architectures: x86 and aarch64 with incompatible sets of CUDA capabilities. We therefore needed to patch devenv in order to allow us to configure those settings on a per-system basis.

Changes in a nutshell

This PR modifies the config structure of the devenv.yaml file in the following ways:

  • Add a top-level element to enable/disable CUDA support for nixpkgs globally: cudaSupport
  • Add a new top-level element: config that can be used to configure on a per-system basis how devenv later configures its Nixpkgs instance

Here's an example of this new format for the config file:

# ... usual config

config:
  x86_64-linux:
    allowUnfree: true
    allowBroken: true
    cudaSupport: true
    cudaCapabilities:
      - "7.5"
      - "8.6"
      - "8.9"
  aarch64-linux:
    allowUnfree: true
    allowBroken: true
    cudaSupport: true
    cudaCapabilities:
      - "8.7"

The devenv/src/flake.tmpl.nix was modified in such a way that the config.<system>.<keys> take precedence over <keys> if present, but should not otherwise have an impact on existing configurations.

@ndam-hexagon ndam-hexagon force-pushed the dev/nixpkgs-config-per-system branch from 0f3fce7 to 90c3911 Compare May 19, 2025 14:52
@ndam-hexagon ndam-hexagon force-pushed the dev/nixpkgs-config-per-system branch from 90c3911 to ef5eb41 Compare May 26, 2025 13:11
@domenkozar
Copy link
Member

Hey! I'd change a bit the way the config is structured:

nixpkgs:
  allowUnfree: true
  allowBroken: false
  
  per-platform:
    x86_64-linux:
      allowUnfree: true
      allowBroken: true
    aarch64-darwin:
      allowUnfree: false

@ndam-hexagon
Copy link
Contributor Author

ndam-hexagon commented Jun 5, 2025

Hey! I'd change a bit the way the config is structured:

nixpkgs:
  allowUnfree: true
  allowBroken: false
  
  per-platform:
    x86_64-linux:
      allowUnfree: true
      allowBroken: true
    aarch64-darwin:
      allowUnfree: false

Sure. I'll make those changes and push a new commit. Are you otherwise ok with how I structured the changes?

@domenkozar
Copy link
Member

Hey! I'd change a bit the way the config is structured:

nixpkgs:
  allowUnfree: true
  allowBroken: false
  
  per-platform:
    x86_64-linux:
      allowUnfree: true
      allowBroken: true
    aarch64-darwin:
      allowUnfree: false

Sure. I'll make those changes and push a new commit. Are you otherwise ok with how I structured the changes?

Yeah, really good stuff :)

@ndam-hexagon
Copy link
Contributor Author

Given the changes you are proposing, should the old syntax still be accepted?

allowUnfree: true

Or should the only way to configure be:

nixpkgs:
    allowUnfree: true

@domenkozar
Copy link
Member

Yeah, we should still support the old way. And change docs for the nixpkgs :)

- Rename `config` to `nixpkgs`
- Change config format to the one proposed by @domenkozar
- Update documentation
- Update JSON schema
@ndam-hexagon ndam-hexagon force-pushed the dev/nixpkgs-config-per-system branch from ef5eb41 to 8e27fd7 Compare June 5, 2025 12:53
@ndam-hexagon
Copy link
Contributor Author

Now that think about it, the followings would be introduced with this PR at the top-level:

  • cudaSupport
  • cudaCapabilities

Do you want those to only be allowed within nixpkgs?

@domenkozar
Copy link
Member

Yes, thank you!

@domenkozar
Copy link
Member

Note that jsonschema will get automatically generated, see https://github.com/cachix/devenv/actions/runs/15467562476/job/43544279281#step:15:23

@ndam-hexagon
Copy link
Contributor Author

Note that jsonschema will get automatically generated, see https://github.com/cachix/devenv/actions/runs/15467562476/job/43544279281#step:15:23

Ah neat. I will remove those changes then.

@ndam-hexagon ndam-hexagon force-pushed the dev/nixpkgs-config-per-system branch from 4832477 to 7abf763 Compare June 5, 2025 16:13
@ndam-hexagon ndam-hexagon force-pushed the dev/nixpkgs-config-per-system branch from 7abf763 to 3c3ab4b Compare June 5, 2025 16:14
@domenkozar domenkozar merged commit cf469b0 into cachix:main Jun 5, 2025
213 of 274 checks passed
@ndam-hexagon ndam-hexagon deleted the dev/nixpkgs-config-per-system branch June 6, 2025 06:48
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.

2 participants