What is the recommended way to add dev commands to a flake?

I usually have a Makefile which contains various helper commands like make test etc.
How could I migrate these into a flake?
I’ve seen aliases in the devShell but they only work if you use nix develop instead of nix-direnv.

I use the apps, so that I can run some utility scripts with nix run .#<name>. e.g.: tlaternet-server/flake.nix at master - tlaternet-server - Gitea: Git with a cup of tea

So in this case I can spin up a test VM with nix run and update some inputs using nix run .#update-nextcloud-apps.

It works really well for me, though it’s definitely abusing the apps output. I don’t think there’s a good standard way yet. It’d be cool if there was at least an app type for this or such, so it’s not exposed to dependant flakes. An “update” type could also hook into nix flake update, for example, given a lot of my helpers revolve around that.

1 Like

Oh, while I’m at it, nix flake check should really obsolete make test. You can run linters with it too, see e.g. dotfiles/alejandra.nix at 800e95bd72164e23712d039c832223958e8e412f · TLATER/dotfiles · GitHub

Using it for unit/tests brings reproducible test environments, which are a huge boon. Shame it doesn’t have quite the granularity of Bazel for test caching, but it’s still quite decent, especially if you’re used to projects that anyway require re-running the full test suite.

1 Like

Thank I’m going to try the apps approach, I’ve seen it before when I did some research with sourcegraph but wasn’t sure if it’s okay.

I’ve played with checks a bit but it didn’t really work.
Most likely because I’ve still got some problems with the poetry2nix setup in the project.

I got the check part working. Turned out that it was a poetry problem not a poetry2nix problem.
Is mkDerivation the best way to create tests?
I’ve seen somewhere the use of mkCommand or so which looked a bit less verbose.

1 Like

Relevant: Adding commands to devenv · Issue #117 · cachix/devenv · GitHub

You’re probably looking for runCommand. Comes with a bonus of not providing a c compiler.

I think I used mkDerivation because I really wanted to use the checkPhase. Bit silly in retrospect, thanks for the review :wink: Or maybe it was how it handles src?

Ah yeah that could be it. I will try to rewrite the checks.