Skip to content

Commit

Permalink
Add nix flake support
Browse files Browse the repository at this point in the history
  • Loading branch information
cyxou committed Apr 7, 2024
1 parent cf235ac commit aaed1a4
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ bin
build
.arg
.env
result
.direnv
21 changes: 21 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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 = "frp-port-keeper";
version = "0.2.0";
pwd = ./.;
src = ./.;
modules = ./gomod2nix.toml;
}
85 changes: 85 additions & 0 deletions flake.lock

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

29 changes: 29 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
description = "A basic gomod2nix flake";

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;
};
})
);
}
90 changes: 90 additions & 0 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
schema = 3

[mod]
[mod."github.com/bytedance/sonic"]
version = "v1.8.0"
hash = "sha256-Y3LcMK+G0hkOdTycEOTeDuar1umagsT5ux7aVQ+MlKw="
[mod."github.com/chenzhuoyu/base64x"]
version = "v0.0.0-20221115062448-fe3a3abad311"
hash = "sha256-xmONcYkIXgXomJYHR521Dr9F3XbbUM14bgf7KJ5FIFc="
[mod."github.com/gin-contrib/sse"]
version = "v0.1.0"
hash = "sha256-zYbMTao+1F+385Lvsba9roLmmt9eYqr57sUWo0LCVhw="
[mod."github.com/gin-gonic/gin"]
version = "v1.9.0"
hash = "sha256-vLkfoIeChmCKcLxRfp080tO0/2n6QBoCLxlFdUEEv+s="
[mod."github.com/go-playground/locales"]
version = "v0.14.1"
hash = "sha256-BMJGAexq96waZn60DJXZfByRHb8zA/JP/i6f/YrW9oQ="
[mod."github.com/go-playground/universal-translator"]
version = "v0.18.1"
hash = "sha256-2/B2qP51zfiY+k8G0w0D03KXUc7XpWj6wKY7NjNP/9E="
[mod."github.com/go-playground/validator/v10"]
version = "v10.11.2"
hash = "sha256-0mKf4ybFK/ZWoIUbmMXB3Fo9AoIqT5zAP30ce4TsBns="
[mod."github.com/goccy/go-json"]
version = "v0.10.0"
hash = "sha256-+m829gnYn/nS0FdWyzrgmAe8a3Q7G0sriZvgwQINHF8="
[mod."github.com/json-iterator/go"]
version = "v1.1.12"
hash = "sha256-To8A0h+lbfZ/6zM+2PpRpY3+L6725OPC66lffq6fUoM="
[mod."github.com/klauspost/cpuid/v2"]
version = "v2.0.9"
hash = "sha256-0rHlHzEVaDdkVbRJDhnAJjfJUmAHOYjXN5u7VoCi5uk="
[mod."github.com/leodido/go-urn"]
version = "v1.2.1"
hash = "sha256-02UfyUwMtTGMUYJOEmiJYOc3LXumr+f7pCT3J7h7iFg="
[mod."github.com/mattn/go-isatty"]
version = "v0.0.17"
hash = "sha256-c1u9eiMF9wLXgGvPTB5DH6S8uuCPqWZJTa6tCGuB3Ek="
[mod."github.com/modern-go/concurrent"]
version = "v0.0.0-20180228061459-e0a39a4cb421"
hash = "sha256-+bdeHUArnpkk4eMQIwXm9K249NkpwAjoTrXrGn/4VUE="
[mod."github.com/modern-go/reflect2"]
version = "v1.0.2"
hash = "sha256-+W9EIW7okXIXjWEgOaMh58eLvBZ7OshW2EhaIpNLSBU="
[mod."github.com/pelletier/go-toml/v2"]
version = "v2.0.6"
hash = "sha256-BxAeApnn5H+OLlH3TXGvIbtC6LmbRnjwbcfT1qMZ4PE="
[mod."github.com/philippgille/gokv"]
version = "v0.6.0"
hash = "sha256-YuxnxF2GXWDqCui2BVAOl279j+U5MvTsHhIGd0Pi+Ds="
[mod."github.com/philippgille/gokv/encoding"]
version = "v0.0.0-20191011213304-eb77f15b9c61"
hash = "sha256-W7GYx3SZlTATh/+XnPuZzQ5jVlObsSEWIIgi4xoIaa0="
[mod."github.com/philippgille/gokv/file"]
version = "v0.6.0"
hash = "sha256-ZwVi4pXX5P0iT6pNUnwIUx3NVZIIW3lGmw+JvR35PaE="
[mod."github.com/philippgille/gokv/util"]
version = "v0.0.0-20191011213304-eb77f15b9c61"
hash = "sha256-eTdMFNM5n4Ai+FzYZXGX24D9WjXHz8sxeEPgpwXrdqs="
[mod."github.com/twitchyliquid64/golang-asm"]
version = "v0.15.1"
hash = "sha256-HLk6oUe7EoITrNvP0y8D6BtIgIcmDZYtb/xl/dufIoY="
[mod."github.com/ugorji/go/codec"]
version = "v1.2.9"
hash = "sha256-LUyCclmjVNbf6iiztNOrEsKzrwmG3mpmM1ykzh/BQ/s="
[mod."golang.org/x/arch"]
version = "v0.0.0-20210923205945-b76863e36670"
hash = "sha256-GRRcSkvNi5Cf9q3UkNVux5yy8n5mPQIFofv1fSSYqQ0="
[mod."golang.org/x/crypto"]
version = "v0.5.0"
hash = "sha256-5L4rCFZ0IMT9aQIeMbfOFbhwi03nXE/EeWuXup+Aeoc="
[mod."golang.org/x/net"]
version = "v0.7.0"
hash = "sha256-LgZYZRwtMqm+soNh+esxDSeRuIDxRGb9OEfYaFJHCDI="
[mod."golang.org/x/sys"]
version = "v0.5.0"
hash = "sha256-0LTr3KeJ1OMQAwYUQo1513dXJtQAJn5Dq8sFkc8ps1U="
[mod."golang.org/x/text"]
version = "v0.7.0"
hash = "sha256-ydgUqX+t5Qke16C6d3FP/06U/N1n+rUKpLRFj4KXjwk="
[mod."google.golang.org/protobuf"]
version = "v1.28.1"
hash = "sha256-sTJYgvlv5is7vHNxcuigF2lNASp0QonhUgnrguhfHSU="
[mod."gopkg.in/ini.v1"]
version = "v1.67.0"
hash = "sha256-V10ahGNGT+NLRdKUyRg1dos5RxLBXBk1xutcnquc/+4="
[mod."gopkg.in/yaml.v3"]
version = "v3.0.1"
hash = "sha256-FqL9TKYJ0XkNwJFnq9j0VvJ5ZUU1RvH/52h/f5bkYAU="
24 changes: 24 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -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
];
}

0 comments on commit aaed1a4

Please sign in to comment.