From ad1918aa6f5715845caad6c36e02b1f8535beab1 Mon Sep 17 00:00:00 2001 From: James Eversole Date: Fri, 7 Feb 2025 18:32:09 -0600 Subject: [PATCH] Statically link binaries --- flake.nix | 85 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/flake.nix b/flake.nix index 0667747..bd68a9d 100644 --- a/flake.nix +++ b/flake.nix @@ -2,46 +2,57 @@ description = "tricu"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs"; - flake-utils.url = "github:numtide/flake-utils"; + nixpkgs = { + url = "https://github.com/nh2/nixpkgs/archive/ede5282c487a1fd2de64303ba59adad6726f1225.tar.gz"; + type = "tarball"; + flake = false; + }; + static-haskell-nix = { + url = "github:nh2/static-haskell-nix"; + flake = false; + }; }; - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - packageName = "tricu"; - containerPackageName = "${packageName}-container"; + outputs = { self, nixpkgs, static-haskell-nix }: + let + system = "x86_64-linux"; + compiler = "ghc948"; + packageName = "tricu"; - customGHC = pkgs.haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [ - megaparsec - ]); - - haskellPackages = pkgs.haskellPackages; - - enableSharedExecutables = false; - enableSharedLibraries = false; - - tricu = pkgs.haskell.lib.justStaticExecutables self.packages.${system}.default; - in { - - packages.${packageName} = - haskellPackages.callCabal2nix packageName self rec {}; - - packages.default = self.packages.${system}.${packageName}; - defaultPackage = self.packages.${system}.default; - - devShells.default = pkgs.mkShell { - buildInputs = with pkgs; [ - haskellPackages.cabal-install - haskellPackages.ghc-events - haskellPackages.ghcid - customGHC - upx - ]; - inputsFrom = builtins.attrValues self.packages.${system}; + overlay = self: super: { + haskell = super.haskell // { + packages = super.haskell.packages // { + ${compiler} = super.haskell.packages.${compiler}.override { + overrides = final: prev: { + ${packageName} = prev.callCabal2nix packageName ./. {}; + }; + }; + }; }; - devShell = self.devShells.${system}.default; + }; - }); + overlays = [overlay]; + + normalPkgs = import nixpkgs { inherit overlays system; }; + + survey = import "${static-haskell-nix}/survey" { inherit compiler normalPkgs; }; + + tricuStatic = survey.haskellPackages.${packageName}; + + in { + packages.${system}.default = tricuStatic; + + devShells.default = normalPkgs.mkShell { + buildInputs = with normalPkgs; [ + normalPkgs.haskellPackages.cabal-install + normalPkgs.haskellPackages.ghc-events + normalPkgs.haskellPackages.ghcid + normalPkgs.upx + ]; + inputsFrom = builtins.attrValues self.packages.${system}; + }; + + devShell = self.devShells.${system}.default; + }; } +