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

Update to data-fix-0.3 #679

Merged
merged 1 commit into from
Jul 24, 2020
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
14 changes: 14 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,20 @@ let
# require n-i >= 0.4. dontCheck helps us avoid conflicts with
# neat-interpolation's test dependencies.
neat-interpolation = pkgs.haskell.lib.dontCheck super.neat-interpolation_0_5_1;

# 2020-07-23 hnix uses multiple functions that are unavailable in
# data-fix < 0.3.
data-fix = haskellPackages.callPackage
({ mkDerivation, base, deepseq, hashable, stdenv }:
mkDerivation {
pname = "data-fix";
version = "0.3.0";
sha256 = "9e59b3ed694b5139316093b3767842e60ad4821858459e7cd763e5773dfa99a0";
libraryHaskellDepends = [ base deepseq hashable ];
homepage = "https://github.com/spell-music/data-fix";
description = "Fixpoint data types";
license = stdenv.lib.licenses.bsd3;
}) {};
Comment on lines +218 to +228
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I arrived at this setup after a bit of trial and error. If there's a better way to achieve the same, I'd happily use it.

Copy link
Collaborator

@Anton-Latukha Anton-Latukha Jul 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe try haskellPackages.callHackage:

Given example is:

...
foo = self.callHackage "foo" "1.5.3" {};
...

It is much more clear and obvious what it is and does.

It calls official hackage2nix machinery into motion and takes Haskell package and automatically generates Nix Haskell package.

callHackage is wonderful to use in cases when Nixpkgs dodges to follow the upstream Hackage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting an error with this patch:

--- a/default.nix
+++ b/default.nix
@@ -215,17 +215,7 @@ let
 
       # 2020-07-23 hnix uses multiple functions that are unavailable in
       # data-fix < 0.3.
-      data-fix = haskellPackages.callPackage
-       ({ mkDerivation, base, deepseq, hashable, stdenv }:
-        mkDerivation {
-          pname = "data-fix";
-          version = "0.3.0";
-          sha256 = "9e59b3ed694b5139316093b3767842e60ad4821858459e7cd763e5773dfa99a0";
-          libraryHaskellDepends = [ base deepseq hashable ];
-          homepage = "https://github.com/spell-music/data-fix";
-          description = "Fixpoint data types";
-          license = stdenv.lib.licenses.bsd3;
-        }) {};
+      data-fix = haskellPackages.callHackage "data-fix" "0.3.0" {};
     };
$ nix-build --argstr compiler ghc883 --arg buildFromSdist true
building '/nix/store/h8zl5khhsf9x2w86qgqw1f48g2y8fxhv-cabal2nix-hnix.drv'...
installing
building '/nix/store/zknicl0518i1m0sh7f7yfk0dby6dsv3q-all-cabal-hashes-component-data-fix-0.3.0.drv'...
tar: */data-fix/0.3.0/data-fix.json: Not found in archive
tar: */data-fix/0.3.0/data-fix.cabal: Not found in archive
tar: Exiting with failure status due to previous errors
builder for '/nix/store/zknicl0518i1m0sh7f7yfk0dby6dsv3q-all-cabal-hashes-component-data-fix-0.3.0.drv' failed with exit code 2
cannot build derivation '/nix/store/9h8v1aia6ak6fb29ljc356aissz0rzbz-cabal2nix-data-fix-0.3.0.drv': 1 dependencies couldn't be built
error: build of '/nix/store/9h8v1aia6ak6fb29ljc356aissz0rzbz-cabal2nix-data-fix-0.3.0.drv' failed
(use '--show-trace' to show detailed location information)

Any ideas?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, it means that Nixpkgs does not imported/updated Hackage revision information into the system.

Seems like callHackageDirect should be used.

I am looking into it, you also can look into haskell-modules/make-package-set.nix to understand this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like callHackageDirect should be used.

Do you mean this?

--- a/default.nix
+++ b/default.nix
@@ -215,17 +215,11 @@ let
 
       # 2020-07-23 hnix uses multiple functions that are unavailable in
       # data-fix < 0.3.
-      data-fix = haskellPackages.callPackage
-       ({ mkDerivation, base, deepseq, hashable, stdenv }:
-        mkDerivation {
-          pname = "data-fix";
-          version = "0.3.0";
-          sha256 = "9e59b3ed694b5139316093b3767842e60ad4821858459e7cd763e5773dfa99a0";
-          libraryHaskellDepends = [ base deepseq hashable ];
-          homepage = "https://github.com/spell-music/data-fix";
-          description = "Fixpoint data types";
-          license = stdenv.lib.licenses.bsd3;
-        }) {};
+      data-fix = haskellPackages.callHackageDirect {
+        pkg = "data-fix";
+        ver = "0.3.0";
+        sha256 = "9e59b3ed694b5139316093b3767842e60ad4821858459e7cd763e5773dfa99a0";
+      } {};
     };
 
     modifier = drv: pkgs.haskell.lib.overrideCabal drv (attrs: {

That produces a different error:

$ nix-build --argstr compiler ghc883 --arg buildFromSdist true
building '/nix/store/dkf1vxj712fmq58wjl03vw2px39n36dk-cabal2nix-hnix.drv'...
installing
building '/nix/store/widy86ykjxr8mviq5c9kkj4alvcgnq4i-source.drv'...

trying http://hackage.haskell.org/package/data-fix-0.3.0/data-fix-0.3.0.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5516  100  5516    0     0  61977      0 --:--:-- --:--:-- --:--:-- 61288
unpacking source archive /tmp/nix-build-source.drv-0/data-fix-0.3.0.tar.gz
hash mismatch in fixed-output derivation '/nix/store/cg310v82g2pnmi6gyp2dhd544jdnxhcj-source':
  wanted: sha256:184rz8ypgrb3sxy9wiaq321d82p689w7dcwkc0qkjlabd7nv6ncy
  got:    sha256:1w3z4fa28zxqwgsynlz025rkmrdcv7bj66031l502nc3x3yfljn6
cannot build derivation '/nix/store/khmfa7xv97fbziibldgi120dccjfkxqj-cabal2nix-data-fix.drv': 1 dependencies couldn't be built
error: build of '/nix/store/khmfa7xv97fbziibldgi120dccjfkxqj-cabal2nix-data-fix.drv' failed
(use '--show-trace' to show detailed location information)

Copy link
Collaborator

@Anton-Latukha Anton-Latukha Jul 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

      data-fix = haskellPackages.callHackageDirect {
        pkg = "dafa-fix";
        ver = "0.3.0";
        sha256 = "184rz8ypgrb3sxy9wiaq321d82p689w7dcwkc0qkjlabd7nv6ncy";
      };

Did not work, nor self.callHackageDirect.

With cryptic:

building '/nix/store/zk6fk22k39h6nprx99qsmysrgnbhf11i-cabal2nix-hnix.drv'...
installing
error: 'callHackageDirect' at /nix/store/5cbvaaalcqj2cczgvp122h4w2sms79jn-nixos-20.09pre235279.5717d9d2f7c/nixos/pkgs/development/haskell-modules/make-package-set.nix:193:25 called with unexpected argument 'pname', at /home/pyro/src/haskell/hnix/default.nix:218:18
(use '--show-trace' to show detailed location information)

We can develop override to more modern Hackage etc.

Lets do not get in the weeds further for this.


At this point I think - lets merge it as you presented it working, and move forward - it is a temporary change and we can and would rehash it in any case.

};

modifier = drv: pkgs.haskell.lib.overrideCabal drv (attrs: {
Expand Down
2 changes: 1 addition & 1 deletion hnix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ library
, bytestring >= 0.10.8 && < 0.11
, comonad >= 5.0.4 && < 5.1
, containers >= 0.5.11.0 && < 0.7
, data-fix >= 0.2.0 && < 0.3
, data-fix >= 0.3.0 && < 0.4
, deepseq >= 1.4.3 && <1.5
, deriving-compat >= 0.3 && < 0.6
, directory >= 1.3.1 && < 1.4
Expand Down
4 changes: 2 additions & 2 deletions src/Nix/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Data.ByteString ( ByteString )
import qualified Data.ByteString as B
import Data.ByteString.Base16 as Base16
import Data.Char ( isDigit )
import Data.Fix ( cata )
import Data.Fix ( foldFix )
import Data.Foldable ( foldrM )
import qualified Data.HashMap.Lazy as M
import Data.List
Expand Down Expand Up @@ -196,7 +196,7 @@ builtinsList = sequence
outputsList = map outputToAttrListElement outputs;

in (builtins.head outputsList).value|]
[| cata Eval.eval expr |]
[| foldFix Eval.eval expr |]
)

, add TopLevel "derivationStrict" derivationStrict_
Expand Down
8 changes: 2 additions & 6 deletions src/Nix/Expr/Types/Annotated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Data.Aeson.TH
import Data.Binary ( Binary(..) )
import Data.Data
import Data.Eq.Deriving
import Data.Fix
import Data.Fix ( Fix(..), unfoldFix )
import Data.Function ( on )
import Data.Functor.Compose
import Data.Hashable
Expand Down Expand Up @@ -108,14 +108,10 @@ type NExprLocF = AnnF SrcSpan NExprF
-- | A nix expression with source location at each subexpression.
type NExprLoc = Fix NExprLocF

instance NFData NExprLoc

#ifdef MIN_VERSION_serialise
instance Serialise NExprLoc
#endif

instance Hashable NExprLoc

instance Binary SrcSpan
instance (Binary ann, Binary a) => Binary (Ann ann a)
instance Binary r => Binary (NExprLocF r)
Expand All @@ -135,7 +131,7 @@ pattern AnnE :: forall ann (g :: * -> *). ann
pattern AnnE ann a = Fix (Compose (Ann ann a))

stripAnnotation :: Functor f => Fix (AnnF ann f) -> Fix f
stripAnnotation = ana (annotated . getCompose . unFix)
stripAnnotation = unfoldFix (annotated . getCompose . unFix)

stripAnn :: AnnF ann f r -> f r
stripAnn = annotated . getCompose
Expand Down
4 changes: 2 additions & 2 deletions src/Nix/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Nix.Pretty where
import Control.Applicative ( (<|>) )
import Control.Comonad
import Control.Monad.Free
import Data.Fix
import Data.Fix ( Fix(..), foldFix )
import Data.HashMap.Lazy ( toList )
import qualified Data.HashMap.Lazy as M
import qualified Data.HashSet as HashSet
Expand Down Expand Up @@ -190,7 +190,7 @@ prettyAtom :: NAtom -> NixDoc ann
prettyAtom atom = simpleExpr $ pretty $ unpack $ atomText atom

prettyNix :: NExpr -> Doc ann
prettyNix = withoutParens . cata exprFNixDoc
prettyNix = withoutParens . foldFix exprFNixDoc

instance HasCitations1 m v f
=> HasCitations m v (NValue' t f m a) where
Expand Down
18 changes: 9 additions & 9 deletions src/Nix/Reduce.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Reader
import Control.Monad.State.Strict
import Data.Fix
import Data.Fix ( Fix(..), foldFix, foldFixM )
-- import Data.Foldable
import Data.HashMap.Lazy ( HashMap )
import qualified Data.HashMap.Lazy as M
Expand Down Expand Up @@ -117,12 +117,12 @@ staticImport pann path = do
x' = Fix (NLet_ span [cur] x)
modify (M.insert path x')
local (const (Just path, emptyScopes @m @NExprLoc)) $ do
x'' <- cata reduce x'
x'' <- foldFix reduce x'
modify (M.insert path x'')
return x''

-- gatherNames :: NExprLoc -> HashSet VarName
-- gatherNames = cata $ \case
-- gatherNames = foldFix $ \case
-- NSym_ _ var -> S.singleton var
-- Compose (Ann _ x) -> fold x

Expand All @@ -132,7 +132,7 @@ reduceExpr mpath expr =
(`evalStateT` M.empty)
. (`runReaderT` (mpath, emptyScopes))
. runReducer
$ cata reduce expr
$ foldFix reduce expr

reduce
:: forall m
Expand Down Expand Up @@ -173,7 +173,7 @@ reduce (NBinary_ bann NApp fun arg) = fun >>= \case

Fix (NAbs_ _ (Param name) body) -> do
x <- arg
pushScope (M.singleton name x) (cata reduce body)
pushScope (M.singleton name x) (foldFix reduce body)

f -> Fix . NBinary_ bann NApp f <$> arg

Expand Down Expand Up @@ -299,15 +299,15 @@ instance Show (f r) => Show (FlaggedF f r) where
type Flagged f = Fix (FlaggedF f)

flagExprLoc :: (MonadIO n, Traversable f) => Fix f -> n (Flagged f)
flagExprLoc = cataM $ \x -> do
flagExprLoc = foldFixM $ \x -> do
flag <- liftIO $ newIORef False
pure $ Fix $ FlaggedF (flag, x)

-- stripFlags :: Functor f => Flagged f -> Fix f
-- stripFlags = cata $ Fix . snd . flagged
-- stripFlags = foldFix $ Fix . snd . flagged

pruneTree :: MonadIO n => Options -> Flagged NExprLocF -> n (Maybe NExprLoc)
pruneTree opts = cataM $ \(FlaggedF (b, Compose x)) -> do
pruneTree opts = foldFixM $ \(FlaggedF (b, Compose x)) -> do
used <- liftIO $ readIORef b
pure $ if used then Fix . Compose <$> traverse prune x else Nothing
where
Expand Down Expand Up @@ -414,7 +414,7 @@ reducingEvalExpr
-> m (NExprLoc, Either r a)
reducingEvalExpr eval mpath expr = do
expr' <- flagExprLoc =<< liftIO (reduceExpr mpath expr)
eres <- catch (Right <$> cata (addEvalFlags eval) expr') (pure . Left)
eres <- catch (Right <$> foldFix (addEvalFlags eval) expr') (pure . Left)
opts :: Options <- asks (view hasLens)
expr'' <- pruneTree opts expr'
return (fromMaybe nNull expr'', eres)
Expand Down
4 changes: 2 additions & 2 deletions src/Nix/Type/Infer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Control.Monad.Reader
import Control.Monad.Ref
import Control.Monad.ST
import Control.Monad.State.Strict
import Data.Fix ( cata )
import Data.Fix ( foldFix )
import Data.Foldable
import qualified Data.HashMap.Lazy as M
import Data.List ( delete
Expand Down Expand Up @@ -564,7 +564,7 @@ instance MonadInfer m => ToValue Bool (InferT s m) (Judgment s) where
toValue _ = pure $ Judgment As.empty [] typeBool

infer :: MonadInfer m => NExpr -> InferT s m (Judgment s)
infer = cata Eval.eval
infer = foldFix Eval.eval

inferTop :: Env -> [(Text, NExpr)] -> Either InferError Env
inferTop env [] = Right env
Expand Down
2 changes: 1 addition & 1 deletion tests/PrettyParseTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ equivUpToNormalization :: NExpr -> NExpr -> Bool
equivUpToNormalization x y = normalize x == normalize y

normalize :: NExpr -> NExpr
normalize = cata $ \case
normalize = foldFix $ \case
NConstant (NInt n) | n < 0 ->
Fix (NUnary NNeg (Fix (NConstant (NInt (negate n)))))
NConstant (NFloat n) | n < 0 ->
Expand Down