nix: go generate in src derivation
All checks were successful
Test / Sandbox (push) Successful in 40s
Test / Fortify (race detector) (push) Successful in 49s
Test / Fortify (push) Successful in 50s
Test / Create distribution (push) Successful in 24s
Test / Sandbox (race detector) (push) Successful in 45s
Test / Fpkg (push) Successful in 39s
Test / Flake checks (push) Successful in 1m12s

This saves the generated files in the nix store and exposes them for use by external tools.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-06-07 03:10:36 +09:00
parent b7e991de5b
commit 9a7c81a44e
3 changed files with 38 additions and 20 deletions

View File

@@ -33,13 +33,34 @@ buildGoModule rec {
pname = "fortify";
version = "0.4.1";
src = builtins.path {
srcFiltered = builtins.path {
name = "${pname}-src";
path = lib.cleanSource ./.;
filter = path: type: !(type == "regular" && (lib.hasSuffix ".nix" path || lib.hasSuffix ".py" path)) && !(type == "directory" && lib.hasSuffix "/test" path) && !(type == "directory" && lib.hasSuffix "/cmd/fsu" path);
};
vendorHash = null;
src = stdenv.mkDerivation {
name = "${pname}-src-full";
inherit version;
enableParallelBuilding = true;
src = srcFiltered;
buildInputs = [
wayland
wayland-protocols
];
nativeBuildInputs = [
go
pkg-config
wayland-scanner
];
buildPhase = "GOCACHE=$(mktemp -d) go generate ./...";
installPhase = "cp -r . $out";
};
ldflags =
lib.attrsets.foldlAttrs
(
@@ -67,7 +88,6 @@ buildGoModule rec {
libseccomp
acl
wayland
wayland-protocols
]
++ (with xorg; [
libxcb
@@ -77,14 +97,9 @@ buildGoModule rec {
nativeBuildInputs = [
pkg-config
wayland-scanner
makeBinaryWrapper
];
preBuild = ''
HOME="$(mktemp -d)" PATH="${pkg-config}/bin:$PATH" go generate ./...
'';
postInstall =
let
appPackages = [
@@ -120,6 +135,10 @@ buildGoModule rec {
gcc
xorg.xorgproto
util-linux
# for go generate
wayland-protocols
wayland-scanner
]
++ buildInputs
++ nativeBuildInputs;