5

I would like to move Haskell projects between my work computer and my laptop on a USB stick. I'm using the stack build system. My laptop is very often away from the Internet, sometimes when I initially insert the USB, so if I just copy the project, I'll be missing the GHC toolchain and all the libraries on the laptop. I want to be able to plug in to the laptop and work, even without being connected.

Various solutions I've seen tell me to use certain stack flags and copy over the ~/.stack directory, but I've never succeeded in getting a successful build - and it seems a rather fragile approach. I would also appreciate a bit of automation, and ideally some versioning support.

Would Nix help with this scenario? How about Nix' Docker integration features? (I have minimal Nix and no Docker experience, but I'm willing to learn if it will help me here.) I would like to retain the ability to use my laptop-based tooling, such as VS Code.

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
Ari Fordsham
  • 2,437
  • 7
  • 28
  • I like the idea of moving a Docker container around, if it's not too large. – Robert Harvey May 25 '21 at 13:56
  • maybe you just do a `stack install X` for all the libraries you use once you have Internet connection? For the same LTS this should yield the same environment where you can reuse the downloaded files – Random Dev May 25 '21 at 14:30
  • @Carsten I don't want to manually track which libraries I'm using. I also don't want to be tethered to an Internet connection. – Ari Fordsham May 25 '21 at 14:33
  • Nix would not be a good fit since the dependencies are stored in a global "Store" (`/nix/store`). You would have to have a custom installation of Nix on the USB stick itself, but this would be very complicated (moving the store to a non-standard location was a big problem when Apple announced that the new OSX would not allow us to have `/nix/store`). – fghibellini May 25 '21 at 14:51
  • There are tricks like `nix-copy-closure` but I don't think the ergonomics would be the best. – fghibellini May 25 '21 at 14:51
  • 1
    If you don't want to manually track which libraries you are using you can also try just downloading all libraries from Stackage: https://github.com/quchen/stackage-everything. Apparently it was only about 60 MB compressed in 2018. – Noughtmare May 25 '21 at 17:46
  • @Noughtmare That's not a bad idea - I'll investigate Stackage and Hackage mirrors. – Ari Fordsham May 26 '21 at 08:08
  • I believe Nix would be able to handle this well. I'm not sure what @fghibellini meant by it not being a good fit due to the store path. Why not just run a Nix environment in a Docker / VM if the path is an issue? – Chris Stryczynski Jun 06 '21 at 23:04
  • Perhaps you can clone your `nix-shell` environment of your Haskell project to another PC as is. I am at early stages of learning Nix/NixOS but it basically seems to be a perfect tool for such needs. [Caching `nix-shell`](https://fzakaria.com/2020/08/11/caching-your-nix-shell.html) and [nix-copy-closure your `nix-shell`](https://fzakaria.com/2020/09/28/nix-copy-closure-your-nix-shell.html) seem to be a good read. – Redu Jun 18 '21 at 12:43

0 Answers0