update nix project config

This commit is contained in:
guochao 2024-05-26 12:37:30 +08:00
parent 6a81d2f348
commit b2a8c41ea0
5 changed files with 99 additions and 44 deletions

2
.envrc
View File

@ -1 +1 @@
use flake use nix --expr '(import <nixpkgs> {}).callPackage ./shell.nix {}'

25
default.nix Normal file
View File

@ -0,0 +1,25 @@
{ buildGoModule, lib, callPackage, project-config? callPackage ./project-config.nix {}, ... }: buildGoModule {
pname = "demo-signaling-server";
version = "0.0.1";
nativeBuildInputs = project-config.buildTools;
buildInputs = project-config.libraries;
src = ./.;
# vendorHash = "";
vendorHash = "sha256-fxjQPK/6IWxnezix8aMMxw3+MZj8XxqnYD5Z9WUsdM4=";
preBuild = ''
go generate -v ./...
'';
GOFLAGS = ["-ldflags=-extldflags=-static" "-w"];
meta = with lib; {
description = "go project scaffold";
homepage = "https://git.jeffthecoder.xyz/public/os-flakes";
license = licenses.unlicense;
maintainers = [ ];
};
}

View File

@ -1,49 +1,29 @@
{ {
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-23.11"; nixpkgs.url = "nixpkgs/nixos-unstable";
}; };
outputs = { nixpkgs, ... }: rec { outputs = { nixpkgs, ... }:
packages = nixpkgs.lib.genAttrs [ "x86_64-linux" "x86_64-darwin" ] (system: let
let pkgs = import nixpkgs { inherit system; }; in { systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
default = pkgs.buildGoModule { foreachSystem = nixpkgs.lib.genAttrs systems;
pname = "demo-signaling-server"; in
version = "0.0.1"; {
packages = foreachSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
rec {
hello = pkgs.callPackage ./default.nix { };
nativeBuildInputs = with pkgs; [ default = hello;
protobuf
protoc-gen-go
protoc-gen-go-grpc
];
preBuild = ''
go generate -v ./...
'';
src = ./.;
CGO_ENABLED = "0";
GOFLAGS = "-ldflags='-extldflags=-static -w -s";
vendorHash = "sha256-fxjQPK/6IWxnezix8aMMxw3+MZj8XxqnYD5Z9WUsdM4=";
};
});
devShells = nixpkgs.lib.genAttrs [ "x86_64-linux" "x86_64-darwin" ] (system:
let pkgs = import nixpkgs { inherit system; }; in {
default = packages."${system}".default.overrideAttrs (prevAttrs: {
GOFLAGS="";
nativeBuildInputs = prevAttrs.nativeBuildInputs ++ (with pkgs; [
gopls
golangci-lint
delve
gosec
go-outline
gotools
gomodifytags
impl
gotests
]);
}); });
}); devShells = foreachSystem
}; (system:
let
pkgs = import nixpkgs { inherit system; };
in
with pkgs; {
default = pkgs.callPackage ./shell.nix { };
});
};
} }

43
project-config.nix Normal file
View File

@ -0,0 +1,43 @@
{ gopls
, golangci-lint
, delve
, gosec
, go-outline
, gotools
, gomodifytags
, impl
, gotests
, protobuf
, protoc-gen-go
, protoc-gen-go-grpc
, ...
}: {
buildTools = [
protobuf
protoc-gen-go
protoc-gen-go-grpc
# pkg-config
# protobuf
# protoc-gen-go
# protoc-gen-go-grpc
# pigeon # PEG parser
# ent-go
# k6 # load testing
];
libraries = [ ];
devShellTools = [
gopls
golangci-lint
delve
gosec
go-outline
gotools
gomodifytags
impl
gotests
];
}

7
shell.nix Normal file
View File

@ -0,0 +1,7 @@
{ callPackage, project-config ? callPackage ./project-config.nix { }, ... }: let
package = callPackage ./default.nix { inherit project-config; };
in
package.overrideAttrs (final: priv: {
GOFLAGS = "";
nativeBuildInputs = priv.nativeBuildInputs ++ project-config.devShellTools;
})