Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to jailbreak packages or not #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:
Expand Down
51 changes: 35 additions & 16 deletions hackage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,21 @@ data ConfigTests = ConfigTests

type instance RuleResult ConfigTests = Bool

-- | Key to obtain jailbreak
data ConfigJailbreak = ConfigJailbreak

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data ConfigJailbreak = ConfigJailbreak
data ConfigJailbreak = ConfigJailbreak

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

97

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data ConfigJailbreak = ConfigJailbreak
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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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
]
, ["}"]
]
Expand Down