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

How to use the output of cabal2nix in a flake? #641

Closed
malikwirin opened this issue Jan 20, 2025 · 1 comment
Closed

How to use the output of cabal2nix in a flake? #641

malikwirin opened this issue Jan 20, 2025 · 1 comment

Comments

@malikwirin
Copy link

Since Zephyr is marked as broken in nixpkgs because its dependencies are no longer available in nixpkgs. Before bumping the dependencies I was looking into solving the issue of using Nix as build tool on the Zephyr repo before bumping its dependencies. When using the the cabal2nix tool inside the repo I get the following output:

{ mkDerivation, aeson, ansi-terminal, ansi-wl-pprint, async, base
, boxes, bytestring, containers, directory, filepath, formatting
, Glob, hspec, hspec-core, HUnit, language-javascript, lib, mtl
, optparse-applicative, process, purescript, QuickCheck, safe, text
, transformers, unordered-containers, utf8-string
}:
mkDerivation {
  pname = "zephyr";
  version = "0.5.3";
  src = ./.;
  isLibrary = true;
  isExecutable = true;
  libraryHaskellDepends = [
    aeson ansi-terminal base boxes containers formatting
    language-javascript mtl purescript safe text unordered-containers
  ];
  executableHaskellDepends = [
    aeson ansi-terminal ansi-wl-pprint async base bytestring containers
    directory filepath formatting Glob language-javascript mtl
    optparse-applicative purescript text transformers utf8-string
  ];
  testHaskellDepends = [
    aeson base containers directory hspec hspec-core HUnit
    language-javascript mtl optparse-applicative process purescript
    QuickCheck text transformers
  ];
  testToolDepends = [ purescript ];
  homepage = "https://github.com/MaybeJustJames/zephyr#readme";
  description = "Zephyr, tree-shaking for the PureScript language";
  license = lib.licenses.mpl20;
  mainProgram = "zephyr";
}

Using it to create the following default.nix

{ pkgs ? import <nixpkgs> { }, ... }:

  let
    mkDerivation = pkgs.stdenv.mkDerivation;
    lib = pkgs.lib;
    haskellPkg = pkgName: pkgs.haskellPackages."${pkgName}";

    aeson = haskellPkg "aeson";
    ansi-terminal = haskellPkg "ansi-terminal";
    ansi-wl-pprint = haskellPkg "ansi-wl-pprint";
    async = haskellPkg "async";
    base = haskellPkg "base";
    boxes = haskellPkg "boxes";
    bytestring = haskellPkg "bytestring_0_12_1_0";
    containers = haskellPkg "containers_0_7";
    directory = haskellPkg "directory_1_3_9_0";
    filepath = haskellPkg "filepath_1_5_3_0";
    formatting = haskellPkg "formatting";
    Glob = haskellPkg "Glob";
    hspec = haskellPkg "hspec";
    hspec-core = haskellPkg "hspec-core";
    HUnit = haskellPkg "HUnit";
    language-javascript = haskellPkg "language-javascript";
    mtl = haskellPkg "mtl_2_3_1";
    optparse-applicative = haskellPkg "optparse-applicative";
    process = haskellPkg "process_1_6_25_0";
    purescript = haskellPkg "purescript";
    QuickCheck = haskellPkg "QuickCheck";
    safe = haskellPkg "safe";
    text = haskellPkg "text_2_1_1";
    transformers = haskellPkg "transformers_0_6_1_2";
    unordered-containers = haskellPkg "unordered-containers";
    utf8-string = haskellPkg "utf8-string";
  in mkDerivation rec {
    name = "zephyr";
    pname = name;
    src = ./.;
    isLibrary = true;
    isExecutable = true;
    libraryHaskellDepends = [
      aeson ansi-terminal base boxes containers formatting language-javascript mtl purescript safe text unordered-containers
    ];
    executableHaskellDepends = [
      aeson ansi-terminal ansi-wl-pprint async base bytestring containers
      directory filepath formatting Glob language-javascript mtl
      optparse-applicative purescript text transformers utf8-string
    ];
    testHaskellDepends = [
      aeson base containers directory hspec hspec-core HUnit
      language-javascript mtl optparse-applicative process purescript
      QuickCheck text transformers
    ];
    testToolDepends = [ purescript ];
    meta = {
      description = "Zephyr, tree-shaking for the PureScript language";
      license = lib.licenses.mpl20;
      homepage = "https://github.com/MaybeJustJames/zephyr";
      maintainers = with pkgs.lib.maintainers; [ malik ];
    };
    hydraPlatforms = lib.platforms.none;
    mainProgram = name;
  }

With the following flake.nix

{
  description = "Flake utils demo";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let pkgs = nixpkgs.legacyPackages.${system}; in
      {
        packages = rec {
          default = zephyr;
          zephyr = import ./default.nix { inherit pkgs; };
        };
      }
    );
}

When doing nix build . I get the following response:

error: builder for '/nix/store/8flm9jchd4526lda5nq0m8nb2sacq30p-zephyr.drv' failed to produce output path for output 'out' at '/nix/store/8flm9jchd4526lda5nq0m8nb2sacq30p-zephyr.drv.chroot/root/nix/store/bhx8nlfdaw5rlzjv2103p9kp8f0g1rcy-zephyr'

And when doing nix-build I get the following:

this derivation will be built:
  /nix/store/qviyy779xrq20fb8c3d14yq2mjwj9ai0-zephyr.drv
building '/nix/store/qviyy779xrq20fb8c3d14yq2mjwj9ai0-zephyr.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/mqscmdznjifxaml3704kgx5lnj98mmvy-zephyr
source root is zephyr
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
no configure script, doing nothing
Running phase: buildPhase
no Makefile or custom buildPhase, doing nothing
Running phase: installPhase
no Makefile or custom installPhase, doing nothing
Running phase: fixupPhase
error: builder for '/nix/store/qviyy779xrq20fb8c3d14yq2mjwj9ai0-zephyr.drv' failed to produce output path for output 'out' at '/nix/store/qviyy779xrq20fb8c3d14yq2mjwj9ai0-zephyr.drv.chroot/root/nix/store/wk1wyiqn1i4yblqybmx81hvl5m3y6fdh-zephyr'

I am obviously missing something but could not find the relevant documentation.

@malikwirin
Copy link
Author

Found the solution
should have used haskellPackages.mkDerivation instead of stdenv.mkDerivation

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

No branches or pull requests

1 participant