Best practices for small private packages

I’m just getting started with nix and really enjoying it, but I have lots of questions. This one is about how people typically package small scripts or projects which are built purely for personal or private use.

In this case I have a bunch of scripts written in Haskell and built with Stack. I’ve managed to get the package to build using Stack’s nix integration, but now I want to install the resulting binaries somewhere I can get at them. Previously I would have just run stack install --copy-bins, which adds the binaries to ~/.local/bin and then I would make sure that ~/.local/bin is on my path.

I’m using Home Manger so I guess I could just modify the PATH of my shell to include ~/.local/bin, but that feels very much like it’s not the nix way. What do people generally suggest for these kinds of things?

I’ve been taking the approach of getting it all working first and then asking questions and linking to the relevant part of my config.

If you’re building things with stack I’d say it’s required to add the stack local bin path in your home manager config

If you started building these with nix instead, I guess you’d do something different but I’m not sure what. Calling nix-env -i would be kind of like stack, but imperative and not reproducible.

I guess you would put nix built Haskell projects in your home manager packages after importing them.

Yeah that latter part is what I’m curious if anyone else has been doing, or whether it’s just not worth the bother.

I wrote this blog article several years ago for some of my co-workers: Sander van der Burg's blog: Managing private Nix packages outside the Nixpkgs tree

Maybe you could get some inspiration from this.

I add these sorts of things to the home.packages config option in my home.nix. I have that checked into git, so I’m not worried about losing state or anything like that.

To be pedantic, the nix way would be to build the packages using nix and not stack. This would enable the package to be reasoned in terms of nix. If you do go this route, I would recommend looking into GitHub - nmattia/niv: Easy dependency management for Nix projects which is useful for tracking packages across many repos (include NUR, which could be used to share the builds).

Building a package using another tool requires you to follow it’s paradigms. In other words, using stack isn’t the nix way, so following stack’s conventions also isn’t going to be the nix way.

This is all great stuff, thanks folks.