Skip to content

Commit c3bc025

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

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ main = do
8080
config <- sconcat <$> mapM (\file -> readConfiguration (nixpkgsRepository </> file)) configFiles
8181
nixpkgs <- readNixpkgPackageMap nixpkgsRepository (Just "{ config = { allowAliases = false; }; }")
8282
preferredVersions <- readPreferredVersions (fromMaybe (hackageRepository </> "preferred-versions") preferredVersionsFile)
83-
let fixup = Map.delete "acme-everything" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
84-
. Map.delete "type" -- TODO: https://github.com/NixOS/cabal2nix/issues/163
85-
. Map.delete "control-invariants" -- TODO: depends on "assert"
86-
. Map.delete "ConcurrentUtils" -- TODO: depends on "assert"
87-
. Map.delete "with" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
88-
. over (at "hermes") (fmap (set (contains "1.3.4.3") False)) -- TODO: https://github.com/haskell/hackage-server/issues/436
89-
hackage <- fixup <$> readHackage hackageRepository
83+
let excluded = excludedPackages config `Set.union` Set.fromList
84+
[ "acme-everything" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
85+
, "type" -- TODO: https://github.com/NixOS/cabal2nix/issues/163
86+
, "control-invariants" -- TODO: depends on "assert"
87+
, "ConcurrentUtils" -- TODO: depends on "assert"
88+
, "with" -- TODO: https://github.com/NixOS/cabal2nix/issues/164
89+
, "hermes" -- TODO: https://github.com/haskell/hackage-server/issues/436
90+
]
91+
hackage <- flip Map.withoutKeys excluded <$> readHackage hackageRepository
9092
let
9193
hackagePackagesFile :: FilePath
9294
hackagePackagesFile = nixpkgsRepository </> "pkgs/development/haskell-modules/hackage-packages.nix"

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)