From 9e44b7963ff3a7b1f045099fc51842dac775e4b1 Mon Sep 17 00:00:00 2001 From: Benoit Donneaux Date: Thu, 13 Jun 2024 13:14:58 +0200 Subject: [PATCH 1/4] Flake it - does not build, but devShell works Likely facing a reproduciblity issue with mockgen to create code at build time! Signed-off-by: Benoit Donneaux --- default.nix | 21 ++++++++++ flake.lock | 85 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 29 ++++++++++++++ gomod2nix.toml | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 24 ++++++++++++ 5 files changed, 261 insertions(+) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 gomod2nix.toml create mode 100644 shell.nix diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..2a72fad --- /dev/null +++ b/default.nix @@ -0,0 +1,21 @@ +{ 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") + ]; + } + ) +, buildGoApplication ? pkgs.buildGoApplication +}: + +buildGoApplication { + pname = "trac2gitea"; + version = "0.1"; + pwd = ./.; + src = ./.; + modules = ./gomod2nix.toml; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..64dfbf2 --- /dev/null +++ b/flake.lock @@ -0,0 +1,85 @@ +{ + "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" + } + }, + "gomod2nix": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1717050755, + "narHash": "sha256-C9IEHABulv2zEDFA+Bf0E1nmfN4y6MIUe5eM2RCrDC0=", + "owner": "nix-community", + "repo": "gomod2nix", + "rev": "31b6d2e40b36456e792cd6cf50d5a8ddd2fa59a1", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "gomod2nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1717974879, + "narHash": "sha256-GTO3C88+5DX171F/gVS3Qga/hOs/eRMxPFpiHq2t+D8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c7b821ba2e1e635ba5a76d299af62821cbcb09f3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "gomod2nix": "gomod2nix", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d5d3df7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,29 @@ +{ + description = "A basic gomod2nix flake for trac2gitea"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.gomod2nix.url = "github:nix-community/gomod2nix"; + inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs"; + inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils"; + + outputs = { self, nixpkgs, flake-utils, gomod2nix }: + (flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + # The current default sdk for macOS fails to compile go projects, so we use a newer one for now. + # This has no effect on other platforms. + callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage; + in + { + packages.default = callPackage ./. { + inherit (gomod2nix.legacyPackages.${system}) buildGoApplication; + }; + devShells.default = callPackage ./shell.nix { + inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix; + }; + }) + ); +} diff --git a/gomod2nix.toml b/gomod2nix.toml new file mode 100644 index 0000000..dd87811 --- /dev/null +++ b/gomod2nix.toml @@ -0,0 +1,102 @@ +schema = 3 + +[mod] + [mod."github.com/emirpasic/gods"] + version = "v1.12.0" + hash = "sha256-IavlXdTPaXr/n0ZjfPm3SmpndU70l5RnrINvqQ7GuEQ=" + [mod."github.com/go-ini/ini"] + version = "v1.67.0" + hash = "sha256-V10ahGNGT+NLRdKUyRg1dos5RxLBXBk1xutcnquc/+4=" + [mod."github.com/go-sql-driver/mysql"] + version = "v1.7.0" + hash = "sha256-xcCINvN+wEiLLmp9ltfLbDEs+/TidoBCQLODw3lMyzE=" + [mod."github.com/golang-sql/civil"] + version = "v0.0.0-20220223132316-b832511892a9" + hash = "sha256-IEz9BkkHyFfs9R4aMxH/c/tD510qSyFEaKrpO4arWpQ=" + [mod."github.com/golang-sql/sqlexp"] + version = "v0.1.0" + hash = "sha256-FhKWdt7vwzTbIsx2u+AzrKO1VFxTw/lbgD9/V5G76jw=" + [mod."github.com/jackc/pgpassfile"] + version = "v1.0.0" + hash = "sha256-H0nFbC34/3pZUFnuiQk9W7yvAMh6qJDrqvHp+akBPLM=" + [mod."github.com/jackc/pgservicefile"] + version = "v0.0.0-20221227161230-091c0ba34f0a" + hash = "sha256-rBtUw15WPPDp2eulHXH5e2zCIed1OPFYwlCpgDOnGRM=" + [mod."github.com/jackc/pgx/v5"] + version = "v5.3.1" + hash = "sha256-0v6gXZIirv80mlnUx3ycxB2/TLvv3rUnm98Ke1ZjYDQ=" + [mod."github.com/jbenet/go-context"] + version = "v0.0.0-20150711004518-d14ea06fba99" + hash = "sha256-VANNCWNNpARH/ILQV9sCQsBWgyL2iFT+4AHZREpxIWE=" + [mod."github.com/jinzhu/inflection"] + version = "v1.0.0" + hash = "sha256-3h3pHib5MaCXKyKLIMyQnSptDJ16kPjCOQPoEBoQsZg=" + [mod."github.com/jinzhu/now"] + version = "v1.1.5" + hash = "sha256-NNLqoFx9FczBBDpD0O0aSHnC/YDZ9E/xQ340o7u63IM=" + [mod."github.com/kevinburke/ssh_config"] + version = "v0.0.0-20190725054713-01f96b0aa0cd" + hash = "sha256-X5L36JG7T2deBkHBABUYf2rQKle8ve35bH/FQeWUrq8=" + [mod."github.com/mattn/go-sqlite3"] + version = "v1.14.22" + hash = "sha256-CWF2Hjg43658NhaePWbGzS19gHJXjuTroG5c0W3hgYQ=" + [mod."github.com/microsoft/go-mssqldb"] + version = "v0.21.0" + hash = "sha256-cAUiV2kw/0M9jldWtqdDC+gboAwGNUS3dNHSDM5EKgo=" + [mod."github.com/mitchellh/go-homedir"] + version = "v1.1.0" + hash = "sha256-oduBKXHAQG8X6aqLEpqZHs5DOKe84u6WkBwi4W6cv3k=" + [mod."github.com/pkg/errors"] + version = "v0.8.1" + hash = "sha256-oe3iddfoLRwpC3ki5fifHf2ZFprtg99iNak50shiuDw=" + [mod."github.com/sergi/go-diff"] + version = "v1.0.0" + hash = "sha256-I8rbJFKm44u/wS/gz+2yX9882xXcBdb9mKEKq5OoJRU=" + [mod."github.com/spf13/pflag"] + version = "v1.0.5" + hash = "sha256-w9LLYzxxP74WHT4ouBspH/iQZXjuAh2WQCHsuvyEjAw=" + [mod."github.com/src-d/gcfg"] + version = "v1.4.0" + hash = "sha256-mXSyOVMB6hSuTddVkBV4+skshppmSu4Klzz7OnVJkhA=" + [mod."github.com/xanzy/ssh-agent"] + version = "v0.2.1" + hash = "sha256-WwVQw4YDBvsLk8vTsqSJXVSRUhMm69erv1ubVralErI=" + [mod."go.uber.org/mock"] + version = "v0.4.0" + hash = "sha256-mJN2cPmAMTZQzOnTpJ8zi9QH2m3OAKI4IpnQW9QYS8s=" + [mod."golang.org/x/crypto"] + version = "v0.8.0" + hash = "sha256-gZ225jF4mxRLlba6OzdTvrsP6kLYf/xOjWMFavCF6tY=" + [mod."golang.org/x/net"] + version = "v0.9.0" + hash = "sha256-EG5GRDq282twyce8uugsDTjMz1pNn6zPcyVTZmSiJ14=" + [mod."golang.org/x/sys"] + version = "v0.7.0" + hash = "sha256-GotRHJaas/q3L+tFam0q3oQ1rc8GDStt7wnz9h8MTEU=" + [mod."golang.org/x/text"] + version = "v0.9.0" + hash = "sha256-tkhDeMsSQZr3jo7vmKehWs3DvWetwXR0IB+DCLbQ4nk=" + [mod."gopkg.in/src-d/go-billy.v4"] + version = "v4.3.2" + hash = "sha256-W1n8AsBrIhWBe3Jz5ZR1DTwLrE9q0vBR/Uqk4/yYppg=" + [mod."gopkg.in/src-d/go-git.v4"] + version = "v4.13.1" + hash = "sha256-uj7etQusc05Tezv5lW7rU+22I9WVQdn6h4PhC6dZzgE=" + [mod."gopkg.in/warnings.v0"] + version = "v0.1.2" + hash = "sha256-ATVL9yEmgYbkJ1DkltDGRn/auGAjqGOfjQyBYyUo8s8=" + [mod."gorm.io/driver/mysql"] + version = "v1.5.0" + hash = "sha256-/p12Sj0arPFJp0Ka8aY1OTacCPCW9/NGTWaGPyrKiWM=" + [mod."gorm.io/driver/postgres"] + version = "v1.5.0" + hash = "sha256-t1stGhKLrMwbOxLsh1LkSM9Wu9QMOOnSwkR8l851o/M=" + [mod."gorm.io/driver/sqlite"] + version = "v1.5.0" + hash = "sha256-iHSonxWbuLBba8AFat0mKBXmUBsDLh/V3jqYM8JX3IE=" + [mod."gorm.io/driver/sqlserver"] + version = "v1.4.3" + hash = "sha256-RUJnLstMhz31hxBv4YD3hC4fHlskcQ89IsvoRv78FxU=" + [mod."gorm.io/gorm"] + version = "v1.25.0" + hash = "sha256-8ORQqnnDhdy9/ubT6dPNVehkkmy8+ff7ynB24myC2Wk=" diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..d4f21a8 --- /dev/null +++ b/shell.nix @@ -0,0 +1,24 @@ +{ 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") + ]; + } + ) +, mkGoEnv ? pkgs.mkGoEnv +, gomod2nix ? pkgs.gomod2nix +}: + +let + goEnv = mkGoEnv { pwd = ./.; }; +in +pkgs.mkShell { + packages = [ + goEnv + gomod2nix + ]; +} From 63e2c4541cc0476cbda05c5c1acf780635412357 Mon Sep 17 00:00:00 2001 From: Benoit Donneaux Date: Tue, 18 Jun 2024 22:06:33 +0200 Subject: [PATCH 2/4] Setup Githup action to CI this Nix flake Signed-off-by: Benoit Donneaux --- .github/workflows/go.yml | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index a618adf..f4aa5b1 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,13 +7,12 @@ on: pull_request: jobs: - main: - name: Main + docker: + name: Docker runs-on: ubuntu-22.04 permissions: pull-requests: write contents: read - steps: - name: Checkout id: checkout @@ -67,3 +66,29 @@ jobs: ./trac2gitea --help 2>&1 | grep -q '^Usage' \ && echo 'PASS' \ || { echo 'FAIL'; exit 1; } + nix: + name: Nix + runs-on: ubuntu-22.04 + permissions: + pull-requests: write + contents: read + strategy: + matrix: + nix_path: + - nixpkgs=channel:nixos-stable + - nixpkgs=channel:nixos-unstable + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + + - name: Install Nix + id: install_nix + uses: cachix/install-nix-action@v27 + with: + nix_path: ${{ matrix.nix_path }} + + - name: Check + id: check + run: | + nix flake check From 23ae7cf9bc441d214824ca85c16a4f438d4040af Mon Sep 17 00:00:00 2001 From: Benoit Donneaux Date: Tue, 18 Jun 2024 22:12:46 +0200 Subject: [PATCH 3/4] Also build the nix package - fails on the missing mocking coding Signed-off-by: Benoit Donneaux --- .github/workflows/go.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f4aa5b1..e67d551 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -92,3 +92,8 @@ jobs: id: check run: | nix flake check + + - name: Build + id: build + run: | + nix-build From 9838b614535b92ce7568adb4cd7881f896ceff10 Mon Sep 17 00:00:00 2001 From: Benoit Donneaux Date: Tue, 18 Jun 2024 22:17:45 +0200 Subject: [PATCH 4/4] Shorter matrix argument Signed-off-by: Benoit Donneaux --- .github/workflows/go.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e67d551..ed5b3cf 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -66,6 +66,7 @@ jobs: ./trac2gitea --help 2>&1 | grep -q '^Usage' \ && echo 'PASS' \ || { echo 'FAIL'; exit 1; } + nix: name: Nix runs-on: ubuntu-22.04 @@ -74,9 +75,9 @@ jobs: contents: read strategy: matrix: - nix_path: - - nixpkgs=channel:nixos-stable - - nixpkgs=channel:nixos-unstable + nix_channel: + - nixos-stable + - nixos-unstable steps: - name: Checkout id: checkout @@ -86,7 +87,7 @@ jobs: id: install_nix uses: cachix/install-nix-action@v27 with: - nix_path: ${{ matrix.nix_path }} + nix_path: nixpkgs=channel:${{ matrix.nix_channel }} - name: Check id: check