agentm / project-m36

Project: M36 Relational Algebra Engine
The Unlicense
876 stars 47 forks source link

Fails to build in nix #350

Closed goosetherumfoodle closed 1 year ago

goosetherumfoodle commented 1 year ago

I've been unable to add this as a dependency to a nix project. I'm on nixos.

I can reproduce with a simple cabal file:

...
library
  exposed-modules:
      Hello
  hs-source-dirs:
      library
  ghc-options: -Wall
  build-depends:
      base
    , project-m36
  default-language: Haskell2010

and a default.nix pointing to the latest nixpkgs and the latest project-m36:

let
  pkgSrc = fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/tags/22.05.tar.gz";
  pkgs = import pkgSrc {};
  hsPkgs = pkgs.haskellPackages.override {
    overrides = self: super: {
      project-m36 = import (fetchTarball "https://github.com/agentm/project-m36/archive/refs/tags/v0.9.5.tar.gz");
    };
  };
in
hsPkgs.developPackage {
  root = ./.;
  modifier = drv:
    pkgs.haskell.lib.addBuildTools drv (with pkgs.haskellPackages;
      [
        cabal-install
        ghcid
        hpack
      ]);
}

With this setup, nix-build fails. It looks like a test fails while trying to make an http request:

  Test suite test-tutoriald-import-tutoriald: RUNNING...
### Error in:   1                         
HttpExceptionRequest Request {
  host                 = "raw.githubusercontent.com"
  port                 = 443
  secure               = True
  requestHeaders       = []
  path                 = "/agentm/project-m36/master/test/TutorialD/Interpreter/Import/httpimporttest.tutd"
  queryString          = ""
  method               = "GET"
  proxy                = Nothing
  rawBody              = False
  redirectCount        = 10
  responseTimeout      = ResponseTimeoutDefault
  requestVersion       = HTTP/1.1
}
 (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [AI_ADDRCONFIG], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = <assumed to be undefined>, addrCanonName = <assumed to be undefined>}, host name: Just "raw.githubusercontent.com", service name: Just "443"): does not exist (Name or service not known))
Cases: 2  Tried: 2  Errors: 1  Failures: 0
YuMingLiao commented 1 year ago

You may use pkgs.haskell.lib.dontCheck to bypass the test-suite of a package if you want to skip it.

project-m36 = pkgs.haskell.lib.dontCheck (import (fetchTarball "https://github.com/agentm/project-m36/archive/refs/tags/v0.9.5.tar.gz"));

agentm commented 1 year ago

Indeed- the tests for the tagged releases always pass, so you can cut your build time by cutting out the tests.

In this particular case, I would guess that there is some proxy/firewall blocking the DNS response.

Does the following, equivalent curl command succeed in the same environment?

curl 'https://raw.githubusercontent.com/agentm/project-m36/master/test/TutorialD/Interpreter/Import/httpimporttest.tutd'

It could be a fair request to have the test point at a local HTTP server, but I am curious as to what is actually blocking the DNS lookup.

goosetherumfoodle commented 1 year ago

I'm not a nix pro and may be misunderstanding, but i believe that network requests are discouraged during the nix build as sources of non-determinism. I'm not at my dev machine right now, but I probably have sandbox-mode enabled, which may be the source of the difference on my machine.

See the 'Sandboxing' section: https://nixos.wiki/wiki/Nix_package_manager#Sandboxing

Some quick googling gives me the impression that people disable network requests for nix builds: https://discourse.nixos.org/t/dealing-with-tests-that-require-networking-support/13804/3

goosetherumfoodle commented 1 year ago

I confirmed my nixos box does indeed have sandbox mode set. And the curl request mentioned succeeds.

Interestingly, I just ran the solution above, with the same config files in my first post, and that got me past the tests but then brought up a new error:

Setup: Encountered missing or private dependencies:
project-m36

Seems like cabal can't find the project, even though it's definitely compiling it.

Edit. Getting the same missing or private dependencies result when i switch off sandbox mode. Now I'm wondering if either I'm the only one compiling this with nix on nixos, or if there's just something particular about my nixos install... I haven't encountered this elsewhere though.

YuMingLiao commented 1 year ago
{ pkgs ? import <nixpkgs> { } }:
with pkgs.haskell.lib; {

  # curryer-rpc-0.2.1
  allowBroken = true;
  packageOverrides = super:
    let self = super.pkgs;
    in rec {
      haskellPackages = haskell.packages.ghc924;
      haskell = super.haskell // {
        packages = super.haskell.packages // {
          ghc924 = super.haskell.packages.ghc924.override {
            overrides = self: super: {
              #to all haskell packages.
              mkDerivation = drv:
                super.mkDerivation (drv // {
                  doCheck = false;
                  doHaddock = false;
                });
               curryer-rpc = self.callHackageDirect {
                      pkg = "curryer-rpc";
              ver = "0.2.2";
              sha256 = "sha256-c4DgpJV3GZl2oW55RR56xps4lGuwTFQzYrJP8VeLLds="; } {};
               fast-builder = doJailbreak super.fast-builder;
               project-m36 = self.callHackageDirect { 
                 pkg = "project-m36";
                 ver = "0.9.5";
                 sha256 = "sha256-uDc7PB01uVyXSSf4t/v2F5ZeOOHu+xCopvDAt7XBquE=";}  {};
           };
          };
        };
      };
    };

}

I may not fully understand how import fetchTarball works. My nix channel is nixos-22.05 now. The code above is my ~/.config/nixpkgs/config.nix. It can get project-m36 working in my computer.

agentm commented 1 year ago

Not calling out to the Internet is a fair request. We can just start a local HTTP server to check that functionality.

Project:M36 also uses nix to build the docker images, in case you need more nix examples to get going.

YuMingLiao commented 1 year ago

Setup: Encountered missing or private dependencies: project-m36

In nix repl "<nixpkgs>", enter haskellPackages.project-m36, what does it say?