From 22baf18d32ccd932bcd9a321807d3a70988e3c3e Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Thu, 15 Aug 2019 17:44:25 +0200 Subject: [PATCH] Add nix stuff to compile fully statically (still not working...) --- default.nix | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 default.nix diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..fed3572 --- /dev/null +++ b/default.nix @@ -0,0 +1,46 @@ +# Run using: +# +# $(nix-build --no-link -A fullBuildScript) +# also the following might be needed: +# sysctl kernel.unprivileged_userns_clone=1 +{ + stack2nix-output-path ? "custom-stack2nix-output.nix", +}: +let + cabalPackageName = "geval"; + compiler = "ghc844"; # matching stack.yaml + + # Pin nixpkgs version. + pkgs = import (fetchTarball https://github.com/nh2/nixpkgs/archive/a2d7e9b875e8ba7fd15b989cf2d80be4e183dc72.tar.gz) {}; + + # Pin static-haskell-nix version. + static-haskell-nix = fetchTarball https://github.com/nh2/static-haskell-nix/archive/1d37d9a83e570eceef9c7dad5c89557f8179a076.tar.gz; + + stack2nix-script = import "${static-haskell-nix}/static-stack2nix-builder/stack2nix-script.nix" { + inherit pkgs; + stack-project-dir = toString ./.; # where stack.yaml is + hackageSnapshot = "2019-05-08T00:00:00Z"; # pins e.g. extra-deps without hashes or revisions + }; + + static-stack2nix-builder = import "${static-haskell-nix}/static-stack2nix-builder/default.nix" { + normalPkgs = pkgs; + inherit cabalPackageName compiler stack2nix-output-path; + # disableOptimization = true; # for compile speed + }; + + # Full invocation, including pinning `nix` version itself. + fullBuildScript = pkgs.writeScript "stack2nix-and-build-script.sh" '' + #!/usr/bin/env bash + set -eu -o pipefail + STACK2NIX_OUTPUT_PATH=$(${stack2nix-script}) + ${pkgs.nix}/bin/nix-build --no-link -A static_package --argstr stack2nix-output-path "$STACK2NIX_OUTPUT_PATH" "$@" + ''; + +in + { + static_package = static-stack2nix-builder.static_package; + inherit fullBuildScript; + # For debugging: + inherit stack2nix-script; + inherit static-stack2nix-builder; +} \ No newline at end of file