Skip to content

Commit 6e22682

Browse files
authored
Add package.isLocal for plan-to-nix & stack-to-nix (input-output-hk#63)
1 parent 9425905 commit 6e22682

File tree

6 files changed

+45
-45
lines changed

6 files changed

+45
-45
lines changed

nix-tools/cabal2nix/Main.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ main = getArgs >>= \case
4848
(Just (DerivationSource{..}, genBindings)) -> genBindings derivHash
4949
_ -> return ()
5050
[path,file] -> doesDirectoryExist file >>= \case
51-
False -> print . prettyNix =<< cabal2nix MinimalDetails (Just (Path path)) (OnDisk file)
51+
False -> print . prettyNix =<< cabal2nix False MinimalDetails (Just (Path path)) (OnDisk file)
5252
True -> print . prettyNix =<< cabalexprs file
5353
[file] -> doesDirectoryExist file >>= \case
54-
False -> print . prettyNix =<< cabal2nix MinimalDetails (Just (Path ".")) (OnDisk file)
54+
False -> print . prettyNix =<< cabal2nix False MinimalDetails (Just (Path ".")) (OnDisk file)
5555
True -> print . prettyNix =<< cabalexprs file
5656
_ -> putStrLn "call with cabalfile (Cabal2Nix file.cabal)."
5757

@@ -72,7 +72,7 @@ cabalFromPath url rev subdir path = do
7272
subdir' = if subdir == "." then Nothing
7373
else Just subdir
7474
src = Just $ Git url rev (Just sha256) subdir'
75-
print . prettyNix =<< cabal2nix MinimalDetails src cabalFile
75+
print . prettyNix =<< cabal2nix False MinimalDetails src cabalFile
7676

7777
findCabalFiles :: FilePath -> IO [CabalFile]
7878
findCabalFiles path = doesFileExist (path </> Hpack.packageConfig) >>= \case
@@ -103,7 +103,7 @@ expr p pkg version = do
103103
doesFileExist (cabalFilePath cabal) >>= \case
104104
True ->
105105
do createDirectoryIfMissing True pkg'
106-
writeDoc nix =<< prettyNix <$> cabal2nix MinimalDetails Nothing cabal
106+
writeDoc nix =<< prettyNix <$> cabal2nix False MinimalDetails Nothing cabal
107107
pure $ version' $= mkRelPath nix
108108
False -> pure $ version' $= mkNull
109109

nix-tools/ci.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
builtins.mapAttrs (k: _v:
22
let
3-
pkgs = import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/160ecb6fd7eaa203c4939f79cdc5b5e2b24dd71e.tar.gz") {
3+
pkgs = import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/57d58888d91f978fccd8648a05fe79dff71d2384.tar.gz") {
44
nixpkgs = builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/2255f292063ccbe184ff8f9b35ce475c04d5ae69.tar.gz";
55
nixpkgsArgs = { system = k; };
66
};
@@ -13,6 +13,7 @@ builtins.mapAttrs (k: _v:
1313
) {
1414
x86_64-linux = {};
1515

16+
1617
# Uncomment to test build on macOS too
1718
# x86_64-darwin = {};
1819
}

nix-tools/hackage2nix/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ main = do
5656
createDirectoryIfMissing False (out </> "hackage")
5757

5858
for_ cabalFiles $ \(cabalFile, pname, path) -> do
59-
gpd <- cabal2nix MinimalDetails Nothing $ InMemory Nothing pname $ BL.toStrict cabalFile
59+
gpd <- cabal2nix False MinimalDetails Nothing $ InMemory Nothing pname $ BL.toStrict cabalFile
6060
writeFile (out </> path) $ show $ prettyNix gpd
6161

6262
type GPDWriter = State (Seq (BL.ByteString, String, FilePath))

nix-tools/lib/Cabal2Nix.hs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ flags = "flags"
5656
buildDepError, sysDepError, pkgConfDepError, exeDepError, legacyExeDepError, buildToolDepError :: Text
5757
buildDepError = "buildDepError"
5858
sysDepError = "sysDepError"
59-
pkgConfDepError = "pkgConfDepError"
59+
pkgConfDepError = "pkgConfDepError"
6060
exeDepError = "exeDepError"
6161
legacyExeDepError = "legacyExeDepError"
62-
buildToolDepError = "buildToolDepError"
62+
buildToolDepError = "buildToolDepError"
6363

6464
($//?) :: NExpr -> Maybe NExpr -> NExpr
6565
lhs $//? (Just e) = lhs $// e
@@ -87,17 +87,17 @@ genExtra Hpack = mkNonRecSet [ "cabal-generator" $= mkStr "hpack" ]
8787

8888
data CabalDetailLevel = MinimalDetails | FullDetails deriving (Show, Eq)
8989

90-
cabal2nix :: CabalDetailLevel -> Maybe Src -> CabalFile -> IO NExpr
91-
cabal2nix fileDetails src = \case
92-
(OnDisk path) -> gpd2nix fileDetails src Nothing
90+
cabal2nix :: Bool -> CabalDetailLevel -> Maybe Src -> CabalFile -> IO NExpr
91+
cabal2nix isLocal fileDetails src = \case
92+
(OnDisk path) -> gpd2nix isLocal fileDetails src Nothing
9393
<$> readGenericPackageDescription normal path
94-
(InMemory gen _ body) -> gpd2nix fileDetails src (genExtra <$> gen)
94+
(InMemory gen _ body) -> gpd2nix isLocal fileDetails src (genExtra <$> gen)
9595
<$> case runParseResult (parseGenericPackageDescription body) of
9696
(_, Left (_, err)) -> error ("Failed to parse in-memory cabal file: " ++ show err)
9797
(_, Right desc) -> pure desc
9898

99-
gpd2nix :: CabalDetailLevel -> Maybe Src -> Maybe NExpr -> GenericPackageDescription -> NExpr
100-
gpd2nix fileDetails src extra gpd = mkLets errorFunctions $ mkFunction args $ toNix' fileDetails gpd $//? (toNix <$> src) $//? extra
99+
gpd2nix :: Bool -> CabalDetailLevel -> Maybe Src -> Maybe NExpr -> GenericPackageDescription -> NExpr
100+
gpd2nix isLocal fileDetails src extra gpd = mkLets errorFunctions $ mkFunction args $ toNixGenericPackageDescription isLocal fileDetails gpd $//? (toNix <$> src) $//? extra
101101
where args :: Params NExpr
102102
args = mkParamset [ ("system", Nothing)
103103
, ("compiler", Nothing)
@@ -108,44 +108,44 @@ gpd2nix fileDetails src extra gpd = mkLets errorFunctions $ mkFunction args $ to
108108
True
109109

110110
errorFunctions :: [Binding NExpr]
111-
errorFunctions =
112-
[ buildDepError $= mkFunction "pkg" (mkThrow $
113-
Fix $ NStr $ Indented 0
114-
[ Plain "The Haskell package set does not contain the package: "
111+
errorFunctions =
112+
[ buildDepError $= mkFunction "pkg" (mkThrow $
113+
Fix $ NStr $ Indented 0
114+
[ Plain "The Haskell package set does not contain the package: "
115115
, Antiquoted "pkg"
116116
, Plain " (build dependency).\n\n"
117117
, Plain haskellUpdateSnippet
118118
])
119-
, sysDepError $= mkFunction "pkg" (mkThrow $
120-
Fix $ NStr $ Indented 0
121-
[ Plain "The Nixpkgs package set does not contain the package: "
119+
, sysDepError $= mkFunction "pkg" (mkThrow $
120+
Fix $ NStr $ Indented 0
121+
[ Plain "The Nixpkgs package set does not contain the package: "
122122
, Antiquoted "pkg"
123123
, Plain " (system dependency).\n\n"
124124
, Plain systemUpdateSnippet
125125
])
126-
, pkgConfDepError $= mkFunction "pkg" (mkThrow $
127-
Fix $ NStr $ Indented 0
128-
[ Plain "The pkg-conf packages does not contain the package: "
126+
, pkgConfDepError $= mkFunction "pkg" (mkThrow $
127+
Fix $ NStr $ Indented 0
128+
[ Plain "The pkg-conf packages does not contain the package: "
129129
, Antiquoted "pkg"
130130
, Plain " (pkg-conf dependency).\n\n"
131131
, Plain "You may need to augment the pkg-conf package mapping in haskell.nix so that it can be found."
132132
])
133-
, exeDepError $= mkFunction "pkg" (mkThrow $
134-
Fix $ NStr $ Indented 0
135-
[ Plain "The local executable components do not include the component: "
133+
, exeDepError $= mkFunction "pkg" (mkThrow $
134+
Fix $ NStr $ Indented 0
135+
[ Plain "The local executable components do not include the component: "
136136
, Antiquoted "pkg"
137137
, Plain " (executable dependency)."
138138
])
139-
, legacyExeDepError $= mkFunction "pkg" (mkThrow $
140-
Fix $ NStr $ Indented 0
141-
[ Plain "The Haskell package set does not contain the package: "
139+
, legacyExeDepError $= mkFunction "pkg" (mkThrow $
140+
Fix $ NStr $ Indented 0
141+
[ Plain "The Haskell package set does not contain the package: "
142142
, Antiquoted "pkg"
143143
, Plain " (executable dependency).\n\n"
144144
, Plain haskellUpdateSnippet
145145
])
146-
, buildToolDepError $= mkFunction "pkg" (mkThrow $
147-
Fix $ NStr $ Indented 0
148-
[ Plain "Neither the Haskell package set or the Nixpkgs package set contain the package: "
146+
, buildToolDepError $= mkFunction "pkg" (mkThrow $
147+
Fix $ NStr $ Indented 0
148+
[ Plain "Neither the Haskell package set or the Nixpkgs package set contain the package: "
149149
, Antiquoted "pkg"
150150
, Plain " (build tool dependency).\n\n"
151151
, Plain "If this is a system dependency:\n"
@@ -213,9 +213,6 @@ capitalize = transformFst toUpper
213213
class ToNixExpr a where
214214
toNix :: a -> NExpr
215215

216-
class ToNixExpr' a where
217-
toNix' :: CabalDetailLevel -> a -> NExpr
218-
219216
class ToNixBinding a where
220217
toNixBinding :: a -> Binding NExpr
221218

@@ -242,8 +239,8 @@ instance ToNixExpr PackageIdentifier where
242239
toNix ident = mkNonRecSet [ "name" $= mkStr (fromString (show (disp (pkgName ident))))
243240
, "version" $= mkStr (fromString (show (disp (pkgVersion ident))))]
244241

245-
instance ToNixExpr' PackageDescription where
246-
toNix' detailLevel pd = mkNonRecSet $
242+
toNixPackageDescription :: Bool -> CabalDetailLevel -> PackageDescription -> NExpr
243+
toNixPackageDescription isLocal detailLevel pd = mkNonRecSet $
247244
[ "specVersion" $= mkStr (fromString (show (disp (specVersion pd))))
248245
, "identifier" $= toNix (package pd)
249246
, "license" $= mkStr (fromString (show (pretty (license pd))))
@@ -260,6 +257,8 @@ instance ToNixExpr' PackageDescription where
260257

261258
, "buildType" $= mkStr (fromString (show (pretty (buildType pd))))
262259
] ++
260+
[ "isLocal" $= mkBool True | isLocal
261+
] ++
263262
[ "setup-depends" $= toNix (BuildToolDependency . depPkgName <$> deps) | Just deps <- [setupDepends <$> setupBuildInfo pd ]] ++
264263
if detailLevel == MinimalDetails
265264
then []
@@ -279,10 +278,10 @@ newtype BuildToolDependency = BuildToolDependency { unBuildToolDependency :: Pac
279278
mkSysDep :: String -> SysDependency
280279
mkSysDep = SysDependency
281280

282-
instance ToNixExpr' GenericPackageDescription where
283-
toNix' detailLevel gpd = mkNonRecSet
281+
toNixGenericPackageDescription :: Bool -> CabalDetailLevel -> GenericPackageDescription -> NExpr
282+
toNixGenericPackageDescription isLocal detailLevel gpd = mkNonRecSet
284283
[ "flags" $= (mkNonRecSet . fmap toNixBinding $ genPackageFlags gpd)
285-
, "package" $= toNix' detailLevel (packageDescription gpd)
284+
, "package" $= toNixPackageDescription isLocal detailLevel (packageDescription gpd)
286285
, "components" $= components ]
287286
where _packageName :: IsString a => a
288287
_packageName = fromString . show . disp . pkgName . package . packageDescription $ gpd

nix-tools/plan2nix/Plan2Nix.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ plan2nix args (Plan { packages, extras, compilerVersion, compilerPackages }) = d
9090
src = Just . C2N.Path $ relPath </> ".." </> (shortRelativePath cwd folder)
9191
in do createDirectoryIfMissing True (takeDirectory nixFile)
9292
writeDoc nixFile =<<
93-
prettyNix <$> cabal2nix (argDetailLevel args) src cabalFile
93+
prettyNix <$> cabal2nix True (argDetailLevel args) src cabalFile
9494
return $ fromString pkg $= mkPath False nix
9595
(name, Just (Package v r flags (Just (DVCS (Git url rev) subdirs)))) ->
9696
fmap concat . forM subdirs $ \subdir ->
@@ -153,7 +153,7 @@ plan2nix args (Plan { packages, extras, compilerVersion, compilerPackages }) = d
153153
src = Just $ C2N.Git url rev (Just sha256) subdir'
154154
createDirectoryIfMissing True (takeDirectory nixFile)
155155
writeDoc nixFile =<<
156-
prettyNix <$> cabal2nix (argDetailLevel args) src cabalFile
156+
prettyNix <$> cabal2nix True (argDetailLevel args) src cabalFile
157157
liftIO $ appendCache (argCacheFile args) url rev subdir sha256 pkg nix
158158
return $ fromString pkg $= mkPath False nix
159159

nix-tools/stack2nix/Stack2nix.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ packages2nix args (Stack _ _ pkgs _) =
141141
src = Just . C2N.Path $ relPath </> folder
142142
in do createDirectoryIfMissing True (takeDirectory nixFile)
143143
writeDoc nixFile =<<
144-
prettyNix <$> cabal2nix (argDetailLevel args) src cabalFile
144+
prettyNix <$> cabal2nix True (argDetailLevel args) src cabalFile
145145
return $ fromString pkg $= mkPath False nix
146146
(DVCS (Git url rev) subdirs) ->
147147
fmap concat . forM subdirs $ \subdir ->
@@ -177,7 +177,7 @@ packages2nix args (Stack _ _ pkgs _) =
177177
src = Just $ C2N.Git url rev (Just sha256) subdir'
178178
createDirectoryIfMissing True (takeDirectory nixFile)
179179
writeDoc nixFile =<<
180-
prettyNix <$> cabal2nix (argDetailLevel args) src cabalFile
180+
prettyNix <$> cabal2nix True (argDetailLevel args) src cabalFile
181181
liftIO $ appendCache (argCacheFile args) url rev subdir sha256 pkg nix
182182
return $ fromString pkg $= mkPath False nix
183183

0 commit comments

Comments
 (0)