Skip to content

Add callStackToNix function #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions call-stack-to-nix.nix
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions test/callStackToNix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.stack-work/
stack-simple.cabal
*~
2 changes: 2 additions & 0 deletions test/callStackToNix/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
6 changes: 6 additions & 0 deletions test/callStackToNix/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = someFunc
33 changes: 33 additions & 0 deletions test/callStackToNix/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
48 changes: 48 additions & 0 deletions test/callStackToNix/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: stack-simple
version: 0.1.0.0
github: "githubuser/stack-simple"
license: BSD3
author: "Author name here"
maintainer: "[email protected]"
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 <https://github.com/githubuser/stack-simple#readme>

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
6 changes: 6 additions & 0 deletions test/callStackToNix/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Lib
( someFunc
) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"
66 changes: 66 additions & 0 deletions test/callStackToNix/stack.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/callStackToNix/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"
1 change: 1 addition & 0 deletions test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down