this post was submitted on 11 Oct 2024
7 points (100.0% liked)

Nix / NixOS

1707 readers
31 users here now

Main links

Videos

founded 1 year ago
MODERATORS
 

edit: for the solution, see my comment below

I need/want to build aeson and its subproject attoparsec-aeson from source (it's a fork of the "official" aeson), but I'm stuck... can you help out?

The sources of attoparsec-aeson live in a subdirectory of the aeson ones, so I have the sources:

aeson-src = fetchFromGitHub {
  ...
};

and the "main" aeson library:

aeson = haskellPackages.mkDerivation {
  pname = "aeson";
  src = aeson-src;
  ...
};

When I get to attoparsec-aeson however I run into a wall: I tried to follow the documentation about sourceRoot:

attoparsec-aeson = haskellPackages.mkDerivation {
  pname = "attoparsec-aeson";
  src = aeson-src;
  sourceRoot = "./attoparsec-aeson"; # maybe this should be "${aeson-src}/attoparsec-aeson"?
                                     # (it doesn't work either way)
  ...
};

but I get

 error: function 'anonymous lambda' called with unexpected argument 'sourceRoot'

Did I fail to spot some major blunder (I am nowhere near an expert)? Does sourceRoot not apply to haskellPackages.mkDerivation? What should I do to make it work?

BTW:

IDK if this may cause issues, but the attoparsec-aeson sources include symlinks to files in the "main" attoparsec sources:

~/git-clone-of-attoparsec-sources $ tree attoparsec-aeson/
attoparsec-aeson/
├── src
│   └── Data
│       └── Aeson
│           ├── Internal
│           │   ├── ByteString.hs -> ../../../../../src/Data/Aeson/Internal/ByteString.hs
│           │   ├── Text.hs -> ../../../../../src/Data/Aeson/Internal/Text.hs
│           │   └── Word8.hs -> ../../../../../src/Data/Aeson/Internal/Word8.hs
│           ├── Parser
│           │   └── Internal.hs
│           └── Parser.hs
├── attoparsec-aeson.cabal
└── LICENSE
top 7 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 3 days ago

In case anyone comes here with the same problem, the solution is:

attoparsec-aeson = haskellPackages.mkDerivation {
  ...
  postUnpack = ''
    mv source source-aeson
    cp -rL source-aeson/attoparsec-aeson source
    rm -fr source-aeson
  '';
  ...
};
```*___*
[–] [email protected] 14 points 1 week ago (1 children)

This may or may not be helpful to you, but I haven’t had to delve into dependency management because I use ‘hix’ to provision and build my Haskell dev environment. I’d highly recommend it. It will simply parse you cabal file and provision all dependencies. I’m hoping such tooling comes to Purescript next because purs-nix is out of date with the new spago).

Here’s a super simple project where I used it:

https://github.com/harryprayiv/XY_math

Ps. I also recommend looking into IOHK’s Haskell tooling and their devshell, which I like to bring into most of my Haskell dev environments.

[–] [email protected] 2 points 1 week ago (1 children)

I agree: flakes are great for development (and not only)!

Unfortunately I still need to build that third party project from source :)
Maybe I should look into disregarding the whole haskellPackages infrastructure and just build with cabal via a shell script.. IDK if that would be accepted in nixpkgs though :/

[–] [email protected] 13 points 1 week ago (1 children)

True! I wonder if the same is true for deriving via cabal2nix.

[–] [email protected] 2 points 1 week ago

cabal2nix doesn't care about any source-repository-package in cabal.project (I think it doesn't even read that file?).

In my case, it generated a project that depended on the aeon from nixpkgs (which IIUC in turn comes from hackage) rather than the forked version.

[–] four 4 points 1 week ago (1 children)

I'm also not a nix expert and I'm not too familiar with Haskell build ecosystem, but doesn't the buildTarget argument do what you need? https://nixos.org/manual/nixpkgs/stable/#haskell-derivation-args (it's the last on the list)

Name of the executable or library to build and install. If unset, all available targets are built and installed.

[–] [email protected] 2 points 1 week ago

That's the thing you want to build (a single project may generate multiple executables - eg. a server and a client) so it won't help in this case but... I must say, I am impressed and really grateful that you went and looked that up for me! Thanks, mate!