From 84c259784885e91d5f0f70c4b9bd6db23534f30f Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Thu, 28 Aug 2025 14:45:34 +0200 Subject: [PATCH 1/2] Add basic .editorconfig Spaces instead of tabs, as used everywhere. --- .editorconfig | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..0f178672 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true From be7f47ffc0eebe572cd3437289370c9efcbb23dd Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sun, 7 Sep 2025 15:23:41 +0200 Subject: [PATCH 2/2] hackage2nix: add excluded-packages config option --- cabal2nix/CHANGELOG.md | 7 +++++-- cabal2nix/hackage2nix/Main.hs | 11 ++++++----- .../Nixpkgs/Haskell/FromCabal/Configuration.hs | 13 ++++++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cabal2nix/CHANGELOG.md b/cabal2nix/CHANGELOG.md index 53bfcfbd..c6e54d15 100644 --- a/cabal2nix/CHANGELOG.md +++ b/cabal2nix/CHANGELOG.md @@ -5,12 +5,15 @@ * In expressions generated by `cabal2nix --shell`, use the `inNixShell` function argument instead of `pkgs.lib.inNixShell`. Note that this requires [Nix 2.4 or later](https://github.com/NixOS/nix/pull/3168). - + Note that this only works correctly if the generated expression is the top level expression. If you want to use a wrapper expression, make sure it has an `inNixShell` argument and pass that through to the generated one. +* `hackage2nix` now supports an `excluded-packages` config option to + prevent creating expressions for specific packages entirely. + ## 2.20.1 * Add support for Cabal `== 3.14.*` in the test suite. @@ -131,7 +134,7 @@ see [#506](https://github.com/NixOS/cabal2nix/pull/506). * Argument parsing logic in `cabal2nix` has been refactored in [#544](https://github.com/NixOS/cabal2nix/pull/544). **API breaking change** for the following modules: - + * `Cabal2nix` * `Distribution.Nixpkgs.Fetch` * `Distribution.Nixpkgs.Haskell.Derivation` (removed instance) diff --git a/cabal2nix/hackage2nix/Main.hs b/cabal2nix/hackage2nix/Main.hs index 5c0b7f64..8eab0c1f 100644 --- a/cabal2nix/hackage2nix/Main.hs +++ b/cabal2nix/hackage2nix/Main.hs @@ -114,11 +114,12 @@ main = do [ Map.singleton name (Set.singleton (resolveConstraint c hackage)) | c@(PackageVersionConstraint name _) <- extraPackages config ] db :: PackageMultiSet - db = Map.unionsWith Set.union [ Map.map Set.singleton generatedDefaultPackageSet - , Map.map Set.singleton latestCorePackageSet - , Map.map Set.singleton latestOverridePackageSet - , extraPackageSet - ] + db = flip Map.withoutKeys (excludedPackages config) $ Map.unionsWith Set.union + [ Map.map Set.singleton generatedDefaultPackageSet + , Map.map Set.singleton latestCorePackageSet + , Map.map Set.singleton latestOverridePackageSet + , extraPackageSet + ] haskellResolver :: HaskellResolver haskellResolver (PackageVersionConstraint name vrange) diff --git a/cabal2nix/src/Distribution/Nixpkgs/Haskell/FromCabal/Configuration.hs b/cabal2nix/src/Distribution/Nixpkgs/Haskell/FromCabal/Configuration.hs index 7ab2aec4..9598658a 100644 --- a/cabal2nix/src/Distribution/Nixpkgs/Haskell/FromCabal/Configuration.hs +++ b/cabal2nix/src/Distribution/Nixpkgs/Haskell/FromCabal/Configuration.hs @@ -64,6 +64,11 @@ data Configuration = Configuration -- also disable their meta.hydraPlatforms attribute to avoid cluttering our -- Hydra job with lots of failure messages. , brokenPackages :: [Constraint] + + -- |These packages have likely been broken for a long time and are unmaintained + -- upstream. To reduce the size of hackage-packages.nix, we don't even create + -- expressions for them. + , excludedPackages :: Set PackageName } deriving (Show, Generic) @@ -79,6 +84,7 @@ instance Semigroup Configuration where , unsupportedPlatforms = unsupportedPlatforms l <> unsupportedPlatforms r , dontDistributePackages = dontDistributePackages l <> dontDistributePackages r , brokenPackages = brokenPackages l <> brokenPackages r + , excludedPackages = excludedPackages l <> excludedPackages r } instance FromJSON Configuration where @@ -92,6 +98,7 @@ instance FromJSON Configuration where <*> o .:? "unsupported-platforms" .!= mempty <*> o .:? "dont-distribute-packages" .!= mempty <*> o .:? "broken-packages" .!= mempty + <*> o .:? "excluded-packages" .!= mempty parseJSON _ = error "invalid Configuration" instance FromJSON Identifier where @@ -114,7 +121,11 @@ assertConsistency :: MonadFail m => Configuration -> m Configuration assertConsistency cfg@Configuration {..} = do let report msg = fail ("*** configuration error: " ++ msg) maintainedPackages = Set.unions (Map.elems packageMaintainers) - disabledPackages = dontDistributePackages `Set.union` Set.fromList (constraintPkgName <$> brokenPackages) + disabledPackages = Set.unions + [ dontDistributePackages + , Set.fromList (constraintPkgName <$> brokenPackages) + , excludedPackages + ] disabledMaintainedPackages = maintainedPackages `Set.intersection` disabledPackages unless (Set.null disabledMaintainedPackages) $ report ("disabled packages that have a maintainer: " ++ show disabledMaintainedPackages)