Skip to content

Commit be7f47f

Browse files
hackage2nix: add excluded-packages config option
1 parent 84c2597 commit be7f47f

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

cabal2nix/CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
* In expressions generated by `cabal2nix --shell`, use the `inNixShell`
66
function argument instead of `pkgs.lib.inNixShell`. Note that this
77
requires [Nix 2.4 or later](https://github.com/NixOS/nix/pull/3168).
8-
8+
99
Note that this only works correctly if the generated expression is
1010
the top level expression. If you want to use a wrapper expression,
1111
make sure it has an `inNixShell` argument and pass that through
1212
to the generated one.
1313

14+
* `hackage2nix` now supports an `excluded-packages` config option to
15+
prevent creating expressions for specific packages entirely.
16+
1417
## 2.20.1
1518

1619
* Add support for Cabal `== 3.14.*` in the test suite.
@@ -131,7 +134,7 @@ see [#506](https://github.com/NixOS/cabal2nix/pull/506).
131134
* Argument parsing logic in `cabal2nix` has been refactored
132135
in [#544](https://github.com/NixOS/cabal2nix/pull/544).
133136
**API breaking change** for the following modules:
134-
137+
135138
* `Cabal2nix`
136139
* `Distribution.Nixpkgs.Fetch`
137140
* `Distribution.Nixpkgs.Haskell.Derivation` (removed instance)

cabal2nix/hackage2nix/Main.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ main = do
114114
[ Map.singleton name (Set.singleton (resolveConstraint c hackage)) | c@(PackageVersionConstraint name _) <- extraPackages config ]
115115

116116
db :: PackageMultiSet
117-
db = Map.unionsWith Set.union [ Map.map Set.singleton generatedDefaultPackageSet
118-
, Map.map Set.singleton latestCorePackageSet
119-
, Map.map Set.singleton latestOverridePackageSet
120-
, extraPackageSet
121-
]
117+
db = flip Map.withoutKeys (excludedPackages config) $ Map.unionsWith Set.union
118+
[ Map.map Set.singleton generatedDefaultPackageSet
119+
, Map.map Set.singleton latestCorePackageSet
120+
, Map.map Set.singleton latestOverridePackageSet
121+
, extraPackageSet
122+
]
122123

123124
haskellResolver :: HaskellResolver
124125
haskellResolver (PackageVersionConstraint name vrange)

cabal2nix/src/Distribution/Nixpkgs/Haskell/FromCabal/Configuration.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ data Configuration = Configuration
6464
-- also disable their meta.hydraPlatforms attribute to avoid cluttering our
6565
-- Hydra job with lots of failure messages.
6666
, brokenPackages :: [Constraint]
67+
68+
-- |These packages have likely been broken for a long time and are unmaintained
69+
-- upstream. To reduce the size of hackage-packages.nix, we don't even create
70+
-- expressions for them.
71+
, excludedPackages :: Set PackageName
6772
}
6873
deriving (Show, Generic)
6974

@@ -79,6 +84,7 @@ instance Semigroup Configuration where
7984
, unsupportedPlatforms = unsupportedPlatforms l <> unsupportedPlatforms r
8085
, dontDistributePackages = dontDistributePackages l <> dontDistributePackages r
8186
, brokenPackages = brokenPackages l <> brokenPackages r
87+
, excludedPackages = excludedPackages l <> excludedPackages r
8288
}
8389

8490
instance FromJSON Configuration where
@@ -92,6 +98,7 @@ instance FromJSON Configuration where
9298
<*> o .:? "unsupported-platforms" .!= mempty
9399
<*> o .:? "dont-distribute-packages" .!= mempty
94100
<*> o .:? "broken-packages" .!= mempty
101+
<*> o .:? "excluded-packages" .!= mempty
95102
parseJSON _ = error "invalid Configuration"
96103

97104
instance FromJSON Identifier where
@@ -114,7 +121,11 @@ assertConsistency :: MonadFail m => Configuration -> m Configuration
114121
assertConsistency cfg@Configuration {..} = do
115122
let report msg = fail ("*** configuration error: " ++ msg)
116123
maintainedPackages = Set.unions (Map.elems packageMaintainers)
117-
disabledPackages = dontDistributePackages `Set.union` Set.fromList (constraintPkgName <$> brokenPackages)
124+
disabledPackages = Set.unions
125+
[ dontDistributePackages
126+
, Set.fromList (constraintPkgName <$> brokenPackages)
127+
, excludedPackages
128+
]
118129
disabledMaintainedPackages = maintainedPackages `Set.intersection` disabledPackages
119130
unless (Set.null disabledMaintainedPackages) $
120131
report ("disabled packages that have a maintainer: " ++ show disabledMaintainedPackages)

0 commit comments

Comments
 (0)