Hi,
I’d like to build a nix package for a go project.
I can find some examples about the contents of what should go into my file, but I have no idea what filename to use, what commands to run or how to include the package I end up building in my configuration.nix
file. Could I get a couple of pointers to get me off the ground?
I’d like to create a nix package for this go-based executable:
which has a go.mod
file in the root. go build
works.
So I’m trying to follow
https://nixos.org/manual/nixpkgs/stable/#sec-language-go
(keep in mind, I’ve never built a package before let alone tried to create my own).
And it has this example:
{
pet = buildGoModule rec {
pname = "pet";
version = "0.3.4";
src = fetchFromGitHub {
owner = "knqyf263";
repo = "pet";
rev = "v${version}";
hash = "sha256-Gjw1dRrgM8D3G7v6WIM2+50r4HmTXvx0Xxme2fH9TlQ=";
};
vendorHash = "sha256-ciBIR+a1oaYH+H1PcC8cD8ncfJczk1IiJ8iYNM+R6aA=";
meta = {
description = "Simple command-line snippet manager, written in Go";
homepage = "https://github.com/knqyf263/pet";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ kalbasit ];
};
};
}
Questions
I think I could figure out how to change that example to match github.com/m-manu/rsync-sidekick if only I had an idea what to do with that text to get the pet
example to work.
- Is the above example complete? If not, what is missing?
- What file name should I put the file contents in?
- What command should I run to test if it works?
- Assuming I can get it to build, and put that file on github e.g. as my own package, how do I include that as a package in my
configuration.nix
? - Is this flake or old-school?
Also, under Obtaining and overriding vendorHash
for buildGoModule
, it suggests:
The following command gets the value of
vendorHash
for packagepet
:
cd path/to/nixpkgs
nix-prefetch -E "{ sha256 }: ((import ./. { }).my-package.overrideAttrs { vendorHash = sha256; }).goModules"
Uhm… What are path/to/nixpkgs
and my-package
? And do I even need this, if I use vendorHash = lib.fakeHash
as suggested?
What I tried
Go - NixOS Wiki
I also looked at Go - NixOS Wiki which is very similar to the above and simply assumes even more that I already know what to do with buildGoModule
.
Search for buildGoModule
Having no idea what to do with this text blob, I found
https://github.com/NixOS/nixpkgs’s pkgs/by-name/ff/ffuf/package.nix
Which also has this pre-amble in addition to a buildGoModule
block:
{
lib,
buildGoModule,
fetchFromGitHub,
fetchpatch,
}:
So I downloaded ff/ffuf/package.nix
as a local package.nix
file, but then what? Neither nix-build package.nix
nor nix build package.nix
work.
Hacking Your First Package — nix-tutorial documentation
I tried following:
Hacking Your First Package — nix-tutorial documentation
and it has a chord_example.nix
file. If I copy that into a chord_example.nix
file and run nix-build chord_example.nix
it does actually work. But nix-build package.nix
from pkgs/by-name/ff/ffuf/package.nix
above didn’t. Huh?