Skip to content

Commit

Permalink
feat: factor out gomod2nix
Browse files Browse the repository at this point in the history
  • Loading branch information
acaloiaro committed Jan 1, 2025
1 parent 0f44c16 commit 7d25a12
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 108 deletions.
57 changes: 37 additions & 20 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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";
});
}
57 changes: 1 addition & 56 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 3 additions & 18 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@
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 = {
self,
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
Expand All @@ -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";
};
}
];
};
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
7 changes: 0 additions & 7 deletions gomod2nix.toml

This file was deleted.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"strings"
"text/template"

"github.com/hashicorp/go-envparse"
"github.com/acaloiaro/go-envparse"
)

const VERSION = "2.14.1"
Expand Down

0 comments on commit 7d25a12

Please sign in to comment.