Skip to content

Commit

Permalink
build(nix-shell): use static libc and static build
Browse files Browse the repository at this point in the history
The non-buildx Dockerfile copies a binary built outside of the docker
build, which may be broken if the dependencies are not met.
This happens on nix-shell as the deps exist on /nix/store.
Get around this by building static binaries in the nix-shell.

Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Jan 6, 2025
1 parent b6de5bd commit e73716f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions buildscripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ XC_ARCH=$(go env GOARCH)
# Build!
echo "==> Building ${CTLNAME} using $(go version)... "

if [ -n "$IN_NIX_SHELL" ]; then
MAYBE_STATIC="-linkmode external -extldflags "-static""
fi

GOOS="${XC_OS}"
GOARCH="${XC_ARCH}"
output_name="bin/${PNAME}/"$GOOS"_"$GOARCH"/"$CTLNAME
Expand All @@ -99,6 +103,7 @@ fi
env GOOS=$GOOS GOARCH=$GOARCH go build -ldflags \
"-X github.com/openebs/lvm-localpv/pkg/version.GitCommit=${GIT_COMMIT} \
-X main.CtlName='${CTLNAME}' \
${MAYBE_STATIC:-} \
-X github.com/openebs/lvm-localpv/pkg/version.Version=${VERSION} \
-X github.com/openebs/lvm-localpv/pkg/version.VersionMeta=${VERSION_META}"\
-o $output_name\
Expand Down
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pkgs.mkShell {
curl
cacert
util-linux
glibc.static
] ++ pkgs.lib.optional (builtins.getEnv "IN_NIX_SHELL" == "pure") docker;
shellHook = ''
export GOPATH=$(pwd)/nix/.go
Expand Down

0 comments on commit e73716f

Please sign in to comment.