From 18d2688e73a7e0796b5c60cac58c53bd300f1936 Mon Sep 17 00:00:00 2001 From: Tony Morris Date: Wed, 4 Apr 2018 12:16:48 +1000 Subject: [PATCH] nix --- Setup.hs | 2 ++ Setup.lhs | 44 ------------------------------------------ default.nix | 26 +++++++++++++++++++++++++ lets-lens.cabal | 12 +++++------- lets-lens.nix | 15 +++++++++++++++ shell.nix | 7 +++++++ test/.gitignore | 8 -------- test/Tests.hs | 4 ++++ test/doctests.hs | 50 ------------------------------------------------ 9 files changed, 59 insertions(+), 109 deletions(-) create mode 100644 Setup.hs delete mode 100644 Setup.lhs create mode 100644 default.nix create mode 100644 lets-lens.nix create mode 100644 shell.nix delete mode 100644 test/.gitignore create mode 100644 test/Tests.hs delete mode 100644 test/doctests.hs diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/Setup.lhs b/Setup.lhs deleted file mode 100644 index 0832aa5..0000000 --- a/Setup.lhs +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env runhaskell -\begin{code} -{-# OPTIONS_GHC -Wall #-} -module Main (main) where - -import Data.List ( nub ) -import Data.Version ( showVersion ) -import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName ) -import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) ) -import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks ) -import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose ) -import Distribution.Simple.BuildPaths ( autogenModulesDir ) -import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag ) -import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) ) -import Distribution.Verbosity ( Verbosity ) -import System.FilePath ( () ) - -main :: IO () -main = defaultMainWithHooks simpleUserHooks - { buildHook = \pkg lbi hooks flags -> do - generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi - buildHook simpleUserHooks pkg lbi hooks flags - } - -generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO () -generateBuildModule verbosity pkg lbi = do - let dir = autogenModulesDir lbi - createDirectoryIfMissingVerbose verbosity True dir - withLibLBI pkg lbi $ \_ libcfg -> do - withTestLBI pkg lbi $ \suite suitecfg -> do - rewriteFile (dir "Build_" ++ testName suite ++ ".hs") $ unlines - [ "module Build_" ++ testName suite ++ " where" - , "deps :: [String]" - , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg)) - ] - where - formatdeps = map (formatone . snd) - formatone p = case packageName p of - PackageName n -> n ++ "-" ++ showVersion (packageVersion p) - -testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)] -testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys - -\end{code} diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..54ad6c4 --- /dev/null +++ b/default.nix @@ -0,0 +1,26 @@ +{ nixpkgs ? import {}, compiler ? "default" }: +let + inherit (nixpkgs) pkgs; + haskellPackages = if compiler == "default" + then pkgs.haskellPackages + else pkgs.haskell.packages.${compiler}; + + tasty-hedgehog-github = pkgs.callPackage (pkgs.fetchFromGitHub { + owner = "qfpl"; + repo = "tasty-hedgehog"; + rev = "5da389f5534943b430300a213c5ffb5d0e13459e"; + sha256 = "04pmr9q70gakd327sywpxr7qp8jnl3b0y2sqxxxcj6zj2q45q38m"; + }) {}; + + modifiedHaskellPackages = haskellPackages.override { + overrides = self: super: { + tasty-hedgehog = + if super ? tasty-hedgehog + then super.tasty-hedgehog + else tasty-hedgehog-github; + }; + }; + + lets-lens = modifiedHaskellPackages.callPackage ./lets-lens.nix {}; +in + lets-lens diff --git a/lets-lens.cabal b/lets-lens.cabal index 367cead..8297bcd 100644 --- a/lets-lens.cabal +++ b/lets-lens.cabal @@ -4,14 +4,15 @@ license: BSD3 license-file: LICENCE author: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> maintainer: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> -copyright: Copyright (C) 2015 National ICT Australia Limited +copyright: Copyright (C) 2015-2016 National ICT Australia Limited +copyright: Copyright (c) 2018, Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230. synopsis: Source code for exercises on the lens concept category: Education description: Source code for exercises on the lens concept homepage: https://github.com/data61/lets-lens bug-reports: https://github.com/data61/lets-lens/issues cabal-version: >= 1.10 -build-type: Custom +build-type: Simple extra-source-files: changelog source-repository head @@ -24,12 +25,9 @@ flag small_base library default-language: Haskell2010 - build-depends: base < 5 && >= 4 - , QuickCheck >= 2.0 - , doctest >= 0.9.7 + build-depends: base >= 4.8 && < 5 , containers >= 0.4.0.0 - , array >= 0.4 - + ghc-options: -Wall -fno-warn-unused-binds -fno-warn-unused-do-bind diff --git a/lets-lens.nix b/lets-lens.nix new file mode 100644 index 0000000..315ac99 --- /dev/null +++ b/lets-lens.nix @@ -0,0 +1,15 @@ +{ mkDerivation, base, containers, directory, doctest, filepath +, QuickCheck, stdenv, template-haskell +}: +mkDerivation { + pname = "lets-lens"; + version = "0.0.1"; + src = ./.; + libraryHaskellDepends = [ base containers ]; + testHaskellDepends = [ + base directory doctest filepath QuickCheck template-haskell + ]; + homepage = "https://github.com/data61/lets-lens"; + description = "Source code for exercises on the lens concept"; + license = stdenv.lib.licenses.bsd3; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..3d41767 --- /dev/null +++ b/shell.nix @@ -0,0 +1,7 @@ +{ nixpkgs ? import {}, compiler ? "default" }: +let + inherit (nixpkgs) pkgs; + drv = import ./default.nix { inherit nixpkgs compiler; }; + drvWithTools = pkgs.haskell.lib.addBuildDepends drv [ pkgs.cabal-install ]; +in + if pkgs.lib.inNixShell then drvWithTools.env else drvWithTools diff --git a/test/.gitignore b/test/.gitignore deleted file mode 100644 index 4c8920a..0000000 --- a/test/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# cabal -/dist - -# cabal-dev -/cabal-dev - -# Haskell Program Coverage -/.hpc diff --git a/test/Tests.hs b/test/Tests.hs new file mode 100644 index 0000000..89ad4b3 --- /dev/null +++ b/test/Tests.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = pure () diff --git a/test/doctests.hs b/test/doctests.hs deleted file mode 100644 index dfa08a8..0000000 --- a/test/doctests.hs +++ /dev/null @@ -1,50 +0,0 @@ -{-# LANGUAGE CPP #-} - -module Main where - -import Build_doctests (deps) -#if (__GLASGOW_HASKELL__ < 710) -import Control.Applicative -#endif -import Control.Monad -import Data.List -import System.Directory -import System.FilePath -import Test.DocTest - -main :: - IO () -main = - getSources >>= \sources -> doctest $ - "-isrc" - : "-idist/build/autogen" - : "-optP-include" - : "-optPdist/build/autogen/cabal_macros.h" - : "-hide-all-packages" - : map ("-package="++) deps ++ sources - -sourceDirectories :: - [FilePath] -sourceDirectories = - [ - "src" - ] - -isSourceFile :: - FilePath - -> Bool -isSourceFile p = - and [takeFileName p /= "Setup.hs", isSuffixOf ".hs" p] - -getSources :: IO [FilePath] -getSources = - liftM (filter isSourceFile . concat) (mapM go sourceDirectories) - where - go dir = do - (dirs, files) <- getFilesAndDirectories dir - (files ++) . concat <$> mapM go dirs - -getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath]) -getFilesAndDirectories dir = do - c <- map (dir ) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir - (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c