Skip to content

Commit

Permalink
Allow customizing the nixpkgs version from the default.nix using addi…
Browse files Browse the repository at this point in the history
…tionalNixpkgsOptions. Additionally use makeWrapper to wrap runtime dependencies on the output binary

This is needed for better supporting cross-compiling IHP apps.

Requires the project's Config/nix/nixpkgs-config.nix to be migrated to this:
```nix
{ ihp, additionalNixpkgsOptions }:
import "${toString ihp}/NixSupport/make-nixpkgs-from-options.nix" {
    ihp = ihp;
    additionalNixpkgsOptions = additionalNixpkgsOptions;
    haskellPackagesDir = ./haskell-packages/.;
}
```
  • Loading branch information
mpscholten committed Sep 17, 2021
1 parent dc977b8 commit e51ace8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
24 changes: 19 additions & 5 deletions NixSupport/default.nix
@@ -1,14 +1,21 @@
{ compiler ? "ghc8104", ihp, haskellDeps ? (p: []), otherDeps ? (p: []), projectPath ? ./., withHoogle ? false }:
{ compiler ? "ghc8104"
, ihp
, haskellDeps ? (p: [])
, otherDeps ? (p: [])
, projectPath ? ./.
, withHoogle ? false
, additionalNixpkgsOptions ? {}
}:

let
pkgs = import "${toString projectPath}/Config/nix/nixpkgs-config.nix" { ihp = ihp; };
pkgs = import "${toString projectPath}/Config/nix/nixpkgs-config.nix" { ihp = ihp; additionalNixpkgsOptions = additionalNixpkgsOptions; };
ghc = pkgs.haskell.packages.${compiler};
allHaskellPackages =
(if withHoogle
then ghc.ghcWithHoogle
else ghc.ghcWithPackages)
(p: builtins.concatLists [ [p.haskell-language-server] (haskellDeps p) ] );
allNativePackages = builtins.concatLists [ (otherDeps pkgs) [pkgs.postgresql] (if pkgs.stdenv.isDarwin then [] else []) ];
allNativePackages = builtins.concatLists [ (otherDeps pkgs) [pkgs.postgresql pkgs.makeWrapper] (if pkgs.stdenv.isDarwin then [] else []) ];
in
pkgs.stdenv.mkDerivation {
name = "app";
Expand All @@ -23,8 +30,15 @@ in
make -B build/bin/RunUnoptimizedProdServer
'';
installPhase = ''
mkdir -p $out
cp -r build/bin $out/bin
mkdir -p "$out"
mkdir -p $out/bin
mv build/bin/RunUnoptimizedProdServer $out/bin/RunUnoptimizedProdServer
makeWrapper $out/bin/RunUnoptimizedProdServer $out/bin/RunProdServer --prefix PATH : ${pkgs.lib.makeBinPath (otherDeps pkgs)}
mkdir -p "$out/lib/build"
cp -R "${ihp}/lib" "$out/lib/build/ihp-lib"
mv static "$out/lib/static"
'';
dontFixup = true;
src = (import <nixpkgs> {}).nix-gitignore.gitignoreSource [] projectPath;
Expand Down
3 changes: 2 additions & 1 deletion NixSupport/make-nixpkgs-from-options.nix
Expand Up @@ -10,6 +10,7 @@
, nixPkgsSha256 ? "0kfrw1mvpx2nkr493iq6bw0d6cxdwrmp6xqsir20bhmqwr36sds7"
, compiler ? "ghc8104"
, manualOverrides ? haskellPackagesNew: haskellPackagesOld: { } # More exotic overrides go here
, additionalNixpkgsOptions ? {}
}:
let
generatedOverrides = haskellPackagesNew: haskellPackagesOld:
Expand Down Expand Up @@ -75,7 +76,7 @@ let
repo = "nixpkgs";
rev = nixPkgsRev;
sha256 = nixPkgsSha256;
})) { inherit config; };
})) ({ inherit config; } // additionalNixpkgsOptions);

in
pkgs

0 comments on commit e51ace8

Please sign in to comment.