feat: factor out gomod2nix

This commit is contained in:
Adriano Caloiaro 2025-01-01 13:17:28 -07:00
parent 0f44c164ae
commit 7d25a128e8
No known key found for this signature in database
GPG key ID: C2BC56DE73CE3F75
7 changed files with 46 additions and 108 deletions

View file

@ -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 <nixpkgs> {}}: 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";
});
}

View file

@ -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",

View file

@ -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";
};
}
];
};

6
go.mod
View file

@ -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

4
go.sum
View file

@ -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=

View file

@ -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"

View file

@ -15,7 +15,7 @@ import (
"strings"
"text/template"
"github.com/hashicorp/go-envparse"
"github.com/acaloiaro/go-envparse"
)
const VERSION = "2.14.1"