I still trying to wrap my head around how to make personal (open source) projects available to nixos (via flakes). I will focus on go
for the moment (but rust
, zig
, java
and node
would also be interesting).
I have a project that uses goreleaser
to build binaries and deb
and apk
for various architectures. It makes the binaries available to homebrew
via my personal tap repo.
Now I am aware that things are very different in nix land. But I am still struggling to make the transition and supporting nix.
Since nix (usually) builds from source it would be so nice if I could just point my flake to my github repo, and (after adding some nix files) I could just build (install when using cachix.org) it via nix.
But is it that easy? Here is what I looked at:
1) goreleaser
I found that goreleaser now has some support for nix but seems to require for me to have my own NUR. Which seems similar to having to maintain the homebrew tap. But IIUC the goreleaser integration is not source based. So that’s not really “the nix way” I guess?
2) nixpkgs
As long as the projects are tiny including them into the mighty nixpkgs
is probably not the way to go. Not sure.
But just to see how things work I thought to look into the nixpkgs
repo. I picked to look at envsubst
as an example. But frankly speaking I don’t see how it works yet. There is nothing about nix in the envsubst repo and in nixpkgs it just has (summary, see the link for full)
buildGoModule rec {
pname = "envsubst";
version = "1.4.2";
src = fetchFromGitHub {
rev = "v${version}";
sha256 = "sha256-gfzqf/CXSwGXBK5VHJnepFZ1wB3WElpEp6ra9JI4WtY=";
};
vendorHash = "sha256-L0MbABgUniuI5NXc4ffBUsQRI716W/FiH38bGthpXzI=";
…and I am not sure how I could/should maintain these hashes myself (if this was my project).
Manually?
I found these docs but that didn’t really help. The docs in the wiki are also unclear on that.
After reading a particular part in the manual, a few links later I found the contributor guide to nixpkgs and IIUC I would need to manually run something like this?
Find the value to put as hash by running
nix-prefetch-github --rev 1f795f9f44607cc5bec70d1300150bfefcef2aae NixOS nix
And I am still not sure I follow.
And then…
3) xs as an example
After some more research I found this project.
- It seems to be it’s own flake referencing the local package
- It uses
buildGoModule
- It has code to update the hashes for
xc.nix
(via script from axc.nix.tmpl
) - It has
goreleaser
as a separate build for the binary assets that just updates the flake on releases
Is this a good example to follow? Are there better?
Are there docs I have missed?
Thanks for the help.
cheers,
Torsten