From 7d25a128e8405548d8bf0a5c0cb21721fe99d05b Mon Sep 17 00:00:00 2001 From: Adriano Caloiaro Date: Wed, 1 Jan 2025 13:17:28 -0700 Subject: [PATCH] feat: factor out gomod2nix --- default.nix | 57 ++++++++++++++++++++++++++++++++------------------ flake.lock | 57 +------------------------------------------------- flake.nix | 21 +++---------------- go.mod | 6 ++---- go.sum | 4 ++-- gomod2nix.toml | 7 ------- main.go | 2 +- 7 files changed, 46 insertions(+), 108 deletions(-) delete mode 100644 gomod2nix.toml diff --git a/default.nix b/default.nix index 9d14357..76013f1 100644 --- a/default.nix +++ b/default.nix @@ -1,21 +1,38 @@ -{ 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 = "ess"; - version = "2.14.1"; - pwd = ./.; - src = ./.; - modules = ./gomod2nix.toml; +{pkgs ? import {}}: let + build = pkgs.buildGoModule { + pname = "ess"; + version = "2.14.1"; + src = ./.; + pwd = ./.; + vendorHash = "sha256-oIA1LTBvkA26ferZI+uOipLE2/wZr2XKjGfESuD/cPk="; + meta = { + description = "ess (env-sample-sync): automatically and safely synchronize env.sample files with .env"; + license = pkgs.lib.licenses.bsd2; + }; + }; +in { + darwin = build.overrideAttrs (old: + old + // { + GOOS = "darwin"; + GOARCH = "amd64"; + }); + linux32 = build.overrideAttrs (old: + old + // { + GOOS = "linux"; + GOARCH = "386"; + }); + x86_64-linux = build.overrideAttrs (old: + old + // { + GOOS = "linux"; + GOARCH = "amd64"; + }); + windows64 = build.overrideAttrs (old: + old + // { + GOOS = "windows"; + GOARCH = "amd64"; + }); } diff --git a/flake.lock b/flake.lock index b3e5b48..3bbfe78 100644 --- a/flake.lock +++ b/flake.lock @@ -369,24 +369,6 @@ "type": "github" } }, - "flake-utils_4": { - "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" - } - }, "gitignore": { "inputs": { "nixpkgs": [ @@ -409,27 +391,6 @@ "type": "github" } }, - "gomod2nix": { - "inputs": { - "flake-utils": "flake-utils_4", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1705314449, - "narHash": "sha256-yfQQ67dLejP0FLK76LKHbkzcQqNIrux6MFe32MMFGNQ=", - "owner": "nix-community", - "repo": "gomod2nix", - "rev": "30e3c3a9ec4ac8453282ca7f67fca9e1da12c3e6", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "gomod2nix", - "type": "github" - } - }, "libgit2": { "flake": false, "locked": { @@ -944,9 +905,8 @@ "root": { "inputs": { "devenv": "devenv", - "gomod2nix": "gomod2nix", "nixpkgs": "nixpkgs_5", - "systems": "systems_3" + "systems": "systems_2" } }, "systems": { @@ -978,21 +938,6 @@ "repo": "default", "type": "github" } - }, - "systems_3": { - "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", diff --git a/flake.nix b/flake.nix index 4c2d69f..8e8e839 100644 --- a/flake.nix +++ b/flake.nix @@ -3,11 +3,6 @@ nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; systems.url = "github:nix-systems/default"; devenv.url = "github:cachix/devenv"; - - gomod2nix = { - url = "github:nix-community/gomod2nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; outputs = { @@ -15,17 +10,15 @@ nixpkgs, devenv, systems, - gomod2nix, ... } @ inputs: let forEachSystem = nixpkgs.lib.genAttrs (import systems); in { packages = forEachSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; callPackage = nixpkgs.darwin.apple_sdk_11_0.callPackage or nixpkgs.legacyPackages.${system}.callPackage; in { - default = callPackage ./. { - inherit (gomod2nix.legacyPackages.${system}) buildGoApplication; - }; + default = (callPackage ./default.nix {}).${system}; }); devShells = forEachSystem (system: let @@ -38,22 +31,14 @@ packages = with pkgs; [ automake go_1_23 - gomod2nix.legacyPackages.${system}.gomod2nix gotools golangci-lint go-tools gopls + nix-update pre-commit svu ]; - - pre-commit.hooks.gomod2nix = { - enable = true; - pass_filenames = false; - name = "gomod2nix"; - description = "Run gomod2nix before commit"; - entry = "${gomod2nix.legacyPackages.${system}.gomod2nix}/bin/gomod2nix"; - }; } ]; }; diff --git a/go.mod b/go.mod index fb6fbba..05b749f 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,5 @@ module github.com/acaloiaro/ess -go 1.21 +go 1.23.1 -replace github.com/hashicorp/go-envparse v0.1.0 => github.com/acaloiaro/go-envparse v0.3.0 - -require github.com/hashicorp/go-envparse v0.1.0 +require github.com/acaloiaro/go-envparse v0.4.0 diff --git a/go.sum b/go.sum index 98f7b7a..e49d38e 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -github.com/acaloiaro/go-envparse v0.3.0 h1:TGHMQ6VK8ABhqalxaRTU2gj75dCDorQq6YTxGVI5X+4= -github.com/acaloiaro/go-envparse v0.3.0/go.mod h1:OHheN1GoygLlAkTlXLXvAdnXdZxy8JUweQ1rAXx1xnc= +github.com/acaloiaro/go-envparse v0.4.0 h1:QmiRB66+dYTbOxDIZ9qGvA3PdzOddBZFgpe1J/vFr/U= +github.com/acaloiaro/go-envparse v0.4.0/go.mod h1:0l65juEw9L8yTwKGdhoNBLtxeaSGGNr26DZXmWB7MsU= diff --git a/gomod2nix.toml b/gomod2nix.toml deleted file mode 100644 index bb19660..0000000 --- a/gomod2nix.toml +++ /dev/null @@ -1,7 +0,0 @@ -schema = 3 - -[mod] - [mod."github.com/hashicorp/go-envparse"] - version = "v0.3.0" - hash = "sha256-pbffSgC8BDtvkQAyI6ILkrMleI8m2JtedV0PL64Ok3I=" - replaced = "github.com/acaloiaro/go-envparse" diff --git a/main.go b/main.go index 5d0425c..6675878 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( "strings" "text/template" - "github.com/hashicorp/go-envparse" + "github.com/acaloiaro/go-envparse" ) const VERSION = "2.14.1"