haskell-nix / hnix-store

Haskell implementation of the Nix store
Apache License 2.0
87 stars 23 forks source link

Please, suit the testsuites to the environement they support #121

Closed Anton-Latukha closed 3 years ago

Anton-Latukha commented 3 years ago

We pretty frequently lately have a need to: overload .cabal with flags, disable some tests on macOS, add/remove Nix overrides for tests, and go into Nixpkgs to maintain tests, to fix some specific test that fails and not suited for some environment.

We can just check in the code the environment where tests are running and simply not run the tests that we know are not suited for that platform. That would allow us to stop flounce around configs and custom commands goalkeeping the tests.

This is projects-wide idea.

The check for macOS is simple. nix-build seems to obscure from programs where they build in, but I thing something like:

  execPath <- fmap (fromMaybe "") $ findExecutable "bash"
  if (isInfixOf "nix" $ execPath) && (isInfixOf "store" $ execPath)
    then (putStrLn $ show execPath)
    else error "Not in nix-build"

--- that tells that we run in nix-build, NixOS already would report other path, so we detected the nix-build.

After that is automated - all we would need to do - is to do is to check the PR in CI and merge the PR in green CI, and rightfully inform - mention the test specifics in the Readme, like "To run io-testsuite in Remote - install/run Nix in daemon multiuser mode", and if people would not read it - no biggy. And we would run CI with reference development requirements (which we nee there anyway) and check PRs through CI, so if in development someone had no ability to run tests for something - CI tests it for people.

Anton-Latukha commented 3 years ago

Got the environment from the nix-build, in fact there is a lot Nix-specific variables in the environment:

NIX_BINTOOLS=/nix/store/2xrj4wg0sn53lbvi6qgkv3vyyzf8c39a-binutils-wrapper-2.34
NIX_BINTOOLS_FOR_BUILD=/nix/store/2xrj4wg0sn53lbvi6qgkv3vyyzf8c39a-binutils-wrapper-2.34
NIX_BINTOOLS_WRAPPER_TARGET_BUILD_x86_64_unknown_linux_gnu=1
NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu=1
NIX_BUILD_CORES=8
NIX_BUILD_TOP=/build
NIX_CC=/nix/store/y78inja64xaaq6bx33nxn2h1lgw0jswk-gcc-wrapper-10.2.0
NIX_CC_FOR_BUILD=/nix/store/y78inja64xaaq6bx33nxn2h1lgw0jswk-gcc-wrapper-10.2.0
NIX_CC_WRAPPER_TARGET_BUILD_x86_64_unknown_linux_gnu=1
NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu=1
NIX_CFLAGS_COMPILE= -frandom-seed=dnjxac16lvkjs68x4bq0qdg9jjbsbh2g-hnix-store-remote-0.4.0.0 -isystem /nix/store/mla5rwv7y9ayphp44p205f34psb5l26q-nix-2.3.10-dev/include -isystem /nix/store/3hyw628cz7izbdiyx77vcmj137rwdzfh-boehm-gc-8.0.4-dev/include -isystem /nix/store/mla5rwv7y9ayphp44p205f34psb5l26q-nix-2.3.10-dev/include -isystem /nix/store/3hyw628cz7izbdiyx77vcmj137rwdzfh-boehm-gc-8.0.4-dev/include
NIX_CFLAGS_COMPILE_FOR_BUILD= -isystem /nix/store/mla5rwv7y9ayphp44p205f34psb5l26q-nix-2.3.10-dev/include -isystem /nix/store/3hyw628cz7izbdiyx77vcmj137rwdzfh-boehm-gc-8.0.4-dev/include -isystem /nix/store/mla5rwv7y9ayphp44p205f34psb5l26q-nix-2.3.10-dev/include -isystem /nix/store/3hyw628cz7izbdiyx77vcmj137rwdzfh-boehm-gc-8.0.4-dev/include -isystem /nix/store/mla5rwv7y9ayphp44p205f34psb5l26q-nix-2.3.10-dev/include -isystem /nix/store/3hyw628cz7izbdiyx77vcmj137rwdzfh-boehm-gc-8.0.4-dev/include
NIX_ENFORCE_NO_NATIVE=1
NIX_ENFORCE_PURITY=1
NIX_HARDENING_ENABLE=fortify stackprotector pic strictoverflow format relro bindnow
NIX_INDENT_MAKE=1
NIX_LDFLAGS=-rpath /nix/store/dnjxac16lvkjs68x4bq0qdg9jjbsbh2g-hnix-store-remote-0.4.0.0/lib64 -rpath /nix/store/dnjxac16lvkjs68x4bq0qdg9jjbsbh2g-hnix-store-remote-0.4.0.0/lib  -L/nix/store/d8248i42qg03smfvyhiw57vd8mkc2f42-ncurses-6.2/lib -L/nix/store/iy6j2166bpd03dfy8qz865ysawy0liar-libffi-3.3/lib -L/nix/store/c4mbjdvf719w1fw26k91kvg74bbz9mvl-gmp-6.2.1/lib -L/nix/store/9gmbz8j16hgln9pgagv74ly6mzsxfd45-boehm-gc-8.0.4/lib -L/nix/store/859dm0ls580aknphgib62xqwjavimj8j-nix-2.3.10/lib -L/nix/store/d8248i42qg03smfvyhiw57vd8mkc2f42-ncurses-6.2/lib -L/nix/store/iy6j2166bpd03dfy8qz865ysawy0liar-libffi-3.3/lib -L/nix/store/c4mbjdvf719w1fw26k91kvg74bbz9mvl-gmp-6.2.1/lib -L/nix/store/9gmbz8j16hgln9pgagv74ly6mzsxfd45-boehm-gc-8.0.4/lib -L/nix/store/859dm0ls580aknphgib62xqwjavimj8j-nix-2.3.10/lib
NIX_LDFLAGS_FOR_BUILD= -L/nix/store/d8248i42qg03smfvyhiw57vd8mkc2f42-ncurses-6.2/lib -L/nix/store/iy6j2166bpd03dfy8qz865ysawy0liar-libffi-3.3/lib -L/nix/store/c4mbjdvf719w1fw26k91kvg74bbz9mvl-gmp-6.2.1/lib -L/nix/store/9gmbz8j16hgln9pgagv74ly6mzsxfd45-boehm-gc-8.0.4/lib -L/nix/store/859dm0ls580aknphgib62xqwjavimj8j-nix-2.3.10/lib -L/nix/store/d8248i42qg03smfvyhiw57vd8mkc2f42-ncurses-6.2/lib -L/nix/store/iy6j2166bpd03dfy8qz865ysawy0liar-libffi-3.3/lib -L/nix/store/c4mbjdvf719w1fw26k91kvg74bbz9mvl-gmp-6.2.1/lib -L/nix/store/9gmbz8j16hgln9pgagv74ly6mzsxfd45-boehm-gc-8.0.4/lib -L/nix/store/859dm0ls580aknphgib62xqwjavimj8j-nix-2.3.10/lib -L/nix/store/d8248i42qg03smfvyhiw57vd8mkc2f42-ncurses-6.2/lib -L/nix/store/iy6j2166bpd03dfy8qz865ysawy0liar-libffi-3.3/lib -L/nix/store/c4mbjdvf719w1fw26k91kvg74bbz9mvl-gmp-6.2.1/lib -L/nix/store/9gmbz8j16hgln9pgagv74ly6mzsxfd45-boehm-gc-8.0.4/lib -L/nix/store/859dm0ls580aknphgib62xqwjavimj8j-nix-2.3.10/lib
NIX_LOG_FD=2
NIX_SSL_CERT_FILE=/no-cert-file.crt
NIX_STORE=/nix/store
sorki commented 3 years ago

I like the proposal.

Regarding env vars I'm not sure if it concerns us, only PATH is allowed to propagate when we start nix-daemon, the rest is mocked - https://github.com/haskell-nix/hnix-store/blob/master/hnix-store-remote/tests/NixDaemon.hs#L48-L56

Anton-Latukha commented 3 years ago

Ok, I reviewed this.

I do not think the initial idea is a good fit, indeed the code needs to be environment-aware, and handle environment situations, so to be able to handle the environment platform-independent. Introducing OS-platform-dependence is a hardcode in a way, the environment anyway always can be in intermediary state, for example if Linux env runs on some Windows or macOS etc..

But... platform detection library I'd considered benefitial.