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
haskellPackages.OpenAL: link with the OpenAL framework on Darwin #70150
Conversation
@mujx Thanks for sending this PR. I've confirmed that this fixes the build on MacOSX. Could you rebase this PR to get rid of the conflict, possibly on the |
@cdepillabout I rebased the branch on master, should I change the PR to point to |
@peti I've confirmed that this builds correctly on MacOSX. It should be ready to be merged in. For future reference, do you want PRs like this that change |
@@ -99,6 +99,12 @@ self: super: builtins.intersectAttrs super { | |||
|
|||
niv = enableSeparateBinOutput super.niv; | |||
|
|||
# Ensure the necessary frameworks for Darwin. | |||
OpenAL = overrideCabal super.OpenAL (drv: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use haskell.lib.addExtraLibrary
to add that extra dependency.
Yes, I agree. It seems unnecessary to have those kind of PRs go through |
librarySystemDepends = drv.librarySystemDepends | ||
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.darwin.apple_sdk.frameworks.OpenAL ]; | ||
}); | ||
OpenAL = addExtraLibrary super.OpenAL ([] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.darwin.apple_sdk.frameworks.OpenAL ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The
[] ++
bit is redundant. pkgs.lib.optional
might be a better choice thanpkgs.lib.optionals
.
@@ -99,6 +99,9 @@ self: super: builtins.intersectAttrs super { | |||
|
|||
niv = enableSeparateBinOutput super.niv; | |||
|
|||
# Ensure the necessary frameworks for Darwin. | |||
OpenAL = addExtraLibrary super.OpenAL (pkgs.lib.optional pkgs.stdenv.isDarwin [ pkgs.darwin.apple_sdk.frameworks.OpenAL ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference between optionals
and optional
is that the former takes a list argument whereas the latter takes an element
. Just changing the name of the function won't result in valid code. You have to adapt your arguments, too. You'll notice what I mean when you, like, test the patch you're submitting.
Also, if you want to pass a list of dependencies here, then you'll need to use addExtraLibraries
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still able to build the package with the current patch on macos & Linux (nix-env -f./ -iA haskellPackages.OpenAL
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. This is an unexpected consequence of the way Nix casts lists into a string by concatenating the individual elements cast to a string. In this particular case, that gives a usable result, i.e. the [pkg]
ends up being essentially the same thing as pkg
(which is what we really want here). It's kind of unfortunate that this bogus code still gives a correct result, mostly due to chance. It's on those occasions where one would really like Nix to have a type system.
@@ -99,6 +99,9 @@ self: super: builtins.intersectAttrs super { | |||
|
|||
niv = enableSeparateBinOutput super.niv; | |||
|
|||
# Ensure the necessary frameworks for Darwin. | |||
OpenAL = addExtraLibrary super.OpenAL (pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.OpenAL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should be similar to other changes already in the file:
OpenAL = addExtraLibrary super.OpenAL (pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.OpenAL); | |
OpenAL = if pkgs.stdenv.isDarwin | |
then addExtraLibrary super.OpenAL pkgs.darwin.apple_sdk.frameworks.OpenAL | |
else super.OpenAL; |
There is a small problem with the current code:
addExtraLibrary super.OpenAL (pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.OpenAL);
Here, addExtraLibrary
wants to take a derivation for its second argument. (If you grep through the nixpkgs source code for addExtraLibrary
, you can see that normally it takes things like udev
, libpcap
, etc.)
However, the output of optional
is a list:
$ nix repl '<nixpkgs>'
nix-repl> lib.optional true "foo"
[ "foo" ]
nix-repl> lib.optional false "foo"
[ ]
Now, in practice, I think that this still works out. The derivations passed to addExtraLibrary
eventually get passed to buildInputs
for the Haskell package derivation. Haskell package derivations eventually get built with stdenv.mkDerivation
, which apparently knows how to deal with inputs in sublists:
$ nix-shell -E 'with (import <nixpkgs> { }); runCommand "dummy" { buildInputs = [ gcc6 ]; } ""' --run 'gcc --version'
gcc (GCC) 6.5.0
$ nix-shell -E 'with (import <nixpkgs> { }); runCommand "dummy" { buildInputs = [ [ gcc6 ] ]; } ""' --run 'gcc --version'
gcc (GCC) 6.5.0
However, it is somewhat confusing to rely on this functionality when writing nix code, so it would be best to change the way it is currently written.
As an aside, you could also do the following:
addExtraLibraries super.OpenAL (pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.OpenAL);
This works because addExtraLibraries
expects a list of derivations as the second argument.
However, personally, I feel that just using an if
statement is the clearest way to write it. It is also used in other parts of the file already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you may want to just rebase your commits into a single, clean commit.
Sorry for going back and forth so much on this change!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I'm still new to nix so thanks for the patience.
I'm a bit confused on what are the best practices regarding the overrides because both the if-then
code and my original patch are already used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, the "best practices" are to use the functions provided in pkgs/development/haskell/lib.nix
.
However there are a lot of places not using the functions provided. Ideally they would all be fixed where possible.
The missing framework caused a build failure on Darwin. see #68306
@peti I think this should be ready for merging now, although you may want to squash all commits. |
Motivation for this change
The missing framework caused a build failure on Darwin. see #68306
Things done
sandbox
innix.conf
on non-NixOS)nix-env -f./nixpkgs -iA haskellPackages.OpenAL
)nix-env -f./nixpkgs -iA haskellPackages.OpenAL
)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)Notify maintainers
cc @