Skip to content

Convert applications using Go modules to Nix expressions [maintainer=@adisbladis]

License

Notifications You must be signed in to change notification settings

niklashhh/gomod2nix

 
 

Repository files navigation

Gomod2nix

Now with Nix instead of TOML. Rewrite in progress...

Convert applications using Go modules -> Nix

Usage

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.

Motivation

The announcement blog post contains comparisons with other Go build systems for Nix and additional notes on the design choices made.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About the project

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.

NGI0 logo NLNet banner Tweag logo

About

Convert applications using Go modules to Nix expressions [maintainer=@adisbladis]

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Nix 54.5%
  • Go 44.5%
  • Other 1.0%