hnix 0.11.0 → 0.11.1
raw patch · 9 files changed
+73/−48 lines, 9 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Nix.Utils: infixl 6 +
+ Nix.Utils: infixl 6 -
- Nix.Utils: seq :: forall (r :: RuntimeRep) a (b :: TYPE r). a -> b -> b
+ Nix.Utils: seq :: a -> b -> b
Files
- CHANGELOG.md +12/−0
- hnix.cabal +1/−1
- src/Nix/Builtins.hs +37/−22
- src/Nix/Effects.hs +1/−1
- src/Nix/Effects/Basic.hs +15/−15
- src/Nix/Exec.hs +2/−5
- src/Nix/Parser.hs +2/−2
- src/Nix/Render.hs +3/−0
- src/Nix/Thunk/Basic.hs +0/−2
CHANGELOG.md view
@@ -1,6 +1,18 @@ # Changelog +## [(diff)](https://github.com/haskell-nix/hnix/compare/0.11.0...master#files_bucket) Progress++### [(diff)](https://github.com/haskell-nix/hnix/compare/0.11.0...0.11.1#files_bucket) 0.11.1 (2020-12-09)++* Additional:+ * [(link)](https://github.com/haskell-nix/hnix/commit/d32a6fbaf3df1c8879d1b19a18f21c031a73e56c) `Nix/Builtins`: `isString` fixed - It used to return `True` for values coercible to string like derivations and paths. It only accepts string values now.+ * [(link)](https://github.com/haskell-nix/hnix/commit/53b4db2525a8f074d8c262fa7b66ce97e5820890) `Nix/Builtins`: `substring` fixed - Negative lengths used to capture an empty string. Now they capture the whole rmeainder of the string.+ * [(link)](https://github.com/haskell-nix/hnix/commit/dc31c5e64f8c7aaaea14cac0134bd47544533e67) `Nix/Effects`: `pathExists` fixed - Now also works with directories.+ * [(link)](https://github.com/haskell-nix/hnix/commit/e2ad934492eeac9881527610e4a1c1cf31ea1115) `Nix/Parser`: `->` is now properly right-associative (was non-associative).+ * [(link)](https://github.com/haskell-nix/hnix/commit/50baea5e1e482be3c4fcc13c9a45b1083243f681) `Nix/Parser`: Nix `assert` parser (`nixAssert` function) now accepts top-level Nix format also (which means also accepts all kinds of statements), before that it accepted only regular Nix expressions.+ * [(link)](https://github.com/haskell-nix/hnix/commit/59698de7185dfae508e5ccea4377a82023c4a0d5) `Nix/Render`: `renderLocation` now also shows/handles location of errors in raw strings.+ ## [(diff)](https://github.com/haskell-nix/hnix/compare/0.10.1...0.11.0#files_bucket) 0.11.0 (2020-11-02)
hnix.cabal view
@@ -1,5 +1,5 @@ name: hnix-version: 0.11.0+version: 0.11.1 synopsis: Haskell implementation of the Nix language description: Haskell implementation of the Nix language. category: System, Data, Nix
src/Nix/Builtins.hs view
@@ -145,18 +145,19 @@ version <- toValue (5 :: Int) pure $ Builtin Normal ("langVersion", version) - , add0 Normal "nixPath" nixPath , add TopLevel "abort" throw_ -- for now , add2 Normal "add" add_ , add2 Normal "addErrorContext" addErrorContext , add2 Normal "all" all_ , add2 Normal "any" any_+ , add2 Normal "appendContext" appendContext , add Normal "attrNames" attrNames , add Normal "attrValues" attrValues , add TopLevel "baseNameOf" baseNameOf , add2 Normal "bitAnd" bitAnd , add2 Normal "bitOr" bitOr , add2 Normal "bitXor" bitXor+ , add0 Normal "builtins" builtinsBuiltin , add2 Normal "catAttrs" catAttrs , add2 Normal "compareVersions" compareVersions_ , add Normal "concatLists" concatLists@@ -205,15 +206,21 @@ , add2 Normal "elemAt" elemAt_ , add Normal "exec" exec_ , add0 Normal "false" (pure $ nvConstant $ NBool False)+ --, add Normal "fetchGit" fetchGit+ --, add Normal "fetchMercurial" fetchMercurial , add Normal "fetchTarball" fetchTarball , add Normal "fetchurl" fetchurl , add2 Normal "filter" filter_+ --, add Normal "filterSource" filterSource+ , add2 Normal "findFile" findFile_ , add3 Normal "foldl'" foldl'_ , add Normal "fromJSON" fromJSON+ --, add Normal "fromTOML" fromTOML , add Normal "functionArgs" functionArgs- , add2 Normal "genList" genList , add Normal "genericClosure" genericClosure+ , add2 Normal "genList" genList , add2 Normal "getAttr" getAttr+ , add Normal "getContext" getContext , add Normal "getEnv" getEnv_ , add2 Normal "hasAttr" hasAttr , add Normal "hasContext" hasContext@@ -236,14 +243,15 @@ , add2 TopLevel "mapAttrs" mapAttrs_ , add2 Normal "match" match_ , add2 Normal "mul" mul_+ , add0 Normal "nixPath" nixPath , add0 Normal "null" (pure $ nvConstant NNull) , add Normal "parseDrvName" parseDrvName , add2 Normal "partition" partition_+ --, add Normal "path" path , add Normal "pathExists" pathExists_ , add TopLevel "placeholder" placeHolder , add Normal "readDir" readDir_ , add Normal "readFile" readFile_- , add2 Normal "findFile" findFile_ , add2 TopLevel "removeAttrs" removeAttrs , add3 Normal "replaceStrings" replaceStrings , add2 TopLevel "scopedImport" scopedImport@@ -252,26 +260,25 @@ , add2 Normal "split" split_ , add Normal "splitVersion" splitVersion_ , add0 Normal "storeDir" (pure $ nvStr $ principledMakeNixStringWithoutContext "/nix/store")+ --, add Normal "storePath" storePath , add' Normal "stringLength" (arity1 $ Text.length . principledStringIgnoreContext) , add' Normal "sub" (arity2 ((-) @Integer))- , add' Normal "substring" (substring @e @t @f @m)+ , add' Normal "substring" substring , add Normal "tail" tail_- , add0 Normal "true" (pure $ nvConstant $ NBool True) , add TopLevel "throw" throw_- , add Normal "toJSON" prim_toJSON , add2 Normal "toFile" toFile+ , add Normal "toJSON" prim_toJSON , add Normal "toPath" toPath , add TopLevel "toString" toString , add Normal "toXML" toXML_ , add2 TopLevel "trace" trace_+ , add0 Normal "true" (pure $ nvConstant $ NBool True) , add Normal "tryEval" tryEval , add Normal "typeOf" typeOf+ --, add0 Normal "unsafeDiscardOutputDependency" unsafeDiscardOutputDependency+ , add Normal "unsafeDiscardStringContext" unsafeDiscardStringContext+ , add2 Normal "unsafeGetAttrPos" unsafeGetAttrPos , add Normal "valueSize" getRecursiveSize- , add Normal "getContext" getContext- , add2 Normal "appendContext" appendContext-- , add2 Normal "unsafeGetAttrPos" unsafeGetAttrPos- , add Normal "unsafeDiscardStringContext" unsafeDiscardStringContext ] where wrap :: BuiltinType -> Text -> v -> Builtin v@@ -652,13 +659,13 @@ thunkStr s = nvStr (hackyMakeNixStringWithoutContext (decodeUtf8 s)) substring :: forall e t f m. MonadNix e t f m => Int -> Int -> NixString -> Prim m NixString-substring start len str = Prim $ if start < 0 --NOTE: negative values of 'len' are OK- then- throwError- $ ErrorCall- $ "builtins.substring: negative start position: "- ++ show start- else pure $ principledModifyNixContents (Text.take len . Text.drop start) str+substring start len str = Prim $+ if start < 0+ then throwError $ ErrorCall $ "builtins.substring: negative start position: " ++ show start+ else pure $ principledModifyNixContents (take . Text.drop start) str+ where+ --NOTE: negative values of 'len' are OK, and mean "take everything"+ take = if len < 0 then id else Text.take len attrNames :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)@@ -766,6 +773,12 @@ bitXor x y = fromValue @Integer x >>= \a -> fromValue @Integer y >>= \b -> toValue (a `xor` b) +builtinsBuiltin+ :: forall e t f m+ . MonadNix e t f m+ => m (NValue t f m)+builtinsBuiltin = (throwError $ ErrorCall "HNix does not provide builtins.builtins at the moment. Using builtins directly should be preferred")+ dirOf :: MonadNix e t f m => NValue t f m -> m (NValue t f m) dirOf x = demand x $ \case NVStr ns -> pure $ nvStr@@ -1040,10 +1053,6 @@ :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m) isList = hasKind @[NValue t f m] -isString- :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)-isString = hasKind @NixString- isInt :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m) isInt = hasKind @Int@@ -1059,6 +1068,12 @@ isNull :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m) isNull = hasKind @()++-- isString cannot use `hasKind` because it coerces derivations to strings.+isString :: MonadNix e t f m => NValue t f m -> m (NValue t f m)+isString v = demand v $ \case+ NVStr{} -> toValue True+ _ -> toValue False isFunction :: MonadNix e t f m => NValue t f m -> m (NValue t f m) isFunction func = demand func $ \case
src/Nix/Effects.hs view
@@ -145,7 +145,7 @@ ++ err pathExists :: MonadFile m => FilePath -> m Bool-pathExists = doesFileExist+pathExists = doesPathExist class Monad m => MonadEnv m where getEnvVar :: String -> m (Maybe String)
src/Nix/Effects/Basic.hs view
@@ -64,13 +64,13 @@ Nothing -> getCurrentDirectory Just v -> demand v $ \case NVPath s -> pure $ takeDirectory s- v ->+ val -> throwError $ ErrorCall $ "when resolving relative path," ++ " __cur_file is in scope," ++ " but is not a path; it is: "- ++ show v+ ++ show val pure $ cwd <///> origPathExpanded removeDotDotIndirections <$> canonicalizePath absPath @@ -111,13 +111,13 @@ where nixFilePath :: MonadEffects t f m => FilePath -> m (Maybe FilePath) nixFilePath path = do- path <- makeAbsolutePath @t @f path- exists <- doesDirectoryExist path- path' <- if exists- then makeAbsolutePath @t @f $ path </> "default.nix"- else pure path- exists <- doesFileExist path'- pure $ if exists then Just path' else Nothing+ absPath <- makeAbsolutePath @t @f path+ isDir <- doesDirectoryExist absPath+ absFile <- if isDir+ then makeAbsolutePath @t @f $ absPath </> "default.nix"+ else return absPath+ exists <- doesFileExist absFile+ pure $ if exists then Just absFile else Nothing findPathBy :: forall e t f m@@ -226,13 +226,13 @@ => [NValue t f m] -> FilePath -> m FilePath-findPathM = findPathBy path+findPathM = findPathBy existingPath where- path :: MonadEffects t f m => FilePath -> m (Maybe FilePath)- path path = do- path <- makeAbsolutePath @t @f path- exists <- doesPathExist path- pure $ if exists then Just path else Nothing+ existingPath :: MonadEffects t f m => FilePath -> m (Maybe FilePath)+ existingPath path = do+ apath <- makeAbsolutePath @t @f path+ exists <- doesPathExist apath+ pure $ if exists then Just apath else Nothing defaultImportPath :: (MonadNix e t f m, MonadState (HashMap FilePath NExprLoc) m)
src/Nix/Exec.hs view
@@ -297,14 +297,12 @@ when (length frames > 2000) $ throwError $ ErrorCall "Function call stack exhausted" case fun' of- NVClosure params f -> do- traceM $ "callFunc:NVFunction taking " ++ show params+ NVClosure _params f -> do f arg NVBuiltin name f -> do span <- currentPos withFrame Info (Calling @m @t name span) (f arg) s@(NVSet m _) | Just f <- M.lookup "__functor" m -> do- traceM "callFunc:__functor" demand f $ (`callFunc` s) >=> (`callFunc` arg) x -> throwError $ ErrorCall $ "Attempt to call non-function: " ++ show x @@ -316,7 +314,6 @@ -> NValue t f m -> m (NValue t f m) execUnaryOp scope span op arg = do- traceM "NUnary" case arg of NVConstant c -> case (op, c) of (NNeg, NInt i ) -> unaryOp $ NInt (-i)@@ -478,7 +475,7 @@ fromStringNoContext :: Framed e m => NixString -> m Text fromStringNoContext ns = case principledGetStringNoContext ns of Just str -> pure str- Nothing -> throwError $ ErrorCall "expected string with no context"+ Nothing -> throwError $ ErrorCall $ "expected string with no context, but got " ++ show ns addTracing :: (MonadNix e t f m, Has e Options, MonadReader Int n, Alternative n)
src/Nix/Parser.hs view
@@ -268,7 +268,7 @@ nixAssert :: Parser NExprLoc nixAssert = annotateLocation1 ( NAssert- <$> (reserved "assert" *> nixExpr)+ <$> (reserved "assert" *> nixToplevelForm) <*> (semi *> nixToplevelForm) <?> "assert" )@@ -643,7 +643,7 @@ , {- 13 -} [binaryL "||" NOr] , {- 14 -}- [binaryN "->" NImpl]+ [binaryR "->" NImpl] ] data OperatorInfo = OperatorInfo
src/Nix/Render.hs view
@@ -77,6 +77,9 @@ renderLocation :: MonadFile m => SrcSpan -> Doc a -> m (Doc a) renderLocation (SrcSpan (SourcePos file begLine begCol) (SourcePos file' endLine endCol)) msg+ | file == file' && file == "<string>" && begLine == endLine+ = pure $ "In raw input string at position " <> pretty (unPos begCol)+ | file /= "<string>" && file == file' = do exist <- doesFileExist file
src/Nix/Thunk/Basic.hs view
@@ -15,7 +15,6 @@ import Control.Monad.Catch import Nix.Thunk-import Nix.Utils import Nix.Var data Deferred m v = Deferred (m v) | Computed v@@ -75,7 +74,6 @@ if nowActive then throwM $ ThunkLoop $ show n else do- traceM $ "Forcing " ++ show n v <- catch action $ \(e :: SomeException) -> do _ <- atomicModifyVar active (False, ) throwM e