Using files with test vectors for `nix build`

Hello,

I’m getting started with nix for Haskell using haskell-flake. When I run nix build, some of my tests fail because they can’t find the file I’m loading as part of the test, even though the file is in the project root folder.
I’m assuming that the haskell-flake tooling is filtering these files out of the src because they’re JSON, how can I include them for the testing phase?

The tests succeed if I use nix develop and then cabal test.

You forgot to git-add the files most likely.

I confirmed that the files are tracked in git.

In that case, a minimal example or the actual code would be helpful.

For the Haskell build, I’m using pretty boilerplate haskell-flake, that’s why I’m thinking it probably has some filtering of files built-in.

This is the summarized flake:

{
  description = "The Haskell library for interaction with the Zcash protocol";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    flake-parts.url = "github:hercules-ci/flake-parts";
    haskell-flake.url = "github:srid/haskell-flake";
    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    crane.url = "github:ipetkov/crane";
    foreign-rust.url = "git+https://code.vergara.tech/Vergara_Tech/haskell-foreign-rust?ref=main";
    hexstring.url = "git+https://code.vergara.tech/Vergara_Tech/haskell-hexstring?ref=master";
  };
  outputs = inputs @ {
    self,
    nixpkgs,
    flake-parts,
    rust-overlay,
    crane,
    foreign-rust,
    hexstring,
    ...
  }:
    flake-parts.lib.mkFlake {inherit inputs;} {
      systems = nixpkgs.lib.systems.flakeExposed;
      imports = [inputs.haskell-flake.flakeModule];

      perSystem = {
        self',
        pkgs,
        config,
        inputs',
        system,
        ...
      }: let
        craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default));
        zcashwrapper = <summarized derivation>
      in
      {
        _module.args.pkgs = import inputs.nixpkgs {
          inherit system;
          overlays = [(import inputs.rust-overlay)];
        };
        
        haskellProjects.default = {
          packages = {
            foreign-rust.source = inputs.foreign-rust;
            hexstring.source = inputs.hexstring;
          };
          settings = {
            rustzcash_wrapper.custom = _: zcashwrapper pkgs;
            borsh = {
              broken = false;
            };
            foreign-rust = {
              check = false;
            };
          };


          devShell = {
          };
        };

        # haskell-flake doesn't set the default package, but you can do it here.
        packages.default = self'.packages.zcash-haskell;
      };
    };
}

When I say a minimal example, I meant one that we could use to build and verify the behavior you’re seeing :slight_smile:

Here is a MWE.

nix build fails on checkPhase.
nix develop, cabal test succeeds.

1 Like