diff --git a/Readme.markdown b/Readme.markdown index 62d2cf6..3a9e96b 100644 --- a/Readme.markdown +++ b/Readme.markdown @@ -49,6 +49,8 @@ alphanumerically and value from later files take precedence - `haddock` -- boolean flag on whether to build haddocks. Default is false. - `tests` -- boolean flag on whether to run tests when building package. Default is false. + - `jailbreak` -- boolean flag on whether to jailbreak packages. If true cabal + won't check dependencies' versions. Default is true. For example: @@ -106,6 +108,9 @@ dummy dependency `testu01`. This allows to provide dependencies. splitmix = ... (prev.callPackage ./pkgs/haskell/splitmix.nix { testu01=null; }); ``` +Field `jailbreak` could be specified for each package. It true nix package will +be jailbroken (cabal won't check dependencies versions) + * `patches` - contains patches that are applied to the nix files (will be modified in the future) Notes: diff --git a/hackage.hs b/hackage.hs index 8353366..3ed4bf6 100644 --- a/hackage.hs +++ b/hackage.hs @@ -93,13 +93,21 @@ data ConfigTests = ConfigTests type instance RuleResult ConfigTests = Bool +-- | Key to obtain jailbreak +data ConfigJailbreak = ConfigJailbreak + deriving stock (Show, Eq, Generic) + deriving anyclass (Hashable, Binary, FromJSON, NFData) + +type instance RuleResult ConfigJailbreak = Bool + data Config = Config { cfgRevision :: !String -- ^ Hackage revision , cfgGhcVersion :: !String -- ^ GHC version to pass to cabal2nix , cfgProfile :: !Bool -- ^ Whether to build profiling , cfgHaddock :: !Bool -- ^ Whether to build haddocks - , cfgTests :: !Bool + , cfgTests :: !Bool -- ^ Whether to enable tests + , cfgJailbreak :: !Bool -- ^ Whether to apply jailbreak to package } deriving stock (Show, Eq, Generic) deriving anyclass (Hashable, Binary, NFData) @@ -108,16 +116,18 @@ instance FromJSON Config where parseJSON = withObject "Config" $ \o -> do cfgRevision <- o .: "revision" cfgGhcVersion <- o .: "ghc_version" - cfgProfile <- o .:? "profile" .!= False - cfgHaddock <- o .:? "haddock" .!= False - cfgTests <- o .:? "tests" .!= False + cfgProfile <- o .:? "profile" .!= False + cfgHaddock <- o .:? "haddock" .!= False + cfgTests <- o .:? "tests" .!= False + cfgJailbreak <- o .:? "jailbreak" .!= True pure Config{..} -- | Information about package. data Package = Package - { packageSource :: Source -- ^ Source location for package - , packageParams :: [String] -- ^ Code fragments to pass to package + { packageSource :: Source -- ^ Source location for package + , packageParams :: [String] -- ^ Code fragments to pass to package + , packageJailbreak :: !Bool -- ^ Whether to apply jailbreak to package } deriving stock (Show, Eq, Generic) deriving anyclass (Hashable, Binary, NFData) @@ -140,10 +150,11 @@ data Git = Git instance FromJSON Package where parseJSON v@String{} = do src <- parseJSON v - pure $ Package src [] + pure $ Package src [] True parseJSON v@(Object o) = do src <- (SourceCabal <$> o .: "hackage") <|> parseJSON v param <- o .:? "parameters" .!= [] - pure $ Package src param + jail <- o .:? "jailbreak" .!= True + pure $ Package src param jail parseJSON _ = fail "Cannot parse package" instance FromJSON Source where @@ -193,11 +204,12 @@ main = do case nm `Map.lookup` repo_set of Just s -> pure s Nothing -> error $ "No such repository: " ++ nm - get_revision <- addOracle $ \ConfigRevisionKey -> pure $ cfgRevision config - get_ghcver <- addOracle $ \ConfigGhcVersion -> pure $ cfgGhcVersion config - get_profile <- addOracle $ \ConfigProfile -> pure $ cfgProfile config - get_haddock <- addOracle $ \ConfigHaddock -> pure $ cfgHaddock config - get_tests <- addOracle $ \ConfigTests -> pure $ cfgTests config + get_revision <- addOracle $ \ConfigRevisionKey -> pure $ cfgRevision config + get_ghcver <- addOracle $ \ConfigGhcVersion -> pure $ cfgGhcVersion config + get_profile <- addOracle $ \ConfigProfile -> pure $ cfgProfile config + get_haddock <- addOracle $ \ConfigHaddock -> pure $ cfgHaddock config + get_tests <- addOracle $ \ConfigTests -> pure $ cfgTests config + get_jailbreak <- addOracle $ \ConfigJailbreak -> pure $ cfgJailbreak config -- Phony targets phony "clean" $ do removeFilesAfter "nix/" ["pkgs/haskell/*.nix", "default.nix"] @@ -257,16 +269,23 @@ main = do profile::String <- get_profile ConfigProfile <&> \case True -> "lib.enableLibraryProfiling" False -> "lib.disableLibraryProfiling" + jailbreak::String <- get_jailbreak ConfigJailbreak <&> \case + True -> "lib.doJailbreak" + False -> "lib.dontJailbreak" liftIO $ writeFile overlay $ unlines $ concat [ [ "pkgs: prev:" , "let" , " lib = pkgs.haskell.lib;" - , [fmt| adjust = drv: lib.doJailbreak ({profile} ({haddock} ({tests} drv)));|] + , [fmt| adjust = drv: {jailbreak} ({profile} ({haddock} ({tests} drv)));|] , "in" , "{" ] - , [ [fmt| {nm} = adjust (prev.callPackage ./{packageNixName nm} {{ {concat $ fmap (++";") param} }});|] - | (nm, Package{packageParams=param}) <- Map.toList pkgs_set + , [ [fmt| {nm} = {fin};|] + | (nm, Package{packageParams=param,packageJailbreak=jail}) <- Map.toList pkgs_set + , let pkg,fin :: String + pkg = [fmt|adjust (prev.callPackage ./{packageNixName nm} {{ {concat $ fmap (++";") param} }})|] + fin | jail = [fmt|lib.doJailbreak ({pkg})|] + | otherwise = pkg ] , ["}"] ]