Skip to content

Commit

Permalink
Build nonReinstallablePkgs from pre-existing packages in plan.json
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishmack committed May 27, 2024
1 parent 200be01 commit 0a6a049
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 24 deletions.
58 changes: 38 additions & 20 deletions nix-tools/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions nix-tools/nix-tools/plan2nix/Plan2Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ plan2nix args Plan { packages, extras, components, compilerVersion, compilerPack
-- called from the toplevel project directory.
cwd <- getCurrentDirectory
extrasNix <- fmap (mkNonRecSet . concat) . forM (Map.toList extras) $ \case
(_name, Just (Package v flags (Just (LocalPath folder)) False)) ->
(_name, Just (Package v flags (Just (LocalPath folder)) False _)) ->
do cabalFiles <- findCabalFiles (argHpackUse args) folder
forM cabalFiles $ \cabalFile ->
let pkg = cabalFilePkgName cabalFile
Expand All @@ -95,7 +95,7 @@ plan2nix args Plan { packages, extras, components, compilerVersion, compilerPack
in do createDirectoryIfMissing True (takeDirectory nixFile)
writeDoc nixFile . prettyNix =<< cabal2nix True (argDetailLevel args) src cabalFile
return $ fromString pkg $= mkPath False nix
(_name, Just (Package v flags (Just (DVCS (Git url rev) subdirs)) False)) ->
(_name, Just (Package v flags (Just (DVCS (Git url rev) subdirs)) False _)) ->
fmap concat . forM subdirs $ \subdir ->
do cacheHits <- liftIO $ cacheHits (argCacheFile args) url rev subdir
case cacheHits of
Expand All @@ -109,11 +109,14 @@ plan2nix args Plan { packages, extras, components, compilerVersion, compilerPack
return $ fromString pkg $= mkPath False nix
_ -> return []
let flags = concatMap (\case
(name, Just (Package _v f _hasDescriptionOverride _)) -> flags2nix name f
(name, Just (Package _v f _hasDescriptionOverride _ _)) -> flags2nix name f
_ -> []) $ Map.toList extras
-- Set the `planned` option for all components in the plan.
planned = map (\name -> name <> ".planned" $=
("lib" @. "mkOverride" @@ mkInt 900 @@ mkBool True)) $ Set.toList components
preExisting = concatMap (\case
(name, Just (Package _ _ _ _ True)) -> [mkStr "rts", mkStr name]
_ -> []) $ Map.toList packages

return $ mkNonRecSet [
"pkgs" $= ("hackage" ==> mkNonRecSet
Expand All @@ -126,7 +129,10 @@ plan2nix args Plan { packages, extras, components, compilerVersion, compilerPack
])
, "extras" $= ("hackage" ==> mkNonRecSet [ "packages" $= extrasNix ])
, "modules" $= mkList [
mkParamset [("lib", Nothing)] True ==> mkNonRecSet [ "packages" $= mkNonRecSet flags ]
mkNonRecSet [
"nonReinstallablePkgs" $= mkList preExisting
]
, mkParamset [("lib", Nothing)] True ==> mkNonRecSet [ "packages" $= mkNonRecSet flags ]
, mkParamset [("lib", Nothing)] True ==> mkNonRecSet [ "packages" $= mkNonRecSet planned ]
]
]
Expand Down Expand Up @@ -200,6 +206,7 @@ value2plan plan = Plan { packages, components, extras, compilerVersion, compiler
. KeyMap.toList $ KeyMap.mapMaybe (^? _Bool) $ pkg ^. key "flags" . _Object
, packageSrc = Nothing
, packageHasDescriptionOverride = isJust (pkg ^? key "pkg-cabal-sha256")
, packagePreExisting = False
}

(_, "inplace") -> Just $ Package
Expand All @@ -208,6 +215,7 @@ value2plan plan = Plan { packages, components, extras, compilerVersion, compiler
. KeyMap.toList $ KeyMap.mapMaybe (^? _Bool) $ pkg ^. key "flags" . _Object
, packageSrc = Nothing
, packageHasDescriptionOverride = isJust (pkg ^? key "pkg-cabal-sha256")
, packagePreExisting = False
}
-- Until we figure out how to force Cabal to reconfigure just about any package
-- this here might be needed, so that we get the pre-existing packages as well.
Expand All @@ -220,6 +228,7 @@ value2plan plan = Plan { packages, components, extras, compilerVersion, compiler
, packageFlags = Map.empty
, packageSrc = Nothing
, packageHasDescriptionOverride = isJust (pkg ^? key "pkg-cabal-sha256") -- likely this is always false
, packagePreExisting = True
}
_ -> Nothing

Expand Down
1 change: 1 addition & 0 deletions nix-tools/nix-tools/plan2nix/Plan2Nix/Plan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ data Package = Package
, packageFlags :: HashMap VarName Bool
, packageSrc :: Maybe PkgSrc
, packageHasDescriptionOverride :: Bool
, packagePreExisting :: Bool
} deriving (Show)

0 comments on commit 0a6a049

Please sign in to comment.