Skip to content

Commit 8f8f952

Browse files
hackage2nix: add excluded-packages config option
1 parent 281e505 commit 8f8f952

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

cabal2nix/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
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. These
16+
packages will be set to `null` explicitly.
17+
1418
## 2.20.1
1519

1620
* Add support for Cabal `== 3.14.*` in the test suite.
@@ -131,7 +135,7 @@ see [#506](https://github.com/NixOS/cabal2nix/pull/506).
131135
* Argument parsing logic in `cabal2nix` has been refactored
132136
in [#544](https://github.com/NixOS/cabal2nix/pull/544).
133137
**API breaking change** for the following modules:
134-
138+
135139
* `Cabal2nix`
136140
* `Distribution.Nixpkgs.Fetch`
137141
* `Distribution.Nixpkgs.Haskell.Derivation` (removed instance)

cabal2nix/hackage2nix/Main.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,11 @@ main = do
170170

171171
overrides :: Doc
172172
overrides = fcat $ punctuate space [ pPrint b <> semi | b <- Set.toList (view (dependencies . each) drv `Set.union` view extraFunctionArgs drv), not (isFromHackage b) ]
173-
return $ render $ nest 2 $
174-
hang (doubleQuotes (text attr) <+> equals <+> text "callPackage") 2 (parens (pPrint drv)) <+> (braces overrides <> semi)
173+
174+
def :: Doc
175+
def | Set.member name $ excludedPackages config = doubleQuotes (text attr) <+> equals <+> text "null"
176+
| otherwise = hang (doubleQuotes (text attr) <+> equals <+> text "callPackage") 2 (parens (pPrint drv)) <+> (braces overrides)
177+
return $ render $ nest 2 def <> semi
175178

176179
return (intercalate "\n\n" defs)
177180

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)