From 26675235712fe09f56f81a6bef6ba3f51b80a486 Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Mon, 28 Aug 2023 16:09:57 +0200 Subject: [PATCH] Expose `CABAL_PROJECT_LOCAL_TEMPLATE` as a `/nix/store/` file --- cross-js.nix | 10 +++------- cross-windows.nix | 10 +++------- flake.nix | 17 ++++++++++------- quirks.nix | 22 ++++++++++++++++++++++ static.nix | 14 +++----------- 5 files changed, 41 insertions(+), 32 deletions(-) create mode 100644 quirks.nix diff --git a/cross-js.nix b/cross-js.nix index 871ef3f3..71faf796 100644 --- a/cross-js.nix +++ b/cross-js.nix @@ -35,6 +35,7 @@ let tool-version-map = import ./tool-map.nix; ${compiler}/bin/${compiler.targetPrefix}hsc2hs --cross-compile "$@" ''; }; + quirks = (import ./quirks.nix { inherit pkgs; }); in pkgs.mkShell ({ # Note [cabal override]: @@ -58,13 +59,7 @@ pkgs.mkShell ({ ]; # hardeningDisable = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isMusl [ "format" "pie" ]; - CABAL_PROJECT_LOCAL_TEMPLATE = with pkgs; '' - package digest - constraints: - HsOpenSSL +use-pkg-config, - zlib +pkg-config - pcre-lite +pkg-config - ''; + CABAL_PROJECT_LOCAL_TEMPLATE = quicks.CABAL_PROJECT_LOCAL_TEMPLATE; shellHook = with pkgs; '' export PS1="\[\033[01;33m\][\w]$\[\033[00m\] " @@ -73,6 +68,7 @@ pkgs.mkShell ({ echo "Revision (input-output-hk/devx): ${if self ? rev then self.rev else "unknown/dirty checkout"}." export CABAL_DIR=$HOME/.cabal-js echo "CABAL_DIR set to $CABAL_DIR" + ${quirks.shellHook} ''; buildInputs = []; diff --git a/cross-windows.nix b/cross-windows.nix index c17759e3..3214dd8b 100644 --- a/cross-windows.nix +++ b/cross-windows.nix @@ -96,6 +96,7 @@ let tool-version-map = import ./tool-map.nix; "$@" ''; }; + quirks = (import ./quirks.nix { inherit pkgs; }); in pkgs.pkgsBuildBuild.mkShell ({ # Note [cabal override]: @@ -118,13 +119,7 @@ pkgs.pkgsBuildBuild.mkShell ({ # "--enable-executable-static" ]; - CABAL_PROJECT_LOCAL_TEMPLATE = '' - package digest - constraints: - HsOpenSSL +use-pkg-config, - zlib +pkg-config - pcre-lite +pkg-config - ''; + CABAL_PROJECT_LOCAL_TEMPLATE = quicks.CABAL_PROJECT_LOCAL_TEMPLATE; shellHook = with pkgs; '' export PS1="\[\033[01;33m\][\w]$\[\033[00m\] " @@ -133,6 +128,7 @@ pkgs.pkgsBuildBuild.mkShell ({ echo "Revision (input-output-hk/devx): ${if self ? rev then self.rev else "unknown/dirty checkout"}." export CABAL_DIR=$HOME/.cabal-windows echo "CABAL_DIR set to $CABAL_DIR" + ${quirks.shellHook} ''; buildInputs = []; diff --git a/flake.nix b/flake.nix index f5c751c4..cdb65042 100644 --- a/flake.nix +++ b/flake.nix @@ -61,6 +61,13 @@ # # nix develop github:input-output-hk/devx#ghc924 --no-write-lock-file -c cabal build # + static-pkgs = if pkgs.stdenv.hostPlatform.isLinux + then if pkgs.stdenv.hostPlatform.isAarch64 + then pkgs.pkgsCross.aarch64-multiplatform-musl + else pkgs.pkgsCross.musl64 + else pkgs; + js-pkgs = pkgs.pkgsCross.ghcjs; + windows-pkgs = pkgs.pkgsCross.mingwW64; devShellsWithToolsModule = toolsModule: let compilers = pkgs: builtins.removeAttrs pkgs.haskell-nix.compiler # Exclude old versions of GHC to speed up `nix flake check` @@ -85,13 +92,6 @@ (builtins.removeAttrs (compilers pkgs) [ ]); - static-pkgs = if pkgs.stdenv.hostPlatform.isLinux - then if pkgs.stdenv.hostPlatform.isAarch64 - then pkgs.pkgsCross.aarch64-multiplatform-musl - else pkgs.pkgsCross.musl64 - else pkgs; - js-pkgs = pkgs.pkgsCross.ghcjs; - windows-pkgs = pkgs.pkgsCross.mingwW64; in (builtins.mapAttrs (compiler-nix-name: compiler: import ./dynamic.nix { inherit pkgs self compiler compiler-nix-name toolsModule; withIOG = false; } ) (compilers pkgs) @@ -202,6 +202,9 @@ }; })) devShellsWithEvalOnLinux) // { }; + packages.cabalProjectLocal.static = (import ./quirks.nix { pkgs = static-pkgs; static = true; }).template; + packages.cabalProjectLocal.cross-js = (import ./quirks.nix { pkgs = js-pkgs; }).template; + packages.cabalProjectLocal.cross-windows = (import ./quirks.nix { pkgs = windows-pkgs; }).template; }); # --- Flake Local Nix Configuration ---------------------------- diff --git a/quirks.nix b/quirks.nix new file mode 100644 index 00000000..26a61df6 --- /dev/null +++ b/quirks.nix @@ -0,0 +1,22 @@ +{ pkgs, static ? false }: rec { + CABAL_PROJECT_LOCAL_TEMPLATE = with pkgs; '' + package digest + ${if static then "extra-lib-dirs: ${zlib}/lib ${pcre}/lib" else ""} + constraints: + HsOpenSSL +use-pkg-config, + zlib +pkg-config, + pcre-lite +pkg-config + ''; + template = pkgs.writeTextFile { + name = "cabal.project.local"; + text = CABAL_PROJECT_LOCAL_TEMPLATE; + }; + shellHook = '' + echo "Quirks:" + echo -e "\tif you have the zlib, HsOpenSSL, or digest package in your dependency tree, please make sure to" + echo -e "\tcat ${template} >> cabal.project.local" + function patchProjectLocal() { + cat ${template} >> "$1" + } + ''; +} diff --git a/static.nix b/static.nix index aa60585a..c25bfc63 100644 --- a/static.nix +++ b/static.nix @@ -50,6 +50,7 @@ let tool-version-map = import ./tool-map.nix; esac ''; }; + quirks = (import ./quirks.nix { inherit pkgs; static = true; }); in pkgs.mkShell (rec { # Note [cabal override]: @@ -73,14 +74,7 @@ pkgs.mkShell (rec { ]; hardeningDisable = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isMusl [ "format" "pie" ]; - CABAL_PROJECT_LOCAL_TEMPLATE = with pkgs; '' - package digest - extra-lib-dirs: ${zlib}/lib ${pcre}/lib - constraints: - HsOpenSSL +use-pkg-config, - zlib +pkg-config, - pcre-lite +pkg-config - ''; + CABAL_PROJECT_LOCAL_TEMPLATE = quirks.CABAL_PROJECT_LOCAL_TEMPLATE; # This is required to prevent # @@ -102,9 +96,7 @@ pkgs.mkShell (rec { export CABAL_DIR=$HOME/.cabal-static echo "CABAL_DIR set to $CABAL_DIR" echo "DYLD_LIBRARY_PATH set to $DYLD_LIBRARY_PATH" - echo "Quirks:" - echo -e "\tif you have the zlib, HsOpenSSL, or digest package in your dependency tree, please make sure to" - echo -e "\techo \"\$CABAL_PROJECT_LOCAL_TEMPLATE\" > cabal.project.local" + ${quirks.shellHook} ''; # these are _target_ libs, e.g. ones we want to link the build