Not sure how to go about doing what I want to do

I’m having a hard time wrapping my head around the entirety of nix and how I should/shouldn’t be doing things. I’m trying to figure out the best way of setting up development environments with a flake. I hop between different languages/pkg managers but my general question remains the same. How do I manage dependencies?

Currently I’m trying to setup an OCaml project and install dream via opam. It’s not in the ocamlPackages so I figure I have to build it. I’m not really sure the idiomatic way to setup a flake with a devshell that can build a package. Should I even bother trying to do that or just install a package like normal?

you have probably found the wiki about OCaml - NixOS Wiki

Sometimes it’s a good start, but sometimes they are a bit out of date…

This repo seems quite cool

sometime is best just to search public repo’s for prior art.

which is sometimes quite useful.

Maybe a Ocaml nixxer can come in and give you are more definitive answer.

p.s. welcome to nix.

1 Like

First off, that website is super cool! Thanks for that. I tried the opam-nix and it seems like it might do what I want but going to take a little more fiddling around. If I don’t get any replies on this thread and I figure it out I’ll update with my findings.

1 Like

Update:

Figured it out using this

My final flake.nix ended up looking like this;

{
  description = "My OCaml project";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    ocaml-overlay.url = "github:nix-ocaml/nix-overlays";
    ocaml-overlay.inputs.nixpkgs.follows = "nixpkgs";
  };
  outputs = { self, nixpkgs, flake-utils, ocaml-overlay }: 
    flake-utils.lib.eachDefaultSystem (system: 
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [
            ocaml-overlay.overlays.default
          ];
        };
      in {
        devShell = pkgs.mkShell {
          buildInputs = [
            pkgs.ocaml
            pkgs.ocamlPackages.dune_2
            pkgs.ocamlPackages.merlin
            pkgs.ocamlPackages.utop
            pkgs.ocamlPackages.dream
          ];
          shellHook = ''
            eval $(opam env)
          '';
        };
      }     
    );
}

For other languages, well, every lang does its own thing. Doing things via nix will therefore always require some language-specific support, because there are no programming-wide standards for this.

For a lot of languages, such support exists. It’s most mature for traditional C/C++, because they’re so fundamental - much of distro packaging consists of wrangling basic shared libs to allow higher level builds to work at all.

Most other languages have some support somewhere, but flexibility, support and usage varies. Some live in nixpkgs, some are documented, many are neither.

This sucks, but it’s an artefact of the general heterogenity in the programming world.

All that said, GitHub - nix-community/dream2nix: Automate reproducible packaging for various language ecosystems [maintainer=@DavHau] tries to solve this problem in general.

I figured there would need to be different implementations on how to use/install packages per language. What’s challenging is trying to figure out how to do it myself if no solution exists or I’m unable to find one. I’ve been using NixOS for about a month and I’m starting to somewhat get a grasp on it but there is still a lot I don’t understand or is unclear.

Documentation seems kind of fragmented and even trying to sort through source code isn’t much clearer. It’s a struggle to just figure out what my expected inputs are and what my outputs needs to be. Nix syntax is easy enough but figuring out the “std lib” and conventions of the language is kind of a nightmare.

Yeah, unfortunately there isn’t much beyond that. Personally I find the source code clear enough when I can find what I’m looking for, but that’s not always a given.

The ecosystem is young and fragmented. Projects like dream2nix give me hope it’s all going somewhere though :slight_smile: