From 1183456755ea6bdd409852d972ab08eafb9a91d5 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Mon, 31 Oct 2022 15:17:42 +0000 Subject: [PATCH 1/2] Change boolattr to always write to the attributes --- cabal2nix/src/Distribution/Nixpkgs/Fetch.hs | 2 +- .../Nixpkgs/Haskell/Derivation.hs | 22 +++++++++---------- .../src/Distribution/Nixpkgs/Meta.hs | 2 +- .../src/Language/Nix/PrettyPrinting.hs | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cabal2nix/src/Distribution/Nixpkgs/Fetch.hs b/cabal2nix/src/Distribution/Nixpkgs/Fetch.hs index 1f2891e0c..a427355a6 100644 --- a/cabal2nix/src/Distribution/Nixpkgs/Fetch.hs +++ b/cabal2nix/src/Distribution/Nixpkgs/Fetch.hs @@ -90,7 +90,7 @@ instance PP.Pretty DerivationSource where [ attr "url" $ string derivUrl , attr "sha256" $ string derivHash , if derivRevision /= "" then attr "rev" (string derivRevision) else PP.empty - , boolattr "fetchSubmodules" (isJust derivSubmodule) (fromJust derivSubmodule) + , boolattr "fetchSubmodules" (maybe True id derivSubmodule) ] , rbrace PP.<> semi ] diff --git a/cabal2nix/src/Distribution/Nixpkgs/Haskell/Derivation.hs b/cabal2nix/src/Distribution/Nixpkgs/Haskell/Derivation.hs index aa489f6cf..9531e553d 100644 --- a/cabal2nix/src/Distribution/Nixpkgs/Haskell/Derivation.hs +++ b/cabal2nix/src/Distribution/Nixpkgs/Haskell/Derivation.hs @@ -120,23 +120,23 @@ instance Pretty Derivation where , onlyIf (_revision > 0) $ attr "revision" $ doubleQuotes $ int _revision , onlyIf (not (null _editedCabalFile) && _revision > 0) $ attr "editedCabalFile" $ string _editedCabalFile , listattr "configureFlags" empty (map (show . show) renderedFlags) - , boolattr "isLibrary" (not _isLibrary || _isExecutable) _isLibrary - , boolattr "isExecutable" (not _isLibrary || _isExecutable) _isExecutable - , boolattr "enableSeparateDataOutput" _enableSeparateDataOutput _enableSeparateDataOutput + , boolattr "isLibrary" _isLibrary + , boolattr "isExecutable" _isExecutable + , boolattr "enableSeparateDataOutput" _enableSeparateDataOutput , onlyIf (_setupDepends /= mempty) $ pPrintBuildInfo "setup" _setupDepends , onlyIf (_libraryDepends /= mempty) $ pPrintBuildInfo "library" _libraryDepends , onlyIf (_executableDepends /= mempty) $ pPrintBuildInfo "executable" _executableDepends , onlyIf (_testDepends /= mempty) $ pPrintBuildInfo "test" _testDepends , onlyIf (_benchmarkDepends /= mempty) $ pPrintBuildInfo "benchmark" _benchmarkDepends - , boolattr "enableLibraryProfiling" _enableLibraryProfiling _enableLibraryProfiling - , boolattr "enableExecutableProfiling" _enableExecutableProfiling _enableExecutableProfiling - , boolattr "enableSplitObjs" (not _enableSplitObjs) _enableSplitObjs - , boolattr "doHaddock" (not _runHaddock) _runHaddock - , boolattr "jailbreak" _jailbreak _jailbreak - , boolattr "doCheck" (not _doCheck) _doCheck - , boolattr "doBenchmark" _doBenchmark _doBenchmark + , boolattr "enableLibraryProfiling" _enableLibraryProfiling + , boolattr "enableExecutableProfiling" _enableExecutableProfiling + , boolattr "enableSplitObjs" _enableSplitObjs + , boolattr "doHaddock" _runHaddock + , boolattr "jailbreak" _jailbreak + , boolattr "doCheck" _doCheck + , boolattr "doBenchmark" _doBenchmark , onlyIf (not (null _testTarget)) $ attr "testTarget" $ string _testTarget - , boolattr "hyperlinkSource" (not _hyperlinkSource) _hyperlinkSource + , boolattr "hyperlinkSource" _hyperlinkSource , onlyIf (not (null _phaseOverrides)) $ vcat ((map text . lines) _phaseOverrides) , pPrint _metaSection , vcat [ attr k (text v) | (k,v) <- Map.toList _extraAttributes ] diff --git a/distribution-nixpkgs/src/Distribution/Nixpkgs/Meta.hs b/distribution-nixpkgs/src/Distribution/Nixpkgs/Meta.hs index 32d88b162..c523284f6 100644 --- a/distribution-nixpkgs/src/Distribution/Nixpkgs/Meta.hs +++ b/distribution-nixpkgs/src/Distribution/Nixpkgs/Meta.hs @@ -288,7 +288,7 @@ instance Pretty Meta where , maybe mempty (renderPlatforms "hydraPlatforms") _hydraPlatforms , maybe mempty (attr "mainProgram" . string) _mainProgram , listattrDoc "maintainers" mempty $ renderMaintainers _maintainers - , boolattr "broken" _broken _broken + , boolattr "broken" _broken ] -- | This function renders an Nix attribute binding suitable for use in diff --git a/distribution-nixpkgs/src/Language/Nix/PrettyPrinting.hs b/distribution-nixpkgs/src/Language/Nix/PrettyPrinting.hs index fa3a7db93..e64e6301f 100644 --- a/distribution-nixpkgs/src/Language/Nix/PrettyPrinting.hs +++ b/distribution-nixpkgs/src/Language/Nix/PrettyPrinting.hs @@ -34,8 +34,8 @@ attr n v = text n <+> equals <+> v <> semi onlyIf :: Bool -> Doc -> Doc onlyIf b d = if b then d else empty -boolattr :: String -> Bool -> Bool -> Doc -boolattr n p v = if p then attr n (bool v) else empty +boolattr :: String -> Bool -> Doc +boolattr n v = attr n (bool v) listattrDoc :: String -> Doc -> [Doc] -> Doc listattrDoc n prefix vs = onlyIf (not (null vs)) $ From 5818a7451320a5ffc4b8e83f62c73de9b55e507b Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Mon, 31 Oct 2022 16:35:17 +0000 Subject: [PATCH 2/2] enableSplitObjs isn't a real argument --- cabal2nix/src/Distribution/Nixpkgs/Haskell/Derivation.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/cabal2nix/src/Distribution/Nixpkgs/Haskell/Derivation.hs b/cabal2nix/src/Distribution/Nixpkgs/Haskell/Derivation.hs index 9531e553d..d9c16d230 100644 --- a/cabal2nix/src/Distribution/Nixpkgs/Haskell/Derivation.hs +++ b/cabal2nix/src/Distribution/Nixpkgs/Haskell/Derivation.hs @@ -130,7 +130,6 @@ instance Pretty Derivation where , onlyIf (_benchmarkDepends /= mempty) $ pPrintBuildInfo "benchmark" _benchmarkDepends , boolattr "enableLibraryProfiling" _enableLibraryProfiling , boolattr "enableExecutableProfiling" _enableExecutableProfiling - , boolattr "enableSplitObjs" _enableSplitObjs , boolattr "doHaddock" _runHaddock , boolattr "jailbreak" _jailbreak , boolattr "doCheck" _doCheck