on iko/ghcjs-patch-master help sign in
Add callStackToNix function (#116)

Allow building a stack project directly without needing to generate the scaffolding. ```nix { mkStackPkgSet, callStackToNix, ... }: let pkgSet = mkStackPkgSet { stack-pkgs = callStackToNix { src = ./.; }; pkg-def-extras = []; modules = []; }; in pkgSet.config.hsPkgs ```

commit390771849af43f274da886175d4619740fe9fe12 authorEdward Amsden <edward@blackriversoft.com> dateFri 17 May 2019, 03:49 (7 years ago) parent072debc
12 files changed+194−3
call-stack-to-nix.nix+20 default.nix+6−2 test/callStackToNix/.gitignore+3 test/callStackToNix/Setup.hs+2 test/callStackToNix/app/Main.hs+6 test/callStackToNix/default.nix+33 test/callStackToNix/package.yaml+48 test/callStackToNix/src/Lib.hs+6 test/callStackToNix/stack.yaml+66 test/callStackToNix/test/Spec.hs+2 test/default.nix+1 test/tests.sh+1−1
call-stack-to-nix.nixnew file+20
@@ -0,0 +1,20 @@
1+/* The function obtained when this is applied to a package set calls
2+ * the stack-to-nix tool on a supplied source set and then
3+ * imports the resulting pkgs.nix. The application of this function
4+ * to a source path can thus be used directly as the input to mkStackPackageSet
5+ */
6+{ nix-tools, pkgs }:
7+{ src, stackYaml ? null }:
8+let
9+ pkgsNix = pkgs.stdenv.mkDerivation {
10+ name = "pkgs-nix";
11+ inherit src;
12+ nativeBuildInputs = [ nix-tools pkgs.nix-prefetch-git ];
13+ installPhase = ''
14+ export LANG=C.utf8 # Needed or stack-to-nix will die on unicode inputs
15+ mkdir -p $out
16+ stack-to-nix --stack-yaml=$src/${if stackYaml == null then "stack.yaml" else stackYaml} -o $out
17+ mv $out/pkgs.nix $out/default.nix
18+ '';
19+ };
20+in import pkgsNix
default.nix+6−2
@@ -106,8 +106,12 @@ let
106106 };
107107
108108 # Programs for generating Nix expressions from Cabal and Stack
109− # files.
110− nix-tools = self.callPackage ./nix-tools { inherit fetchExternal; };
109+ # files. We need to make sure we build this from the buildPackages,
110+ # we never want to actually cross compile nix-tools on it's own.
111+ nix-tools = pkgs.buildPackages.callPackage ./nix-tools { inherit fetchExternal; inherit (self) mkCabalProjectPkgSet; };
112+
113+ # Function to call stackToNix
114+ callStackToNix = self.callPackage ./call-stack-to-nix.nix {};
111115
112116 # Snapshots of Hackage and Stackage, converted to Nix expressions,
113117 # regularly updated.
test/callStackToNix/.gitignorenew file+3
@@ -0,0 +1,3 @@
1+.stack-work/
2+stack-simple.cabal
3+*~
test/callStackToNix/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
test/callStackToNix/app/Main.hsnew file+6
@@ -0,0 +1,6 @@
1+module Main where
2+
3+import Lib
4+
5+main :: IO ()
6+main = someFunc
test/callStackToNix/default.nixnew file+33
@@ -0,0 +1,33 @@
1+{ stdenv, mkStackPkgSet, callStackToNix }:
2+
3+with stdenv.lib;
4+
5+let
6+ pkgSet = mkStackPkgSet {
7+ stack-pkgs = callStackToNix { src = ./.; };
8+ pkg-def-extras = [];
9+ modules = [];
10+ };
11+
12+ packages = pkgSet.config.hsPkgs;
13+
14+in
15+ stdenv.mkDerivation {
16+ name = "callStackToNix-test";
17+
18+ buildCommand = ''
19+ exe="${packages.stack-simple.components.exes.stack-simple-exe}/bin/stack-simple-exe"
20+
21+ printf "checking whether executable runs... " >& 2
22+ $exe
23+
24+ touch $out
25+ '';
26+
27+ meta.platforms = platforms.all;
28+
29+ passthru = {
30+ # Attributes used for debugging with nix repl
31+ inherit pkgSet packages;
32+ };
33+ }
test/callStackToNix/package.yamlnew file+48
@@ -0,0 +1,48 @@
1+name: stack-simple
2+version: 0.1.0.0
3+github: "githubuser/stack-simple"
4+license: BSD3
5+author: "Author name here"
6+maintainer: "example@example.com"
7+copyright: "2019 Author name here"
8+
9+extra-source-files:
10+- README.md
11+- ChangeLog.md
12+
13+# Metadata used when publishing your package
14+# synopsis: Short description of your package
15+# category: Web
16+
17+# To avoid duplicated efforts in documentation and dealing with the
18+# complications of embedding Haddock markup inside cabal files, it is
19+# common to point users to the README.md file.
20+description: Please see the README on GitHub at <https://github.com/githubuser/stack-simple#readme>
21+
22+dependencies:
23+- base >= 4.7 && < 5
24+
25+library:
26+ source-dirs: src
27+
28+executables:
29+ stack-simple-exe:
30+ main: Main.hs
31+ source-dirs: app
32+ ghc-options:
33+ - -threaded
34+ - -rtsopts
35+ - -with-rtsopts=-N
36+ dependencies:
37+ - stack-simple
38+
39+tests:
40+ stack-simple-test:
41+ main: Spec.hs
42+ source-dirs: test
43+ ghc-options:
44+ - -threaded
45+ - -rtsopts
46+ - -with-rtsopts=-N
47+ dependencies:
48+ - stack-simple
test/callStackToNix/src/Lib.hsnew file+6
@@ -0,0 +1,6 @@
1+module Lib
2+ ( someFunc
3+ ) where
4+
5+someFunc :: IO ()
6+someFunc = putStrLn "someFunc"
test/callStackToNix/stack.yamlnew file+66
@@ -0,0 +1,66 @@
1+# This file was automatically generated by 'stack init'
2+#
3+# Some commonly used options have been documented as comments in this file.
4+# For advanced use and comprehensive documentation of the format, please see:
5+# https://docs.haskellstack.org/en/stable/yaml_configuration/
6+
7+# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8+# A snapshot resolver dictates the compiler version and the set of packages
9+# to be used for project dependencies. For example:
10+#
11+# resolver: lts-3.5
12+# resolver: nightly-2015-09-21
13+# resolver: ghc-7.10.2
14+#
15+# The location of a snapshot can be provided as a file or url. Stack assumes
16+# a snapshot provided as a file might change, whereas a url resource does not.
17+#
18+# resolver: ./custom-snapshot.yaml
19+# resolver: https://example.com/snapshots/2018-01-01.yaml
20+resolver: lts-13.6
21+
22+# User packages to be built.
23+# Various formats can be used as shown in the example below.
24+#
25+# packages:
26+# - some-directory
27+# - https://example.com/foo/bar/baz-0.0.2.tar.gz
28+# - location:
29+# git: https://github.com/commercialhaskell/stack.git
30+# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
31+# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
32+# subdirs:
33+# - auto-update
34+# - wai
35+packages:
36+- .
37+# Dependency packages to be pulled from upstream that are not in the resolver
38+# using the same syntax as the packages field.
39+# (e.g., acme-missiles-0.3)
40+extra-deps:
41+- process-1.6.5.0
42+- transformers-0.5.6.2
43+
44+# Override default flag values for local packages and extra-deps
45+# flags: {}
46+
47+# Extra package databases containing global packages
48+# extra-package-dbs: []
49+
50+# Control whether we use the GHC we find on the path
51+# system-ghc: true
52+#
53+# Require a specific version of stack, using version ranges
54+# require-stack-version: -any # Default
55+# require-stack-version: ">=1.9"
56+#
57+# Override the architecture used by stack, especially useful on Windows
58+# arch: i386
59+# arch: x86_64
60+#
61+# Extra directories used by stack for building
62+# extra-include-dirs: [/path/to/dir]
63+# extra-lib-dirs: [/path/to/dir]
64+#
65+# Allow a newer minor version of GHC than the snapshot specifies
66+# compiler-check: newer-minor
test/callStackToNix/test/Spec.hsnew file+2
@@ -0,0 +1,2 @@
1+main :: IO ()
2+main = putStrLn "Test suite not yet implemented"
test/default.nix+1
@@ -15,6 +15,7 @@ in {
1515 with-packages = haskell.callPackage ./with-packages { inherit util; };
1616 builder-haddock = haskell.callPackage ./builder-haddock {};
1717 stack-simple = haskell.callPackage ./stack-simple {};
18+ callStackToNix = haskell.callPackage ./callStackToNix {};
1819
1920 # Run unit tests with: nix-instantiate --eval --strict -A unit
2021 # An empty list means success.
test/tests.sh+1−1
@@ -12,7 +12,7 @@ rm -rvf */cabal.project.local */.ghc.environment* */dist */dist-newstyle */.stac
1212echo >& 2
1313
1414printf "*** Running the nix-build tests...\n" >& 2
15−nix-build $NIX_BUILD_ARGS --no-out-link --keep-going ./default.nix
15+nix build $NIX_BUILD_ARGS --no-link --keep-going -f ./default.nix
1616echo >& 2
1717
1818printf "*** Running the unit tests... " >& 2