Skip to content

Commit

Permalink
Expose CABAL_PROJECT_LOCAL_TEMPLATE as a /nix/store/ file
Browse files Browse the repository at this point in the history
  • Loading branch information
yvan-sraka committed Aug 31, 2023
1 parent f87e924 commit fa7fc57
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
10 changes: 3 additions & 7 deletions cross-js.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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\] "
Expand All @@ -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 = [];

Expand Down
10 changes: 3 additions & 7 deletions cross-windows.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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\] "
Expand All @@ -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 = [];

Expand Down
17 changes: 10 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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)
Expand Down Expand Up @@ -202,6 +202,9 @@
};
})) devShellsWithEvalOnLinux) // {
};
packages.cabal_project_local.static = (import ./quirks.nix { pkgs = static-pkgs; static = true; }).template;
packages.cabal_project_local.cross-js = (import ./quirks.nix { pkgs = js-pkgs; }).template;
packages.cabal_project_local.cross-windows = (import ./quirks.nix { pkgs = windows-pkgs; }).template;
});

# --- Flake Local Nix Configuration ----------------------------
Expand Down
22 changes: 22 additions & 0 deletions quirks.nix
Original file line number Diff line number Diff line change
@@ -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"
}
'';
}
14 changes: 3 additions & 11 deletions static.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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
#
Expand All @@ -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
Expand Down

0 comments on commit fa7fc57

Please sign in to comment.