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

Nix build #5298

Closed
guilhermehas opened this issue Feb 12, 2019 · 18 comments
Closed

Nix build #5298

guilhermehas opened this issue Feb 12, 2019 · 18 comments
Labels

Comments

@guilhermehas
Copy link

I am trying to build with the command
nix-build
but I am having this problem
building '/nix/store/xdc8nr2pkxx6w04r9cp5hlwwjqk2na40-cabal2nix-pandoc.drv'... installing error: anonymous function at /nix/store/c9gjkn3a7w7wbdl8ws9g7n1mrmx978mb-cabal2nix-pandoc/default.nix:1:1 called without required argument 'HsYAML', at /nix/store/y0g35y0zdf3pkyjhmv34h3h1nkifivs9-source/pkgs/development/haskell-modules/make-package-set.nix:88:27

@jgm
Copy link
Owner

jgm commented Feb 12, 2019

@hamishmack added the default.nix and may be able to help.
If not, I'll probably just delete it as it may be out of date. I know nothing about nix, sorry.

@mb21 mb21 added the package label Feb 12, 2019
@guilhermehas
Copy link
Author

The problem is just with the default.nix file.

@jgm
Copy link
Owner

jgm commented Feb 12, 2019

I'm inclined to delete the default.nix file, since I don't know how to keep it up to date, and it's problematic if it's not kept up to date, since people will assume they can use it.

@peti
Copy link

peti commented Feb 14, 2019

👍 for deleting the default.nix file. This is a generated file and it should not be tracked in version control. Anyone who needs this file can just generate it easily by running:

$ cabal2nix . >default.nix

@guilhermehas
Copy link
Author

guilhermehas commented Feb 14, 2019

After using this command, I got this new nix file

{ mkDerivation, aeson, aeson-pretty, base, base64-bytestring
, binary, blaze-html, blaze-markup, bytestring, case-insensitive
, cmark-gfm, containers, criterion, data-default, deepseq, Diff
, directory, doctemplates, exceptions, executable-path, filepath
, Glob, haddock-library, hslua, hslua-module-text, HsYAML, HTTP
, http-client, http-client-tls, http-types, ipynb, JuicyPixels, mtl
, network, network-uri, pandoc-types, parsec, process, QuickCheck
, random, safe, SHA, skylighting, split, stdenv, syb, tagsoup
, tasty, tasty-golden, tasty-hunit, tasty-quickcheck, temporary
, texmath, text, time, unicode-transforms, unix
, unordered-containers, vector, weigh, xml, zip-archive, zlib
}:
mkDerivation {
  pname = "pandoc";
  version = "2.6.1";
  src = ./.;
  configureFlags = [ "-fhttps" "-f-trypandoc" ];
  isLibrary = true;
  isExecutable = true;
  enableSeparateDataOutput = true;
  libraryHaskellDepends = [
    aeson aeson-pretty base base64-bytestring binary blaze-html
    blaze-markup bytestring case-insensitive cmark-gfm containers
    data-default deepseq directory doctemplates exceptions filepath
    Glob haddock-library hslua hslua-module-text HsYAML HTTP
    http-client http-client-tls http-types ipynb JuicyPixels mtl
    network network-uri pandoc-types parsec process random safe SHA
    skylighting split syb tagsoup temporary texmath text time
    unicode-transforms unix unordered-containers vector xml zip-archive
    zlib
  ];
  executableHaskellDepends = [ base ];
  testHaskellDepends = [
    base base64-bytestring bytestring containers Diff directory
    executable-path filepath Glob hslua pandoc-types process QuickCheck
    tasty tasty-golden tasty-hunit tasty-quickcheck temporary text time
    xml zip-archive
  ];
  benchmarkHaskellDepends = [
    base bytestring containers criterion mtl text time weigh
  ];
  postInstall = ''
    mkdir -p $out/share
    mv $data/*/*/man $out/share/
  '';
  homepage = "https://pandoc.org";
  description = "Conversion between markup formats";
  license = stdenv.lib.licenses.gpl2;
}

And have this error using nix-build

error: cannot auto-call a function that has an argument without a default value ('mkDerivation')

@jgm jgm closed this as completed in b6c64bd Feb 14, 2019
@jgm
Copy link
Owner

jgm commented Feb 14, 2019 via email

@srid
Copy link

srid commented Mar 28, 2019

default.nix is a generated file and it should not be tracked in version control.

This is not necessarily true, especially if you use haskellPackages.developPackage instead of cabal2nix.

Having a default.nix also allows the developer to override dependencies to the exact version, or source repo, they would like the package to depend on.

@peti
Copy link

peti commented Mar 28, 2019

default.nix is a generated file and it should not be tracked in version control.

This is not necessarily true, especially if you use haskellPackages.developPackage instead of cabal2nix.

developPackage is a wrapper around cabal2nix.

@srid
Copy link

srid commented Mar 28, 2019

Yes, but I was referring to the cabal2nix command that is used to generate a default.nix. My point was that default.nix does not have to be generated.

@peti
Copy link

peti commented Mar 28, 2019

My point was that default.nix does not have to be generated.

What does it matter? The point is that it is a generated file and as such it should not be checked into the git repository because it can be derived automatically from the Cabal file.

@hamishmack
Copy link
Contributor

The point is that it is a generated file

Actually it was not default.nix.

Sorry, I should have pointed that out earlier.

@srid
Copy link

srid commented Mar 28, 2019

The point is that it is a generated file and as such it should not be checked into the git repository

Yes.

because it can be derived automatically from the Cabal file.

But that will not allow you to override library dependencies to the exact version, or different source repo. Or specify non-Haskell dependencies (eg: latex). I once tried writing a default.nix to use pandoc 2.x as a library in my own Haskell project (nixpkgs only had 1.x at that time), which involved overriding a bunch of dependencies although I had given up on it.

Actually it was not default.nix.

Oh yes. I doubt a mere cabal2nix-generated default.nix is going to work for a non-trivial project like pandoc anyway.

@hamishmack
Copy link
Contributor

Oh yes. I doubt a mere cabal2nix-generated default.nix is going to work for a non-trivial project like pandoc anyway.

It is getting pretty close though. I think a lot of the things that were in the old default.nix are in the output of cabal2nix now.

I did have a go a while back at updating it for use with a newer nixpkgs. Here is where I got to....

# This Nix file can be handy when working on the github version of pandoc.
#
# To build pandoc run:
#    nix-build
# To run a nix shell with everything needed to build pandoc with cabal:
#    nix-shell
# To build pandoc for use on Linux and macOS systems without Nix:
#    nix-build -A patched
{ pkgs ?
    import ((import <nixpkgs> {}).pkgs.fetchFromGitHub {
      owner = "NixOS"; repo = "nixpkgs";
      rev = "6450d8c5ca6f4a9de975897bccdebc15c68f1ec3";
      sha256 = "1fyzihzkwyl0g0lpiq59d37waxqzr590z28b0jp5q85x3p68vp2r";
    }) {} }:
let haskellPackages = pkgs.haskellPackages;
    overrides = self: super: { };
    source-overrides = {
      pandoc-types = pkgs.fetchFromGitHub {
        owner = "jgm";
        repo = "pandoc-types";
        rev = "177473c655a128b1d95e35b314c277a9d5e71427";
        sha256 = "1v6qqvrzrl2z6zbagh78vfis6slvvscnnq3qkk4jn448gl0s4qs3";
      };
    };
    filterHaskellSource = src:
      builtins.filterSource (path: type:
        pkgs.lib.all (i: i != baseNameOf path) [ ".git" "dist-newstyle" "cabal.project.local" "dist" ".stack-work" ".DS_Store" "default.nix" "result" ]
          && pkgs.lib.all (i: !(pkgs.lib.hasSuffix i path)) [ ".lkshf" ]
          && pkgs.lib.all (i: !(pkgs.lib.hasPrefix i path)) [ ".ghc.environment." ]
        ) src;

    # Normal nix derivation
    drv = (
        haskellPackages.extend (
          pkgs.lib.composeExtensions (
            haskellPackages.packageSourceOverrides source-overrides
          ) overrides
        )
      ).callCabal2nix "pandoc" (filterHaskellSource ./.) {};

    # Like drv but with static linking for haskell libraries
    static = pkgs.haskell.lib.justStaticExecutables (drv.overrideAttrs (old: {
        buildInputs = old.buildInputs ++ [
          pkgs.zlib.static
          haskellPackages.file-embed
        ];
        configureFlags = [
          "-fembed_data_files"
          "--disable-executable-dynamic"
        ];
      }));

    # Patch binaries for use on macOS and linux systems without nix
    # and bundle the required gmp and lua libraries
    patched = pkgs.stdenv.mkDerivation {
        name = "pandoc-patched";
        buildInputs = [
          static
          pkgs.zip
          pkgs.gnutar
        ];
        unpackPhase = "true";
        buildPhase = "true";
        installPhase = if pkgs.stdenv.isDarwin
          then ''
              mkdir -p $out/bin
              cp ${static}/bin/pandoc $out/bin
              cp ${pkgs.gmp}/lib/libgmp.10.dylib $out/bin
              cp ${pkgs.lua5_3}/lib/liblua.5.3.4.dylib $out/bin
              chmod +w $out/bin/*
              echo patching libgmp and liblua
              install_name_tool -id "@executable_path/libgmp.10.dylib" "$out/bin/libgmp.10.dylib"
              install_name_tool -id "@executable_path/liblua.5.3.4.dylib" "$out/bin/liblua.5.3.4.dylib"
              for fn in $out/bin/*; do
                echo patching $fn
                install_name_tool -change "${pkgs.libiconv}/lib/libiconv.dylib" /usr/lib/libiconv.dylib "$fn"
                install_name_tool -change "${pkgs.stdenv.libc}/lib/libSystem.B.dylib" /usr/lib/libSystem.B.dylib "$fn"
                install_name_tool -change "${pkgs.gmp}/lib/libgmp.10.dylib" "@executable_path/libgmp.10.dylib" "$fn"
                install_name_tool -change "${pkgs.lua5_3}/lib/liblua.5.3.4.dylib" "@executable_path/liblua.5.3.4.dylib" "$fn"
              done
              (cd $out/.. && zip -r $out/pandoc-macOS.zip `basename $out`/bin)
            ''
          else ''
              mkdir -p $out/bin
              cp ${static}/bin/pandoc $out/bin
              cp ${pkgs.gmp}/lib/libgmp.so* $out/bin
              cp ${pkgs.lua5_3}/lib/liblua.so* $out/bin
              chmod +w $out/bin/pandoc
              patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 $out/bin/pandoc
              patchelf --set-rpath '$ORIGIN' $out/bin/pandoc
              (cd $out/.. && tar -czf $out/pandoc-linux.tar.gz `basename $out`/bin)
            '';
    };
in if pkgs.lib.inNixShell then drv.env else drv // { inherit static patched; }

@srid
Copy link

srid commented Jul 8, 2019

I managed to install the latest pandoc using Nix and reflex-platform: https://github.com/srid/rib/pull/14/files

@mb21
Copy link
Collaborator

mb21 commented Jul 8, 2019

Depending on your use-case, you can use the default pandoc nix package: https://nixos.org/nixos/packages.html#pandoc-2, for example:

nix-shell --pure -p pandoc

@srid
Copy link

srid commented Jul 8, 2019

My use case is to use pandoc as a library along with reflex-dom. The later is best done using reflex-platform which pins a version of nixpkgs that has much older pandoc; hence the need to override it as I did above.

@reyman
Copy link

reyman commented Nov 6, 2021

@srid I found your comment by googling, actually the version of pandoc is really outdated (2.14.02) and i need a simple derivation for a flake to compile a latest version (2.14.2 or newer) . Do you have this in stock ? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants