Skip to content

Commit 7e4e665

Browse files
authored
Merge pull request #24 from MatrixAI/wrap-deps
Add mkWrapper example
2 parents b812763 + 66fbee8 commit 7e4e665

7 files changed

Lines changed: 74 additions & 31 deletions

File tree

app/deps/Main.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import Deps ( sayHello )
4+
5+
main :: IO ()
6+
main = sayHello

cabal.nix

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{ mkDerivation, base, data-default-class, hello, hpack, http-types
2+
, iproute, monad-logger, mtl, network, safe-exceptions, stdenv
3+
, text, transformers, typed-process, wai, warp
4+
}:
5+
mkDerivation {
6+
pname = "haskell-demo";
7+
version = "0.1.0.0";
8+
src = ./.;
9+
isLibrary = true;
10+
isExecutable = true;
11+
libraryHaskellDepends = [
12+
base data-default-class http-types iproute monad-logger mtl network
13+
safe-exceptions text transformers typed-process wai warp
14+
];
15+
libraryToolDepends = [ hello hpack ];
16+
executableHaskellDepends = [
17+
base data-default-class http-types iproute monad-logger mtl network
18+
safe-exceptions text transformers typed-process wai warp
19+
];
20+
executableToolDepends = [ hello ];
21+
testHaskellDepends = [
22+
base data-default-class http-types iproute monad-logger mtl network
23+
safe-exceptions text transformers typed-process wai warp
24+
];
25+
testToolDepends = [ hello ];
26+
prePatch = "hpack";
27+
homepage = "https://github.com/MatrixAI/Haskell-Demo#readme";
28+
license = stdenv.lib.licenses.asl20;
29+
}

default.nix

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
{ mkDerivation, base, data-default-class, hpack, http-types
2-
, iproute, monad-logger, mtl, network, safe-exceptions, stdenv
3-
, text, transformers, wai, warp
4-
}:
5-
mkDerivation {
6-
pname = "haskell-demo";
7-
version = "0.1.0.0";
8-
src = ./.;
9-
isLibrary = true;
10-
isExecutable = true;
11-
libraryHaskellDepends = [
12-
base data-default-class http-types iproute monad-logger mtl network
13-
safe-exceptions text transformers wai warp
14-
];
15-
libraryToolDepends = [ hpack ];
16-
executableHaskellDepends = [
17-
base data-default-class http-types iproute monad-logger mtl network
18-
safe-exceptions text transformers wai warp
19-
];
20-
testHaskellDepends = [
21-
base data-default-class http-types iproute monad-logger mtl network
22-
safe-exceptions text transformers wai warp
23-
];
24-
prePatch = "hpack";
25-
homepage = "https://github.com/MatrixAI/Haskell-Demo#readme";
26-
license = stdenv.lib.licenses.asl20;
27-
}
1+
{ pkgs ? import ./pkgs.nix }:
2+
3+
with pkgs;
4+
let
5+
drv = (haskellPackages.callPackage ./cabal.nix { inherit hello; });
6+
in
7+
drv.overrideAttrs (attrs: {
8+
src = nix-gitignore.gitignoreSource [] ./.;
9+
nativeBuildInputs = attrs.nativeBuildInputs ++ [ makeWrapper ];
10+
postFixup = ''
11+
wrapProgram $out/bin/haskell-demo-deps-exe \
12+
--set PATH ${lib.makeBinPath [
13+
hello
14+
]}
15+
'';
16+
})

package.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ dependencies:
2525
- http-types
2626
- data-default-class
2727
- text
28+
- typed-process
29+
30+
system-build-tools:
31+
- hello
2832

2933
library:
3034
source-dirs: src
@@ -41,6 +45,7 @@ library:
4145
- FFI
4246
- Demo
4347
- Library
48+
- Deps
4449

4550
executables:
4651
haskell-demo-ffi-exe:
@@ -70,6 +75,15 @@ executables:
7075
- -with-rtsopts=-N
7176
dependencies:
7277
- haskell-demo
78+
haskell-demo-deps-exe:
79+
main: Main.hs
80+
source-dirs: app/deps
81+
ghc-options:
82+
- -threaded
83+
- -rtsopts
84+
- -with-rtsopts=-N
85+
dependencies:
86+
- haskell-demo
7387

7488
tests:
7589
haskell-demo-test:

release.nix

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ with pkgs;
44
let
55
haskellPackages = haskell.packages.ghc865;
66
strict = drv: haskell.lib.buildStrictly drv;
7-
drv = (haskellPackages.callPackage ./default.nix {}).overrideAttrs (attrs: {
8-
src = nix-gitignore.gitignoreSource [] ./.;
9-
});
7+
drv = haskellPackages.callPackage ./default.nix {};
108
in
119
rec {
1210
library = drv;

shell.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ in
1616
echo 'Entering ${attrs.name}'
1717
set -v
1818
19-
cabal2nix --hpack . >./default.nix
19+
cabal2nix --hpack . >./cabal.nix
2020
hpack --force
2121
cabal v2-configure
2222

src/Deps.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Deps where
3+
4+
import System.Process.Typed ( runProcess_ )
5+
6+
sayHello :: IO ()
7+
sayHello = runProcess_ "hello"

0 commit comments

Comments
 (0)