再见 Opam,你好 Nix

  • Language preference and Opam issues: The author has been writing OCaml since November 2023 and enjoys it. But they have problems with Opam, the OCaml package manager. It has affected the development workflow and they want to get rid of it.
  • Introduction to Nix: The author saw Nix-related content on Twitch and started working at CarbonCloud where Haskell with Nix is used. This led them to try Nix with OCaml.
  • Reasons for moving to Nix: They faced frustrations with OPAM when working on multiple projects with different library versions. It often requires creating new switches and reinstalling. Nix can handle these situations better. Also, it takes time to release on the OPAM repository and Opam sometimes installs non-OCaml libraries without asking.
  • Moving to nix flakes: The author is transitioning to Nix to remove Opam. Nix allows for an easily reproducible developer environment and efficient building. It's straightforward to integrate OCaml with Nix using the nix-ocaml/nix-overlay repository.
  • Installing ocaml compiler and more: Instead of opam install, use ocamlPackages in nix buildInputs. For packages not on Nix, use builtins.fetchurl like in the example of installing code_mirror.
  • What it means for other developers: Other developers don't have to use Nix. But for contributing to the project, running nix develop gives the exact environment. The devShell config simplifies building and previewing.
  • Building for production: Nix enables building the project locally and in CI with nix build, ensuring consistent output and simplifying the build process.
  • Conclusion: The author may not use Nix for all OCaml projects. But they appreciate the simplicity of nix build in CI. There is an effort to increase the number of libraries installable with Nix Flakes, and the only downside is the time to set up a new dev environment.
阅读 12
0 条评论