fix: fix nix build error (#1280)
Some checks are pending
最新版 / Build binary CI (386, linux) (push) Waiting to run
最新版 / Build binary CI (386, windows) (push) Waiting to run
最新版 / Build binary CI (amd64, linux) (push) Waiting to run
最新版 / Build binary CI (amd64, windows) (push) Waiting to run
最新版 / Build binary CI (arm, linux) (push) Waiting to run
最新版 / Build binary CI (arm64, linux) (push) Waiting to run
PushLint / lint (push) Waiting to run

This commit is contained in:
Nobody6825 2026-01-30 23:18:10 +08:00 committed by GitHub
parent 1c8ff7b143
commit f6934709cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 85 additions and 68 deletions

View File

@ -18,9 +18,9 @@ buildGoApplication {
version = "1.8.0"; version = "1.8.0";
pwd = ./.; pwd = ./.;
src = ./.; src = ./.;
# spec go version manually bcs go = pkgs.go_1_24;
# https://github.com/nix-community/gomod2nix/blob/30e3c3a9ec4ac8453282ca7f67fca9e1da12c3e6/builder/default.nix#L130 preBuild = ''
# do not work go generate main.go
go = pkgs.go_1_20; '';
modules = ./gomod2nix.toml; modules = ./gomod2nix.toml;
} }

View File

@ -28,11 +28,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1742209644, "lastModified": 1767019875,
"narHash": "sha256-jMy1XqXqD0/tJprEbUmKilTkvbDY/C0ZGSsJJH4TNCE=", "narHash": "sha256-NodN+lhWTD59b44Q2bPjE1edINfjfRkQYdZsrxifCeU=",
"owner": "nix-community", "owner": "nix-community",
"repo": "gomod2nix", "repo": "gomod2nix",
"rev": "8f3534eb8f6c5c3fce799376dc3b91bae6b11884", "rev": "49662a44272806ff785df2990a420edaaca15db4",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -43,11 +43,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1745391562, "lastModified": 1769461804,
"narHash": "sha256-sPwcCYuiEopaafePqlG826tBhctuJsLx/mhKKM5Fmjo=", "narHash": "sha256-msG8SU5WsBUfVVa/9RPLaymvi5bI8edTavbIq3vRlhI=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "8a2f738d9d1f1d986b5a4cd2fd2061a7127237d7", "rev": "bfc1b8a4574108ceef22f02bafcf6611380c100d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -57,28 +57,11 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-with-go_1_20": {
"locked": {
"lastModified": 1710843028,
"narHash": "sha256-CMbK45c4nSkGvayiEHFkGFH+doGPbgo3AWfecd2t1Fk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "33c51330782cb486764eb598d5907b43dc87b4c2",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "33c51330782cb486764eb598d5907b43dc87b4c2",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"gomod2nix": "gomod2nix", "gomod2nix": "gomod2nix",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs"
"nixpkgs-with-go_1_20": "nixpkgs-with-go_1_20"
} }
}, },
"systems": { "systems": {

View File

@ -1,7 +1,6 @@
{ {
description = " ZeroBot OneBot "; description = " ZeroBot OneBot ";
inputs.nixpkgs-with-go_1_20.url = "github:NixOS/nixpkgs/33c51330782cb486764eb598d5907b43dc87b4c2";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.gomod2nix.url = "github:nix-community/gomod2nix"; inputs.gomod2nix.url = "github:nix-community/gomod2nix";
@ -11,53 +10,85 @@
outputs = { outputs = {
self, self,
nixpkgs, nixpkgs,
nixpkgs-with-go_1_20,
flake-utils, flake-utils,
gomod2nix, gomod2nix,
... }: (flake-utils.lib.eachDefaultSystem (
} @ inputs: let system: let
allSystems = flake-utils.lib.allSystems; pkgs = nixpkgs.legacyPackages.${system};
in (
flake-utils.lib.eachSystem allSystems
(system: let
old-nixpkgs = nixpkgs-with-go_1_20.legacyPackages.${system};
pkgs = import nixpkgs {
inherit system;
overlays = [ callPackage = pkgs.callPackage;
(_: _: { # Simple test check added to nix flake check
go_1_20 = old-nixpkgs.go_1_20; go-test = pkgs.stdenvNoCC.mkDerivation {
}) name = "go-test";
dontBuild = true;
src = ./.;
doCheck = true;
nativeBuildInputs = with pkgs; [
go
writableTmpDirAsHomeHook
]; ];
checkPhase = ''
go test -v ./...
'';
installPhase = ''
mkdir "$out"
'';
}; };
# Simple lint check added to nix flake check
# The current default sdk for macOS fails to compile go projects, so we use a newer one for now. go-lint = pkgs.stdenvNoCC.mkDerivation {
# This has no effect on other platforms. name = "go-lint";
callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage; dontBuild = true;
in { src = ./.;
# doCheck will fail at write files doCheck = true;
packages = rec { nativeBuildInputs = with pkgs; [
ZeroBot-Plugin = (callPackage ./. (inputs golangci-lint
// { go
writableTmpDirAsHomeHook
];
checkPhase = ''
golangci-lint run
'';
installPhase = ''
mkdir "$out"
'';
};
# doCheck will fail at download files
ZeroBot-Plugin = (callPackage ./. {
inherit (gomod2nix.legacyPackages.${system}) buildGoApplication; inherit (gomod2nix.legacyPackages.${system}) buildGoApplication;
})) }).overrideAttrs (_: {doCheck = false;});
.overrideAttrs (_: {doCheck = false;}); # Build container layered image, useful overtime to save storage on duplicated layers
containerImage = pkgs.dockerTools.buildLayeredImage {
default = ZeroBot-Plugin;
docker_builder = pkgs.dockerTools.buildLayeredImage {
name = "ZeroBot-Plugin"; name = "ZeroBot-Plugin";
tag = "latest"; tag = "latest";
created = "now";
contents = [ contents = [
self.packages.${system}.ZeroBot-Plugin
pkgs.cacert pkgs.cacert
pkgs.openssl
]; ];
config = {
Cmd = ["${ZeroBot-Plugin}/bin/ZeroBot-Plugin"];
}; };
}; };
in {
inherit containerImage;
checks = {
inherit go-test go-lint;
};
packages.default = ZeroBot-Plugin;
devShells.default = callPackage ./shell.nix { devShells.default = callPackage ./shell.nix {
inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix; inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix;
}; };
# Custom application to build and load container image into the docker daemon
# For now docker is a requirement
apps.build-and-load = {
type = "app";
program = "${pkgs.writeShellScriptBin "build-and-load" ''
nix build .#containerImage.${system}
docker load < result
echo "Container image loaded"
''}/bin/build-and-load";
};
formatter = pkgs.alejandra; formatter = pkgs.alejandra;
}) }
); ));
} }

View File

@ -13,7 +13,10 @@
mkGoEnv ? pkgs.mkGoEnv, mkGoEnv ? pkgs.mkGoEnv,
gomod2nix ? pkgs.gomod2nix, gomod2nix ? pkgs.gomod2nix,
}: let }: let
goEnv = mkGoEnv { pwd = ./.; go = pkgs.go_1_20; }; goEnv = mkGoEnv {
pwd = ./.;
go = pkgs.go_1_24;
};
in in
pkgs.mkShell { pkgs.mkShell {
packages = [ packages = [