Skip to content
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

Fixes for hnix 0.16 #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions yarn2nix/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ dependencies:
- aeson-better-errors >= 0.9.1.1
- async-pool == 0.9.*
- base == 4.*
- bytestring == 0.10.*
- bytestring >= 0.10 && < 0.12
- containers >= 0.5 && < 0.7
- data-fix >= 0.0.7 && < 0.4
- directory == 1.3.*
- filepath == 1.4.*
- hnix >= 0.6 && < 0.15
- hnix >= 0.6 && < 0.17
- mtl == 2.2.*
- prettyprinter >= 1.2 && < 1.8
- process >= 1.4
Expand All @@ -39,7 +39,7 @@ dependencies:
- transformers == 0.5.*
- unordered-containers == 0.2.*
- yarn-lock == 0.6.*
- optparse-applicative >= 0.16 && < 0.17
- optparse-applicative >= 0.16 && < 0.18

library:
source-dirs: src
Expand Down
4 changes: 3 additions & 1 deletion yarn2nix/src/Distribution/Nixpkgs/Nodejs/FromPackage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Distribution.Nixpkgs.Nodejs.FromPackage

import Protolude

import Data.Coerce (coerce)

import Nix.Expr
import Nix.Expr.Additions

Expand Down Expand Up @@ -35,7 +37,7 @@ genTemplate :: Maybe NL.LicensesBySpdxId -> NP.Package -> NExpr
genTemplate licSet NP.Package{..} =
-- reserved for possible future arguments (to prevent breakage)
simpleParamSet []
==> Param nodeDepsSym
==> Param (coerce nodeDepsSym)
==> (mkNonRecSet
[ "key" $= packageKeyToSet (NP.parsePackageKeyName name)
, "version" $= mkStr version
Expand Down
18 changes: 14 additions & 4 deletions yarn2nix/src/Nix/Expr/Additions.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE TupleSections, OverloadedStrings #-}
{-# LANGUAGE TupleSections, OverloadedStrings, CPP #-}
{-|
Description: Additional functions that should probably be in @hnix@

Expand All @@ -11,6 +11,7 @@ module Nix.Expr.Additions
, StrQ(..), mkStrQ, mkStrQI
) where

import Data.Coerce (coerce)
import Data.Fix (Fix(..))
import Data.Text (Text)
import Data.String (IsString(..))
Expand All @@ -36,25 +37,34 @@ dynamicKey k = DynamicKey $ Plain $ DoubleQuoted [Plain k]

-- | Inherit the given list of symbols.
inheritStatic :: [Text] -> Binding e
#if MIN_VERSION_hnix(0,16,0)
inheritStatic = inherit . coerce
#else
inheritStatic names = inherit (map StaticKey names) nullPos
#endif

-- | shortcut to create a list of closed params, like @{ foo, bar, baz }:@
simpleParamSet :: [Text] -> Params NExpr
simpleParamSet prms = mkParamset (fmap (, Nothing) prms) False

-- | shortcut to create a list of multiple params, like @a: b: c:@
multiParam :: [Text] -> NExpr -> NExpr
multiParam ps expr = foldr mkFunction expr $ map Param ps
multiParam ps expr = foldr mkFunction expr $ map (Param . coerce) ps

-- TODO: switch over to !. when
-- https://github.com/jwiegley/hnix/commit/8b4c137a3b125f52bb78039a9d201492032b38e8
-- goes upstream
-- | Like '!.', but automatically convert plain strings to static keys.
(!!.) :: NExpr -> Text -> NExpr
aset !!. k = Fix
$ NSelect aset
(pure $ (if isPlainSymbol k then StaticKey else dynamicKey) k) Nothing
$ mkNSelect aset
(pure $ (if isPlainSymbol k then StaticKey . coerce else dynamicKey) k)
where
#if MIN_VERSION_hnix(0,16,0)
mkNSelect a b = NSelect Nothing a b
#else
mkNSelect a b = NSelect a b Nothing
#endif
-- the nix lexer regex for IDs (symbols) is
-- [a-zA-Z\_][a-zA-Z0-9\_\'\-]*
isPlainSymbol :: Text -> Bool
Expand Down
22 changes: 11 additions & 11 deletions yarn2nix/yarn2nix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ library
, aeson-better-errors >=0.9.1.1
, async-pool ==0.9.*
, base ==4.*
, bytestring ==0.10.*
, bytestring >=0.10 && <0.12
, containers >=0.5 && <0.7
, data-fix >=0.0.7 && <0.4
, directory ==1.3.*
, filepath ==1.4.*
, hnix >=0.6 && <0.15
, hnix >=0.6 && <0.17
, mtl ==2.2.*
, optparse-applicative ==0.16.*
, optparse-applicative >=0.16 && <0.18
, prettyprinter >=1.2 && <1.8
, process >=1.4
, protolude ==0.3.*
Expand All @@ -76,12 +76,12 @@ executable node-package-tool
, aeson-better-errors >=0.9.1.1
, async-pool ==0.9.*
, base ==4.*
, bytestring ==0.10.*
, bytestring >=0.10 && <0.12
, containers >=0.5 && <0.7
, data-fix >=0.0.7 && <0.4
, directory ==1.3.*
, filepath ==1.4.*
, hnix >=0.6 && <0.15
, hnix >=0.6 && <0.17
, mtl ==2.2.*
, optparse-applicative >=0.13
, prettyprinter >=1.2 && <1.8
Expand All @@ -108,14 +108,14 @@ executable yarn2nix
, aeson-better-errors >=0.9.1.1
, async-pool ==0.9.*
, base ==4.*
, bytestring ==0.10.*
, bytestring >=0.10 && <0.12
, containers >=0.5 && <0.7
, data-fix >=0.0.7 && <0.4
, directory ==1.3.*
, filepath ==1.4.*
, hnix >=0.6 && <0.15
, hnix >=0.6 && <0.17
, mtl ==2.2.*
, optparse-applicative ==0.16.*
, optparse-applicative >=0.16 && <0.18
, prettyprinter >=1.2 && <1.8
, process >=1.4
, protolude ==0.3.*
Expand Down Expand Up @@ -143,15 +143,15 @@ test-suite yarn2nix-tests
, aeson-better-errors >=0.9.1.1
, async-pool ==0.9.*
, base ==4.*
, bytestring ==0.10.*
, bytestring >=0.10 && <0.12
, containers >=0.5 && <0.7
, data-fix >=0.0.7 && <0.4
, directory ==1.3.*
, filepath ==1.4.*
, hnix >=0.6 && <0.15
, hnix >=0.6 && <0.17
, mtl ==2.2.*
, neat-interpolation >=0.3 && <0.6
, optparse-applicative ==0.16.*
, optparse-applicative >=0.16 && <0.18
, prettyprinter >=1.2 && <1.8
, process >=1.4
, protolude ==0.3.*
Expand Down