diff --git a/call-stack-to-nix.nix b/call-stack-to-nix.nix new file mode 100644 index 0000000000..86c122b2e4 --- /dev/null +++ b/call-stack-to-nix.nix @@ -0,0 +1,20 @@ +/* The function obtained when this is applied to a package set calls + * the stack-to-nix tool on a supplied source set and then + * imports the resulting pkgs.nix. The application of this function + * to a source path can thus be used directly as the input to mkStackPackageSet + */ +{ nix-tools, pkgs }: +{ src, stackYaml ? null }: +let + pkgsNix = pkgs.stdenv.mkDerivation { + name = "pkgs-nix"; + inherit src; + nativeBuildInputs = [ nix-tools pkgs.nix-prefetch-git ]; + installPhase = '' + export LANG=C.utf8 # Needed or stack-to-nix will die on unicode inputs + mkdir -p $out + stack-to-nix --stack-yaml=$src/${if stackYaml == null then "stack.yaml" else stackYaml} -o $out + mv $out/pkgs.nix $out/default.nix + ''; + }; +in import pkgsNix diff --git a/default.nix b/default.nix index 175228a4b3..20c57fd093 100644 --- a/default.nix +++ b/default.nix @@ -106,8 +106,12 @@ let }; # Programs for generating Nix expressions from Cabal and Stack - # files. - nix-tools = self.callPackage ./nix-tools { inherit fetchExternal; }; + # files. We need to make sure we build this from the buildPackages, + # we never want to actually cross compile nix-tools on it's own. + nix-tools = pkgs.buildPackages.callPackage ./nix-tools { inherit fetchExternal; inherit (self) mkCabalProjectPkgSet; }; + + # Function to call stackToNix + callStackToNix = self.callPackage ./call-stack-to-nix.nix {}; # Snapshots of Hackage and Stackage, converted to Nix expressions, # regularly updated. diff --git a/test/callStackToNix/.gitignore b/test/callStackToNix/.gitignore new file mode 100644 index 0000000000..93c2650f43 --- /dev/null +++ b/test/callStackToNix/.gitignore @@ -0,0 +1,3 @@ +.stack-work/ +stack-simple.cabal +*~ \ No newline at end of file diff --git a/test/callStackToNix/Setup.hs b/test/callStackToNix/Setup.hs new file mode 100644 index 0000000000..9a994af677 --- /dev/null +++ b/test/callStackToNix/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/test/callStackToNix/app/Main.hs b/test/callStackToNix/app/Main.hs new file mode 100644 index 0000000000..de1c1ab35c --- /dev/null +++ b/test/callStackToNix/app/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Lib + +main :: IO () +main = someFunc diff --git a/test/callStackToNix/default.nix b/test/callStackToNix/default.nix new file mode 100644 index 0000000000..fac148f9ee --- /dev/null +++ b/test/callStackToNix/default.nix @@ -0,0 +1,33 @@ +{ stdenv, mkStackPkgSet, callStackToNix }: + +with stdenv.lib; + +let + pkgSet = mkStackPkgSet { + stack-pkgs = callStackToNix { src = ./.; }; + pkg-def-extras = []; + modules = []; + }; + + packages = pkgSet.config.hsPkgs; + +in + stdenv.mkDerivation { + name = "callStackToNix-test"; + + buildCommand = '' + exe="${packages.stack-simple.components.exes.stack-simple-exe}/bin/stack-simple-exe" + + printf "checking whether executable runs... " >& 2 + $exe + + touch $out + ''; + + meta.platforms = platforms.all; + + passthru = { + # Attributes used for debugging with nix repl + inherit pkgSet packages; + }; + } diff --git a/test/callStackToNix/package.yaml b/test/callStackToNix/package.yaml new file mode 100644 index 0000000000..7903b38ff8 --- /dev/null +++ b/test/callStackToNix/package.yaml @@ -0,0 +1,48 @@ +name: stack-simple +version: 0.1.0.0 +github: "githubuser/stack-simple" +license: BSD3 +author: "Author name here" +maintainer: "example@example.com" +copyright: "2019 Author name here" + +extra-source-files: +- README.md +- ChangeLog.md + +# Metadata used when publishing your package +# synopsis: Short description of your package +# category: Web + +# To avoid duplicated efforts in documentation and dealing with the +# complications of embedding Haddock markup inside cabal files, it is +# common to point users to the README.md file. +description: Please see the README on GitHub at + +dependencies: +- base >= 4.7 && < 5 + +library: + source-dirs: src + +executables: + stack-simple-exe: + main: Main.hs + source-dirs: app + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - stack-simple + +tests: + stack-simple-test: + main: Spec.hs + source-dirs: test + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - stack-simple diff --git a/test/callStackToNix/src/Lib.hs b/test/callStackToNix/src/Lib.hs new file mode 100644 index 0000000000..d36ff2714d --- /dev/null +++ b/test/callStackToNix/src/Lib.hs @@ -0,0 +1,6 @@ +module Lib + ( someFunc + ) where + +someFunc :: IO () +someFunc = putStrLn "someFunc" diff --git a/test/callStackToNix/stack.yaml b/test/callStackToNix/stack.yaml new file mode 100644 index 0000000000..bd2cb60d1e --- /dev/null +++ b/test/callStackToNix/stack.yaml @@ -0,0 +1,66 @@ +# This file was automatically generated by 'stack init' +# +# Some commonly used options have been documented as comments in this file. +# For advanced use and comprehensive documentation of the format, please see: +# https://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Resolver to choose a 'specific' stackage snapshot or a compiler version. +# A snapshot resolver dictates the compiler version and the set of packages +# to be used for project dependencies. For example: +# +# resolver: lts-3.5 +# resolver: nightly-2015-09-21 +# resolver: ghc-7.10.2 +# +# The location of a snapshot can be provided as a file or url. Stack assumes +# a snapshot provided as a file might change, whereas a url resource does not. +# +# resolver: ./custom-snapshot.yaml +# resolver: https://example.com/snapshots/2018-01-01.yaml +resolver: lts-13.6 + +# User packages to be built. +# Various formats can be used as shown in the example below. +# +# packages: +# - some-directory +# - https://example.com/foo/bar/baz-0.0.2.tar.gz +# - location: +# git: https://github.com/commercialhaskell/stack.git +# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# subdirs: +# - auto-update +# - wai +packages: +- . +# Dependency packages to be pulled from upstream that are not in the resolver +# using the same syntax as the packages field. +# (e.g., acme-missiles-0.3) +extra-deps: +- process-1.6.5.0 +- transformers-0.5.6.2 + +# Override default flag values for local packages and extra-deps +# flags: {} + +# Extra package databases containing global packages +# extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true +# +# Require a specific version of stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: ">=1.9" +# +# Override the architecture used by stack, especially useful on Windows +# arch: i386 +# arch: x86_64 +# +# Extra directories used by stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] +# +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor diff --git a/test/callStackToNix/test/Spec.hs b/test/callStackToNix/test/Spec.hs new file mode 100644 index 0000000000..cd4753fc9c --- /dev/null +++ b/test/callStackToNix/test/Spec.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "Test suite not yet implemented" diff --git a/test/default.nix b/test/default.nix index 083a0370a7..0789f84ab3 100644 --- a/test/default.nix +++ b/test/default.nix @@ -15,6 +15,7 @@ in { with-packages = haskell.callPackage ./with-packages { inherit util; }; builder-haddock = haskell.callPackage ./builder-haddock {}; stack-simple = haskell.callPackage ./stack-simple {}; + callStackToNix = haskell.callPackage ./callStackToNix {}; # Run unit tests with: nix-instantiate --eval --strict -A unit # An empty list means success. diff --git a/test/tests.sh b/test/tests.sh index 6e28335c73..5ed6fefc68 100755 --- a/test/tests.sh +++ b/test/tests.sh @@ -12,7 +12,7 @@ rm -rvf */cabal.project.local */.ghc.environment* */dist */dist-newstyle */.stac echo >& 2 printf "*** Running the nix-build tests...\n" >& 2 -nix-build $NIX_BUILD_ARGS --no-out-link --keep-going ./default.nix +nix build $NIX_BUILD_ARGS --no-link --keep-going -f ./default.nix echo >& 2 printf "*** Running the unit tests... " >& 2