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

haskellPackages.OpenAL: link with the OpenAL framework on Darwin #70150

Merged
merged 5 commits into from Oct 5, 2019
Merged

haskellPackages.OpenAL: link with the OpenAL framework on Darwin #70150

merged 5 commits into from Oct 5, 2019

Conversation

mujx
Copy link
Contributor

@mujx mujx commented Oct 1, 2019

Motivation for this change

The missing framework caused a build failure on Darwin. see #68306

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS (nix-env -f./nixpkgs -iA haskellPackages.OpenAL)
    • other Linux distributions (nix-env -f./nixpkgs -iA haskellPackages.OpenAL)
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @

@cdepillabout
Copy link
Member

@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 haskell-updates branch? Once you do that, we can try to get this PR merged in.

@mujx
Copy link
Contributor Author

mujx commented Oct 4, 2019

@cdepillabout I rebased the branch on master, should I change the PR to point to haskell-updates instead?

@cdepillabout
Copy link
Member

cdepillabout commented Oct 4, 2019

@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 configuration-nix.nix to be based on the haskell-updates branch? I was thinking it wouldn't be necessary, because it won't affect the hackage2nix process. This PR is purely just fixing the build on MacOSX.

@@ -99,6 +99,12 @@ self: super: builtins.intersectAttrs super {

niv = enableSeparateBinOutput super.niv;

# Ensure the necessary frameworks for Darwin.
OpenAL = overrideCabal super.OpenAL (drv: {
Copy link
Member

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.

@peti
Copy link
Member

peti commented Oct 4, 2019

Do you want PRs like this that change configuration-nix.nix to be based on the haskell-updates branch? I was thinking it wouldn't be necessary, because it won't affect the hackage2nix process.

Yes, I agree. It seems unnecessary to have those kind of PRs go through haskell-updates.

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 ]);
Copy link
Member

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 than pkgs.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 ]);
Copy link
Member

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.

Copy link
Contributor Author

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).

Copy link
Member

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);
Copy link
Member

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:

Suggested change
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.

Copy link
Member

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!

Copy link
Contributor Author

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.

Copy link
Member

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.

@cdepillabout
Copy link
Member

@peti I think this should be ready for merging now, although you may want to squash all commits.

@peti peti merged commit 0b1fb4f into NixOS:master Oct 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants