git.iko.soy/typeable/cabal2nix
on master help sign in
If both package.yaml and cabal exist, prefer package.yaml.

This is because in a nomal workflow, you would generate the .cabal every now and then from the package.yaml file. If you forget to do this generation and you have an old .cabal file in your tree (common because for users of hpack, .cabal files are usually in .gitignore), then until now nix would pick up the outdated cabal file and you would accidentally be running against outdated cabal contents. So in this commit we change the logic from "if *.cabal doens't exist, check if package.yaml exist, if so use hpack" to "if package.ymal exists, use hpack, otherwise use *.cabal"

commit5721bed2a598a018119413bfe868bd286735cb15 authorNiklas Hambüchen <mail@nh2.me> dateTue 17 Jul 2018, 12:40 (8 years ago) parent13ff907
1 file changed+11−6
src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+11−6
src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+11−6
@@ -183,13 +183,18 @@ cabalFromDirectory :: Bool -- ^ Whether hpack should regenerate the cabal file
183183 -> FilePath -> MaybeT IO (Bool, Cabal.GenericPackageDescription)
184184cabalFromDirectory True dir = hpackDirectory dir
185185cabalFromDirectory False dir = do
186− cabals <- liftIO $ getDirectoryContents dir >>= filterM doesFileExist . map (dir </>) . filter (".cabal" `isSuffixOf`)
187− case cabals of
188− [] -> do
189− liftIO $ hPutStrLn stderr "*** found zero cabal files. Trying hpack..."
186+ useHpack <- liftIO $ doesFileExist (dir </> "package.yaml")
187+ if useHpack
188+ then do
189+ liftIO $ hPutStrLn stderr "*** found package.yaml. Using hpack..."
190190 hpackDirectory dir
191− [cabalFile] -> (,) False <$> cabalFromFile True cabalFile
192− _ -> liftIO $ fail ("*** found more than one cabal file (" ++ show cabals ++ "). Exiting.")
191+ else do
192+ cabals <- liftIO $ getDirectoryContents dir >>= filterM doesFileExist . map (dir </>) . filter (".cabal" `isSuffixOf`)
193+ case cabals of
194+ [] -> do
195+ fail "*** Found neither a .cabal file nor package.yaml. Exiting."
196+ [cabalFile] -> (,) False <$> cabalFromFile True cabalFile
197+ _ -> liftIO $ fail ("*** found more than one cabal file (" ++ show cabals ++ "). Exiting.")
193198
194199handleIO :: (Exception.IOException -> IO a) -> IO a -> IO a
195200handleIO = Exception.handle