Skip to content

Instantly share code, notes, and snippets.

@teh
Last active August 2, 2017 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teh/f4b45ba1ac46f0ae618c05739570d026 to your computer and use it in GitHub Desktop.
Save teh/f4b45ba1ac46f0ae618c05739570d026 to your computer and use it in GitHub Desktop.
{ mkDerivation, stdenv, haskell, glibc, gmp, bytestring
}:
let gmp-static = gmp.override { withStatic = true; };
in mkDerivation {
pname = "static-haskell";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
configureFlags = [
"--ghc-option=-optl=-static"
"--ghc-option=-optl=-pthread"
"--extra-lib-dirs=${glibc.static}/lib"
"--extra-lib-dirs=${gmp-static}/lib"
];
executableHaskellDepends = [
bytestring
];
license = stdenv.lib.licenses.gpl3;
enableSharedExecutables = false;
}
module Main where
main = print "hi"
$ nix-build -E "with (import <nixpkgs> {}).pkgs; haskellPackages.callPackage ./. {}"
...
$ ldd /nix/store/pd6ax4qhldi79vkilxy8246l7pz7l59f-static-haskell-0.1.0.0/bin/main
	not a dynamic executable
$ /nix/store/pd6ax4qhldi79vkilxy8246l7pz7l59f-static-haskell-0.1.0.0/bin/main
"hi"
name: static-haskell-nix
version: 0.1.0.0
dependencies:
- base >=4.9 && <5
executables:
main:
main: Main.hs
-- This file has been generated from package.yaml by hpack version 0.17.0.
--
-- see: https://github.com/sol/hpack
name: static-haskell-nix
version: 0.1.0.0
build-type: Simple
cabal-version: >= 1.10
executable main
main-is: Main.hs
build-depends:
base >=4.9 && <5
default-language: Haskell2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment