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

How to toggle optional dependencies #572

Closed
blackliner opened this issue Jul 20, 2024 · 4 comments
Closed

How to toggle optional dependencies #572

blackliner opened this issue Jul 20, 2024 · 4 comments

Comments

@blackliner
Copy link

blackliner commented Jul 20, 2024

Is it possible to use nixpkgs_package and change the optional dependencies? See for example: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/opencv/default.nix#L46-L54

something like

load("@rules_nixpkgs_core//:nixpkgs.bzl", "nixpkgs_package")
load("//packages/thirdparty/nix:defs.bzl", "NIX_REPOSITORIES")

def opencv():
    nixpkgs_package(
        name = "opencv4",
        repositories = NIX_REPOSITORIES,
        build_file = "//packages/thirdparty/opencv:BUILD.bazel.tmpl",
        optionals = [ {"enableGtk2": False}, {"enableJPEG": True} ]
    )
@aherrmann
Copy link
Member

I think it should be possible to achieve this using the existing nixopts attribute.
Something along the lines of the following (not tested)

    nixpkgs_package(
        name = "opencv4",
        repositories = NIX_REPOSITORIES,
        build_file = "//packages/thirdparty/opencv:BUILD.bazel.tmpl",
        nixopts = [ "--arg", "enableGtk2", "false", "--arg", "enableJPEG", "true" ]
    )

@blackliner
Copy link
Author

blackliner commented Aug 14, 2024

Doesn't seem to work. Looking at https://ryantm.github.io/nixpkgs/using/overrides/, it mentions .override that can be used in derivations. Is there a way to use the command line to provide overrides? Or other means with nixpkgs_package

Would NixOS/nix#5766 be the missing part?

Could we write a proxy default.nix for the time being to set the override? This does NOT do the trick yet :-/

{ pkgs ? import <nixpkgs> {} }:

let
  opencv4 = pkgs.opencv4.overrideAttrs (previousAttrs: {
    enableEXR = false;
  });
in
opencv4

@aherrmann
Copy link
Member

I see, in that case this should be doable using the nix_file_content attribute to provide a Nix expression, see example in tests.
Something like

    nixpkgs_package(
        name = "opencv4",
        repositories = NIX_REPOSITORIES,
        build_file = "//packages/thirdparty/opencv:BUILD.bazel.tmpl",
        nix_file_content = "let pkgs = import <nixpkgs> { config = {}; overlays = []; }; in pkgs.opencv.override { enableEXR = false; }",
    )

Would NixOS/nix#5766 be the missing part?

That would make it possible to configure the override using nixopts. But, nix_file_content should also work.

@blackliner
Copy link
Author

Thank you, this workaround did it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants