From e3067b88c55055fcffa13e77f5dc21dccbdf8ea9 Mon Sep 17 00:00:00 2001 From: Noon van der Silk Date: Tue, 30 Jul 2024 10:48:40 +0100 Subject: [PATCH] Add flake to build via Nix and gomod2nix --- .envrc | 1 + .gitignore | 3 + flake.lock | 151 +++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 59 +++++++++++++++++++ gomod2nix.toml | 102 +++++++++++++++++++++++++++++++++ 5 files changed, 316 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 gomod2nix.toml diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..3550a30f --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 5a21a995..730187f8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ **/debug.test vendor + +result +.direnv/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..0e206b85 --- /dev/null +++ b/flake.lock @@ -0,0 +1,151 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gomod2nix": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1721902146, + "narHash": "sha256-zIycVdlCezEPqbbznII1VSC+gR4W2woG8EEEwz7Zjy0=", + "owner": "nix-community", + "repo": "gomod2nix", + "rev": "7b8ef0d5fdc09b3a7acb27f1e6c168888947f364", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "gomod2nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1717179513, + "narHash": "sha256-vboIEwIQojofItm2xGCdZCzW96U85l9nDW3ifMuAIdM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63dacb46bf939521bdc93981b4cbb7ecb58427a0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1720957393, + "narHash": "sha256-oedh2RwpjEa+TNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "693bc46d169f5af9c992095736e82c3488bf7dbb", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "gomod2nix": "gomod2nix", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1722330636, + "narHash": "sha256-uru7JzOa33YlSRwf9sfXpJG+UAV+bnBEYMjrzKrQZFw=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "768acdb06968e53aa1ee8de207fd955335c754b7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..0f1b77bc --- /dev/null +++ b/flake.nix @@ -0,0 +1,59 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/24.05"; + gomod2nix = { + url = "github:nix-community/gomod2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-utils.url = "github:numtide/flake-utils"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + }; + + outputs = + { self + , nixpkgs + , gomod2nix + , flake-utils + , treefmt-nix + , ... + }: + flake-utils.lib.eachDefaultSystem (system: + let + pumba = with pkgs; gomod2nix.legacyPackages.${system}.buildGoApplication { + name = "pumba"; + src = ./.; + pwd = ./.; # Must be added due to bug https://github.com/nix-community/gomod2nix/issues/120 + + # Rename the binary as it's called 'cmd' presently. + fixupPhase = '' + mv $out/bin/cmd $out/bin/pumba + ''; + }; + + goEnv = gomod2nix.legacyPackages.${system}.mkGoEnv { pwd = ./.; }; + + pkgs = import nixpkgs { inherit system; }; + in + { + # Development shells for hacking + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + goEnv + gomod2nix.packages.${system}.default # gomod2nix CLI + ]; + }; + + packages = { + default = pumba; + }; + + formatter = + let + fmt = treefmt-nix.lib.evalModule pkgs (_: { + projectRootFile = "flake.nix"; + programs.nixpkgs-fmt.enable = true; + }); + in + fmt.config.build.wrapper; + }); +} diff --git a/gomod2nix.toml b/gomod2nix.toml new file mode 100644 index 00000000..9c2f316b --- /dev/null +++ b/gomod2nix.toml @@ -0,0 +1,102 @@ +schema = 3 + +[mod] + [mod."github.com/Microsoft/go-winio"] + version = "v0.6.1" + hash = "sha256-BL0BVaHtmPKQts/711W59AbHXjGKqFS4ZTal0RYnR9I=" + [mod."github.com/cpuguy83/go-md2man/v2"] + version = "v2.0.2" + hash = "sha256-OvWCtDsVrYzM84SMQwOXPLBxnWnMC1hDm+KiI6zm3uk=" + [mod."github.com/davecgh/go-spew"] + version = "v1.1.1" + hash = "sha256-nhzSUrE1fCkN0+RL04N4h8jWmRFPPPWbCuDc7Ss0akI=" + [mod."github.com/docker/distribution"] + version = "v2.8.2+incompatible" + hash = "sha256-ocVWMRt5ErWdVsj3rsNa/QhizG5b/PCu8LoOlUi24/c=" + [mod."github.com/docker/docker"] + version = "v23.0.3+incompatible" + hash = "sha256-JvrWYi6rfQW566wXke4HKUwlCdUTxR+kyTM2tz8pCO8=" + [mod."github.com/docker/go-connections"] + version = "v0.4.0" + hash = "sha256-GHNIjOuuNp5lFQ308+nDNwQPGESCVV7bCUxSW5ZxZlc=" + [mod."github.com/docker/go-units"] + version = "v0.5.0" + hash = "sha256-iK/V/jJc+borzqMeqLY+38Qcts2KhywpsTk95++hImE=" + [mod."github.com/gogo/protobuf"] + version = "v1.3.2" + hash = "sha256-pogILFrrk+cAtb0ulqn9+gRZJ7sGnnLLdtqITvxvG6c=" + [mod."github.com/google/go-cmp"] + version = "v0.5.9" + hash = "sha256-lQc4O00R3QSMGs9LP8Sy7A9kj0cqV5rrUdpnGeipIyg=" + [mod."github.com/johntdyer/slack-go"] + version = "v0.0.0-20180213144715-95fac1160b22" + hash = "sha256-jd/Od/vnon2CEkxQ2Mf+w32fSSBIkTX0vgpytHJJYYw=" + [mod."github.com/johntdyer/slackrus"] + version = "v0.0.0-20210521205746-42486fb4c48c" + hash = "sha256-80ztGeOVqiuja9MoHizUPqBoGRV378PFjZpx50/gbno=" + [mod."github.com/kr/text"] + version = "v0.2.0" + hash = "sha256-fadcWxZOORv44oak3jTxm6YcITcFxdGt4bpn869HxUE=" + [mod."github.com/moby/term"] + version = "v0.0.0-20210619224110-3f7ff695adc6" + hash = "sha256-ji80C4u0OJb59wIuPF4LiWf/yaGqZVfFsy+irp25Sc0=" + [mod."github.com/morikuni/aec"] + version = "v1.0.0" + hash = "sha256-5zYgLeGr3K+uhGKlN3xv0PO67V+2Zw+cezjzNCmAWOE=" + [mod."github.com/niemeyer/pretty"] + version = "v0.0.0-20200227124842-a10e7caefd8e" + hash = "sha256-m2D7hWZrDst0rb91lmjSuNrzBQbmQ0Oe2UOp3wn8qso=" + [mod."github.com/opencontainers/go-digest"] + version = "v1.0.0" + hash = "sha256-cfVDjHyWItmUGZ2dzQhCHgmOmou8v7N+itDkLZVkqkQ=" + [mod."github.com/opencontainers/image-spec"] + version = "v1.1.0-rc4" + hash = "sha256-rsc3wL80rmQhf4tiHQ0RJAcTsbdzqqS3TIlK9BWzOKQ=" + [mod."github.com/pkg/errors"] + version = "v0.9.1" + hash = "sha256-mNfQtcrQmu3sNg/7IwiieKWOgFQOVVe2yXgKBpe/wZw=" + [mod."github.com/pmezard/go-difflib"] + version = "v1.0.0" + hash = "sha256-/FtmHnaGjdvEIKAJtrUfEhV7EVo5A/eYrtdnUkuxLDA=" + [mod."github.com/russross/blackfriday/v2"] + version = "v2.1.0" + hash = "sha256-R+84l1si8az5yDqd5CYcFrTyNZ1eSYlpXKq6nFt4OTQ=" + [mod."github.com/sirupsen/logrus"] + version = "v1.9.3" + hash = "sha256-EnxsWdEUPYid+aZ9H4/iMTs1XMvCLbXZRDyvj89Ebms=" + [mod."github.com/stretchr/objx"] + version = "v0.5.0" + hash = "sha256-nY4mvP0f0Ry1IKMKQAYNuioA5h4red4mmQqeGZw6EF0=" + [mod."github.com/stretchr/testify"] + version = "v1.8.4" + hash = "sha256-MoOmRzbz9QgiJ+OOBo5h5/LbilhJfRUryvzHJmXAWjo=" + [mod."github.com/urfave/cli"] + version = "v1.22.12" + hash = "sha256-FTdBlhQvyDhgrDcSJDxgSLS/cBSP8B1BC/AxGA9Lyss=" + [mod."golang.org/x/mod"] + version = "v0.12.0" + hash = "sha256-M/oXnzm7odpJdQzEnG6W0pNYtl0uhOM/l7qgfGVpU2M=" + [mod."golang.org/x/net"] + version = "v0.15.0" + hash = "sha256-k0hgSwNmZz9nN9cqqACNHdnejV50AAwzxnoyTs9liXw=" + [mod."golang.org/x/sync"] + version = "v0.3.0" + hash = "sha256-bCJKLvwExhYacH2ZrWlZ38lr1d6oNenNt2m1QqDCs0o=" + [mod."golang.org/x/sys"] + version = "v0.12.0" + hash = "sha256-Ht/PhBJGWNBg4ksmdUu4+7hJjFypSwoUN/8DJricd+0=" + [mod."golang.org/x/time"] + version = "v0.1.0" + hash = "sha256-9tbFLEh3MbhbDxU3vw763vf8ppsZicpfAbo5V4PslLE=" + [mod."golang.org/x/tools"] + version = "v0.13.0" + hash = "sha256-OCgLOwia8fNHxfdogXVApf0/qK6jE2ukegOx7lkOzfo=" + [mod."gopkg.in/check.v1"] + version = "v1.0.0-20200227125254-8fa46927fb4f" + hash = "sha256-nGV66SlDrpDfhkzlr9h52JybsCioW3ix5bKmbkEfoDs=" + [mod."gopkg.in/yaml.v3"] + version = "v3.0.1" + hash = "sha256-FqL9TKYJ0XkNwJFnq9j0VvJ5ZUU1RvH/52h/f5bkYAU=" + [mod."gotest.tools/v3"] + version = "v3.0.2" + hash = "sha256-R9KZ5NexCr9mexcjZhPlhRy+cx2d19vGD7hQ9xfFy/4="