From 5ae3bfb85866c87dc17131b27a66dcb630b5f1ff Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Mon, 16 Sep 2024 19:15:34 +0300 Subject: [PATCH 1/4] Add option to disable jailbreak of packages --- hackage.hs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/hackage.hs b/hackage.hs index 8353366..837658a 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,9 +116,10 @@ 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{..} @@ -193,11 +202,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,11 +267,14 @@ 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" , "{" ] From e51afdfff4376c2685287321b05c5c94d7c88d9d Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Tue, 17 Sep 2024 12:53:08 +0300 Subject: [PATCH 2/4] Allow jailbreak on per-package basis --- hackage.hs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/hackage.hs b/hackage.hs index 837658a..7c09ddc 100644 --- a/hackage.hs +++ b/hackage.hs @@ -125,8 +125,9 @@ instance FromJSON Config where -- | 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) @@ -149,10 +150,11 @@ data Git = Git instance FromJSON Package where parseJSON v@String{} = do src <- parseJSON v - pure $ Package src [] + pure $ Package src [] False parseJSON v@(Object o) = do src <- (SourceCabal <$> o .: "hackage") <|> parseJSON v param <- o .:? "parameters" .!= [] - pure $ Package src param + jail <- o .:? "jailbreak" .!= False + pure $ Package src param jail parseJSON _ = fail "Cannot parse package" instance FromJSON Source where @@ -278,8 +280,12 @@ main = do , "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 ] , ["}"] ] From c50c34890cecc1749f91f0a88f6f045529441d78 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Tue, 17 Sep 2024 13:02:06 +0300 Subject: [PATCH 3/4] Update ereadme --- Readme.markdown | 5 +++++ 1 file changed, 5 insertions(+) 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: From f5147ece1d5308911f4a1a0f4932202b519b79d2 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Sun, 22 Sep 2024 17:58:11 +0300 Subject: [PATCH 4/4] Use correct defaults --- hackage.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hackage.hs b/hackage.hs index 7c09ddc..3ed4bf6 100644 --- a/hackage.hs +++ b/hackage.hs @@ -150,10 +150,10 @@ data Git = Git instance FromJSON Package where parseJSON v@String{} = do src <- parseJSON v - pure $ Package src [] False + pure $ Package src [] True parseJSON v@(Object o) = do src <- (SourceCabal <$> o .: "hackage") <|> parseJSON v param <- o .:? "parameters" .!= [] - jail <- o .:? "jailbreak" .!= False + jail <- o .:? "jailbreak" .!= True pure $ Package src param jail parseJSON _ = fail "Cannot parse package"