mirror of
https://github.com/ilyakooo0/haskell.nix.git
synced 2024-09-11 06:55:40 +03:00
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 ```
This commit is contained in:
parent
072debc663
commit
390771849a
20
call-stack-to-nix.nix
Normal file
20
call-stack-to-nix.nix
Normal file
@ -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
|
@ -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.
|
||||
|
3
test/callStackToNix/.gitignore
vendored
Normal file
3
test/callStackToNix/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.stack-work/
|
||||
stack-simple.cabal
|
||||
*~
|
2
test/callStackToNix/Setup.hs
Normal file
2
test/callStackToNix/Setup.hs
Normal file
@ -0,0 +1,2 @@
|
||||
import Distribution.Simple
|
||||
main = defaultMain
|
6
test/callStackToNix/app/Main.hs
Normal file
6
test/callStackToNix/app/Main.hs
Normal file
@ -0,0 +1,6 @@
|
||||
module Main where
|
||||
|
||||
import Lib
|
||||
|
||||
main :: IO ()
|
||||
main = someFunc
|
33
test/callStackToNix/default.nix
Normal file
33
test/callStackToNix/default.nix
Normal file
@ -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
test/callStackToNix/package.yaml
Normal file
48
test/callStackToNix/package.yaml
Normal file
@ -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 <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
test/callStackToNix/src/Lib.hs
Normal file
6
test/callStackToNix/src/Lib.hs
Normal file
@ -0,0 +1,6 @@
|
||||
module Lib
|
||||
( someFunc
|
||||
) where
|
||||
|
||||
someFunc :: IO ()
|
||||
someFunc = putStrLn "someFunc"
|
66
test/callStackToNix/stack.yaml
Normal file
66
test/callStackToNix/stack.yaml
Normal file
@ -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
test/callStackToNix/test/Spec.hs
Normal file
2
test/callStackToNix/test/Spec.hs
Normal file
@ -0,0 +1,2 @@
|
||||
main :: IO ()
|
||||
main = putStrLn "Test suite not yet implemented"
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user