From 09c16eb663a4acd1989ee3f901a232fac12b233f Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Sat, 15 Feb 2025 19:38:37 +0200 Subject: [PATCH] nix: static builds --- .gitignore | 1 + flake.nix | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index cef45c23..b654bd1d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ tmp *.db .bin/ appview/pages/static/* +result !.gitkeep diff --git a/flake.nix b/flake.nix index 870fb1a0..132fe61d 100644 --- a/flake.nix +++ b/flake.nix @@ -45,7 +45,7 @@ }; appview = with final; - final.buildGoModule { + final.pkgsStatic.buildGoModule { pname = "appview"; version = "0.1.0"; src = gitignoreSource ./.; @@ -56,16 +56,25 @@ subPackages = ["cmd/appview"]; vendorHash = "sha256-QgUPTOgAdKUTg+ztfs194G7pt3/qDtqTMkDRmMECxSo="; env.CGO_ENABLED = 1; + stdenv = pkgsStatic.stdenv; }; - knotserver = with final; - final.buildGoModule { - pname = "knotserver"; - version = "0.1.0"; - src = gitignoreSource ./.; - subPackages = ["cmd/knotserver"]; - vendorHash = "sha256-QgUPTOgAdKUTg+ztfs194G7pt3/qDtqTMkDRmMECxSo="; - env.CGO_ENABLED = 1; - }; + + knotserver = with final; + final.pkgsStatic.buildGoModule { + pname = "knotserver"; + version = "0.1.0"; + src = gitignoreSource ./.; + subPackages = ["cmd/knotserver"]; + vendorHash = "sha256-QgUPTOgAdKUTg+ztfs194G7pt3/qDtqTMkDRmMECxSo="; + env.CGO_ENABLED = 1; + nativeBuildInputs = with pkgsMusl; [ pkg-config ]; + + # Add these ldflags for static compilation + ldflags = [ "-s" "-w" "-linkmode external" ''-extldflags "-static -L${pkgsStatic.musl}/lib"'' ]; + + # Use static stdenv + stdenv = pkgMusl.stdenv; + }; }; packages = forAllSystems (system: { inherit (nixpkgsFor."${system}") indigo-lexgen appview knotserver; -- 2.51.2