Git Product home page Git Product logo

Comments (6)

m4dc4p avatar m4dc4p commented on June 19, 2024 2

Accidently re-opened - nothing needs to change. Thanks for the tip about applyPatches, I will look into that!

from cabal2nix.

m4dc4p avatar m4dc4p commented on June 19, 2024 1

Totally get it, and I appreciate your help. This is unfortunately in the middle of a large commercial project and I don't have the time/energy to cut that down to a manageable chunk.

For posterity, note that I essentially can't modify the source repository here (xxx-gogol), so checking in a cabal file isn't really an option. I have to make changes to the downloaded sources for GHC 9 compatability, thus the additional dependency I'm trying to add.

I was able to implement a solution that patches the sources first, then uses those patched sources as input to cabal2nix. It looks something like this:

  xxx-gogol-patch = stdenv.mkDerivation {
    patches = ./xxx-gogol.patch;
    src = sources.xxx-gogol;
    name = "xxx-gogol-patch";
    dontConfigure = true;
    dontBuild = true;
    dontInstall= true;
    postPatch = ''
      mkdir $out
      cp -R . $out
    '';
  };


  # Use the patched sources from above to generate nix expression for xxx-gogol,
  # rather than raw sources downloade by niv. If we instead applied the ./xxx-gogol.patch
  # file here (via `appendPatch` or any other mechanism), it won't have any effect, because
  # cabal2nix always runs before any patching is done, and the nix expression it generates does
  # not show the dependency on singletons-th.
  xxx-gogol = hfinal.callCabal2nix "xxx-gogol" "${xxx-gogol-patch.out}" { };

from cabal2nix.

cdepillabout avatar cdepillabout commented on June 19, 2024

My guess is that you are calling appendPatch and callCabal2nix in the wrong order.

For instance, calling cabal2nix cabal://lua-1.0.0 is going to give an output like this:

{ mkDerivation, base, bytestring, lib, tasty, tasty-hunit }:
mkDerivation {
  pname = "lua";
  version = "1.0.0";
  sha256 = "289d4ebb54e92d7c3955a56b1671872343d3f841c2b91abba26ad39ebc06c153";
  libraryHaskellDepends = [ base bytestring ];
  testHaskellDepends = [ base bytestring tasty tasty-hunit ];
  homepage = "https://hslua.github.io/";
  description = "Lua, an embeddable scripting language";
  license = lib.licenses.mit;
}

This cabal2nix call has already called hpack, and read the resulting lua.cabal file to turn it into the above Nix derivation. Your call to appendPatch happens after this, but it is already too late. The Nix derivation has already been produced.

I think your two choices here are either to patch sources.xxx-gogol before calling cabal2nix, or just add the singletons-th dependency after calling cabal2nix. In Nixpkgs, we generally take the second approach. Here's a random example:

https://github.com/NixOS/nixpkgs/blob/9d23b4c6c949947902d599a0fdc711f35f31310c/pkgs/development/haskell-modules/configuration-common.nix#L1771

from cabal2nix.

m4dc4p avatar m4dc4p commented on June 19, 2024

Thanks for the help! How would I patch the sources before calling cabal2nix? I suppose I'd have to create a derivation with just the sources for xxx-gogol, patch those, then call cabal2nix over that? Sounds much cleaner than below but also harder!

Regardless, addBuildDepend pretty much did the trick. However, the cabal file still needed to get regenerated, and somehow libraryHaskellDepends didn't have singletons-th in it. But I was able to add the library by hand, and updated postPatch so it would run hpack again.

This is what I ended up with:

addBuildDepend singletons-th (overrideCabal (
      appendPatch (
        hfinal.callCabal2nix "xxx-gogol" sources.xxx-gogol { }
      ) [./xxx-gogol.patch]
    ) (drv: {
      libraryHaskellDepends = drv.libraryHaskellDepends ++ [ singletons-th ];
      postPatch = ''
        hpack
        '';
    }));

from cabal2nix.

cdepillabout avatar cdepillabout commented on June 19, 2024

Without a fully reproducible example, it is hard to help you, but I thought that all you'd need would be something like this:

addBuildDepend singletons-th (hfinal.callCabal2nix "xxx-gogol" sources.xxx-gogol { })

Although I'm not sure if you have some specific hpack-related problems to work around. You should probably be checking the xxx.gogol.cabal file into your repo as well if you're not already: https://www.fpcomplete.com/blog/storing-generated-cabal-files/.

from cabal2nix.

sternenseemann avatar sternenseemann commented on June 19, 2024

How would I patch the sources before calling cabal2nix?

nixpkgs has a simpler function for this, called applyPatches.

I don't see how this is a cabal2nix issue really, it behaves correctly in this example in my opinion. Can you state what you would like to change?

from cabal2nix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.