Now with Nix instead of TOML. Rewrite in progress...
Convert applications using Go modules -> Nix
From the Go project directory execute:
$ gomod2nix
This will create gomod2nix.nix
which contains something like:
# Generated by gomod2nix
{ pkgs, lib, ... }:
{
schemaVersion = 4;
mod."github.com/go-openapi/validate" = { version = "v0.22.1"; hash = "sha256-xU2pyIwBlXZnb25gn9lnyE+IQLNXo1RCAB9jINjKVMo="; replacedPath = ""; };
}
A sample default.nix
which invokes the buildGoApplication
(which can be created using the generate
subcommand) is as follows:
{ pkgs ? (
let
inherit (builtins) fetchTree fromJSON readFile;
inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix;
in
import (fetchTree nixpkgs.locked) {
overlays = [
(import "${fetchTree gomod2nix.locked}/overlay.nix")
];
}
)
}:
pkgs.buildGoApplication {
pname = "argo-trash";
version = builtins.replaceStrings [ "\n" ] [ "" ] (builtins.readFile ./VERSION);
pwd = ./.;
src = ./.;
modules = ./gomod2nix.nix;
}
For more in-depth usage check the Getting Started and the Nix API reference docs.
The announcement blog post contains comparisons with other Go build systems for Nix and additional notes on the design choices made.
This project is licensed under the MIT License. See the LICENSE file for details.
The developmentent of Trustix (which Gomod2nix is a part of) has been sponsored by Tweag I/O and funded by the NLNet foundation and the European Commission’s Next Generation Internet programme through the NGI Zero PET (privacy and trust enhancing technologies) fund.