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 handle optional dependencies not available on the given (host) platform? #35906

Closed
shlevy opened this issue Feb 28, 2018 · 21 comments
Closed
Labels
6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: darwin Running or building packages on Darwin
Milestone

Comments

@shlevy
Copy link
Member

shlevy commented Feb 28, 2018

Example: strace optionally depends on libunwind, which hasn't yet been ported to RISC-V. Do we want the strace build expression to explicitly say optional libunwind.supportsTarget libunwind, or do we want the libunwind expression to simply be null on unsupported systems? Or is there another alternative?

@Ericson2314 @bgamari @dtzWill (we need @nixpkgs-cross...)

@Ericson2314
Copy link
Member

Ericson2314 commented Feb 28, 2018

assert and tryEval, lolololol.

In seriousness though, this is yet another excellent reason to peak at the meta of invalid derivations. Then we can make some adapter for a "best effort" dependency like pkg: if pkg.meta.available then pkg else null . Let's bring in @vcunat, @oxij and the other meta check people.

@Ericson2314
Copy link
Member

C.f. #35111 and #33057

@7c6f434c
Copy link
Member

There is also an option to have requiredBuildInputs and optionalBuildInputs with the latter filtered through a platform-support check.

Of course, this will bring us really close to a point where we need a single buildInputs parameter with a possibility to add attributes native, optional etc.

@shlevy
Copy link
Member Author

shlevy commented Feb 28, 2018

@Ericson2314 I think you misunderstood: I'm not asking how we check if something is supported, I'm asking where we check. If we check at libunwind, then strace works out of the box but we silently lose features. If we check at strace, then we explicitly opt-out of the features but have to be more verbose.

@shlevy
Copy link
Member Author

shlevy commented Feb 28, 2018

@7c6f434c yeah, that's a good way to do this. @Ericson2314 can you fit that into your mkDerivation model?

@vcunat
Copy link
Member

vcunat commented Feb 28, 2018

Peeking at meta of invalid derivations works already. EDIT: almost all attributes should work lazily, not just meta.

@Ericson2314
Copy link
Member

Ericson2314 commented Feb 28, 2018

@shlevy I was trying to answer that, just skipped a lot I guess.

  1. We can't just make libunwind null across the board, because some packages might require it.

  2. We don't want to make checking at strace too verbose.

Let's have our cake and eat it too:

# in lib
{ 
  optionalDep = dep: if dep.meta.available or false then dep else null;
}
# strace v1, shorter
{ stdenv, libunwind }:

stdenv.mkDerivation {
  buildInputs = [ (stdenv.lib.optionalDep libunwind) ];
}
# strace v2, longer
{ stdenv
, supportUnwinding ? libunwind.meta.availible or false
, libunwind
}:

stdenv.mkDerivation {
  buildInputs = stdenv.lib.optional supportUnwinding libunwind;
  /* somethingElse = ... supportUnwinding ..; */
}

@Ericson2314
Copy link
Member

Ericson2314 commented Feb 28, 2018

Of course, this will bring us really close to a point where we need a single buildInputs parameter with a possibility to add attributes native, optional etc.

@7c6f434c yeah, that's a good way to do this. @Ericson2314 can you fit that into your mkDerivation model?

That's a fine idea, and it fits in that I don't see affecting the core model at all. As long as we keep doing dependency propagation in bash, We'll need to convert that to basically what we have anyways.

@shlevy
Copy link
Member Author

shlevy commented Feb 28, 2018

Cool, sounds good. I'll go with the optionalFoo approach until optionalInputs etc. is available.

@shlevy shlevy closed this as completed Feb 28, 2018
@Ericson2314
Copy link
Member

optionalFoo is which approach? You mean making my library helper like that?

@Ericson2314
Copy link
Member

See also #34444 for making the meta checks work for cross.

@7c6f434c
Copy link
Member

Is it a good idea to (eventually) handle native-ness in the same way? Or propagation?

@Ericson2314
Copy link
Member

@7c6f434c I'm open to that. I mean I think of deps not in terms of the names but the two axes (see unstable nixpkgs manual), so the flattening that top-level attrs do is unfortunate. The limitations of bash mean that effectively we'll convert away from this stuff in the end so it must be just an easy superficial change.

@shlevy
Copy link
Member Author

shlevy commented Feb 28, 2018

@Ericson2314 so I'd have foo attribute and an optionalFoo attribute that is null on unsupported systems and thus can be safely added to inputs.

Speaking of limitations of bash... We may want to take advantage of __structuredAttrs = true here.

I'm definitely in favor of inputs being a list (set?) of packages with optional tags like buildTime = true and propagated = false if we can make that work nicely.

@Ericson2314
Copy link
Member

Ericson2314 commented Feb 28, 2018

@shlevy errrr not to bikeshed, but I must say I like my optionalDep helper better. I don't think optionalFoo scales elegantly. If we end up making an optionalFoo attribute for every Linux-only package a Darwin package could use on Linux, for example, that's a lot of extra bloat in all-packages.nix.

CC @NixOS/darwin-maintainers

@Ericson2314 Ericson2314 reopened this Feb 28, 2018
@Ericson2314 Ericson2314 added 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: darwin Running or building packages on Darwin labels Feb 28, 2018
@Ericson2314 Ericson2314 changed the title How to handle optional dependencies to ported to a given host? How to handle optional dependencies not available on the given (host) platform? Feb 28, 2018
@Ericson2314 Ericson2314 added this to the 18.03 milestone Feb 28, 2018
@Ericson2314
Copy link
Member

(Renamed because I don't see this as a cross-specific issue but general portability one. Reopened waiting on the darwin people's input more than my little bike-shed above.)

@shlevy
Copy link
Member Author

shlevy commented Feb 28, 2018

Right, that's better.

@7c6f434c
Copy link
Member

@Ericson2314 I wonder how to treat noarch packages in the two-axis model (for example, fonts — and yes, they are needed in the build time).

@oxij
Copy link
Member

oxij commented Mar 1, 2018 via email

@shlevy
Copy link
Member Author

shlevy commented Mar 2, 2018

Action item tracked in #36226

@7c6f434c
Copy link
Member

7c6f434c commented Mar 3, 2018

Unfortunately, null provides a way to quickly remove some dependencies without adding extra support into packages. USE flags require too many changes across the tree and will be hard to negotiate; also, a global override of null ensures that success does mean «no such packages is used», USE flags with Nixpkgs callPackage require active maintenance and vigilance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: darwin Running or building packages on Darwin
Projects
None yet
Development

No branches or pull requests

5 participants