Skip to content

Commit b89beea

Browse files
authored
Use latest nixpkgs (#131)
* add some macros to conditionally skip dropSuffix * explicitly import Control.Monad.Catch
1 parent d3247a7 commit b89beea

File tree

7 files changed

+59
-27
lines changed

7 files changed

+59
-27
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<version: 2
1+
version: 2
22
jobs:
33
build:
44
docker:

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ $ nix-shell
6666
[nix-shell:nixfromnpm]$ cabal run -- <arguments>
6767
```
6868

69+
#### Customizing `nixpkgs` and GHC versions
70+
71+
By default, we pin the version of `nixpkgs` in order to maintain a
72+
reliable build. However, if you'd like to build off of `nixpkgs` in
73+
your `NIX_PATH` or some other custom location:
74+
75+
```bash
76+
$ nix-env -f release.nix -iA nixfromnpm --arg nixpkgs '<nixpkgs>'
77+
```
78+
79+
The GHC version can also be set explicitly, although of course, the
80+
package is not guaranteed to build with any arbitrary GHC version:
81+
82+
```bash
83+
$ nix-env -f release.nix -iA nixfromnpm --argstr compiler ghc802
84+
```
85+
86+
Note that the above options also apply to `nix-build`, `nix-shell`, etc.
87+
6988
### Usage
7089

7190
#### Using the `nix-node-packages` repo

default.nix

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
{ mkDerivation, aeson, ansi-terminal, base, bytestring
22
, classy-prelude, containers, curl, data-default, data-fix
3-
, directory, hnix, hspec, lifted-base, MissingH, monad-control, mtl
3+
, directory, exceptions, hnix, hspec, lifted-base, MissingH
4+
, monad-control, mono-traversable, mtl, neat-interpolation
45
, network-uri, optparse-applicative, parsec, pcre-heavy, QuickCheck
56
, semver-range, SHA, shelly, stdenv, system-filepath, temporary
67
, text, text-render, transformers, unix, unordered-containers
7-
, neat-interpolation
88
}:
99
mkDerivation {
1010
pname = "nixfromnpm";
1111
version = "0.13.0";
1212
src = ./.;
1313
isLibrary = true;
1414
isExecutable = true;
15+
enableSeparateDataOutput = true;
1516
libraryHaskellDepends = [
1617
aeson ansi-terminal base bytestring classy-prelude containers curl
17-
data-default data-fix directory hnix lifted-base MissingH
18-
monad-control mtl network-uri optparse-applicative parsec
19-
pcre-heavy semver-range SHA shelly system-filepath temporary text
20-
text-render transformers unix unordered-containers
21-
];
22-
executableHaskellDepends = [
23-
aeson ansi-terminal base bytestring classy-prelude containers curl
24-
data-default data-fix directory hnix lifted-base MissingH
25-
monad-control mtl network-uri optparse-applicative parsec
26-
pcre-heavy semver-range SHA shelly system-filepath temporary text
27-
text-render transformers unix unordered-containers
18+
data-default data-fix directory exceptions hnix lifted-base
19+
MissingH monad-control mono-traversable mtl network-uri
20+
optparse-applicative parsec pcre-heavy semver-range SHA shelly
21+
system-filepath temporary text text-render transformers unix
22+
unordered-containers
2823
];
24+
executableHaskellDepends = [ base optparse-applicative ];
2925
testHaskellDepends = [
30-
aeson ansi-terminal base bytestring classy-prelude containers curl
31-
data-default data-fix directory hnix hspec lifted-base MissingH
32-
monad-control mtl network-uri optparse-applicative parsec
33-
pcre-heavy QuickCheck semver-range SHA shelly system-filepath
34-
temporary text text-render transformers unix unordered-containers
35-
neat-interpolation
26+
aeson base bytestring classy-prelude hnix hspec mono-traversable
27+
neat-interpolation QuickCheck text
3628
];
3729
description = "Generate nix expressions from npm packages";
3830
license = stdenv.lib.licenses.mit;

nixfromnpm.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ library
4747
, NixFromNpm.Options
4848
other-modules: Filesystem.Path.Wrappers
4949
, NixFromNpm.HttpTools
50+
, NixFromNpm.Merge
5051
, NixFromNpm.Npm.Resolve
5152
, Paths_nixfromnpm
5253
other-extensions: NoImplicitPrelude
5354
build-depends: base >=4.8 && < 5.0
5455
, classy-prelude
56+
, mono-traversable
5557
, text
5658
, bytestring
5759
, mtl
@@ -79,6 +81,7 @@ library
7981
, semver-range >=0.2.7
8082
, data-fix
8183
, pcre-heavy
84+
, exceptions
8285
default-language: Haskell2010
8386

8487
executable nixfromnpm
@@ -98,6 +101,7 @@ test-suite unit-tests
98101
, OverloadedStrings
99102
build-depends: base >=4.8 && < 5.0
100103
, classy-prelude
104+
, mono-traversable
101105
, aeson
102106
, bytestring
103107
, hnix

release.nix

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
{ nixpkgs ? (import ./nix/17_09.nix) }:
1+
{
2+
nixpkgs ? import ./nix/17_09.nix,
3+
compiler ? null,
4+
}:
25
let
3-
46
config = { allowUnfree = true; };
57

68
overlays = [
7-
(newPkgs: oldPkgs: {
9+
(newPkgs: oldPkgs: rec {
810

9-
haskellPackages = oldPkgs.haskellPackages.override {
11+
origHaskellPackages = if compiler == null then oldPkgs.haskellPackages
12+
else oldPkgs.haskell.packages."${compiler}";
13+
haskellPackages = origHaskellPackages.override {
1014
overrides = haskellPackagesNew: haskellPackagesOld:
1115
{ semver-range =
1216
haskellPackagesNew.callPackage ./nix/semver-range.nix { };

shell.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
args@{...}: (import ./release.nix args).nixfromnpm.env
1+
{
2+
nixpkgs ? import ./nix/17_09.nix,
3+
compiler ? null
4+
}:
5+
(import ./release.nix {inherit nixpkgs compiler;}).nixfromnpm.env

src/NixFromNpm/Common.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE LambdaCase #-}
2+
{-# LANGUAGE CPP #-}
23
{-# LANGUAGE OverloadedStrings #-}
34
{-# LANGUAGE NoMonomorphismRestriction #-}
45
{-# LANGUAGE FlexibleContexts #-}
@@ -12,6 +13,7 @@ module NixFromNpm.Common (
1213
module Control.Applicative,
1314
module Control.Exception.Lifted,
1415
module Control.Monad,
16+
module Control.Monad.Catch,
1517
module Control.Monad.Except,
1618
module Control.Monad.Identity,
1719
module Control.Monad.Reader,
@@ -35,19 +37,24 @@ module NixFromNpm.Common (
3537
module Control.Monad.Trans.Control,
3638
module System.Console.ANSI,
3739
Name, AuthToken, Record, (//), (<>),
38-
uriToText, uriToString, putStrsLn, putStrs, dropSuffix, maybeIf, failC,
40+
uriToText, uriToString, putStrsLn, putStrs, maybeIf, failC,
3941
errorC, joinBy, mapJoinBy, getEnv, modifyMap, unsafeParseURI,
4042
parseURIText, withColor, withUL, warn, warns, assert, fatal, fatalC,
4143
partitionEither, throw, eitherToMaybe
44+
#if !MIN_VERSION_mono_traversable(1,0,7)
45+
, dropSuffix
46+
#endif
4247
) where
4348

4449
import ClassyPrelude hiding (assert, asList, find, FilePath, bracket,
4550
maximum, maximumBy, (</>), (<>),
4651
minimum, try, stripPrefix, ioError,
4752
mapM_, sequence_, foldM, forM_, throw, throwIO,
4853
filterM, replicateM, writeFile, readFile,
49-
writeFileUtf8, readFileUtf8)
54+
writeFileUtf8, readFileUtf8, catch, catches,
55+
Handler)
5056
import Control.Exception (throw)
57+
import Control.Monad.Catch (catch, catches, Handler(..))
5158
import qualified Prelude as P
5259
import Control.Monad.RWS.Strict hiding (Any, (<>))
5360
import Control.Monad (when)
@@ -141,11 +148,13 @@ putStrsLn = putStrLn . concat
141148
putStrs :: MonadIO m => [Text] -> m ()
142149
putStrs = putStr . concat
143150

151+
#if !MIN_VERSION_mono_traversable(1,0,7)
144152
-- | Strip the given suffix from the given string.
145153
dropSuffix :: Text -> Text -> Text
146154
dropSuffix suffix input = case T.stripSuffix suffix input of
147155
Nothing -> input
148156
Just stripped -> stripped
157+
#endif
149158

150159
-- | Return a Just value if the argument is True, else Nothing.
151160
maybeIf :: Bool -> a -> Maybe a

0 commit comments

Comments
 (0)