Skip to content

Commit 1d0000c

Browse files
authored
Update for Cabal 3.6.2 and hnix 0.16 (#113)
1 parent ed5bd72 commit 1d0000c

File tree

12 files changed

+61
-40
lines changed

12 files changed

+61
-40
lines changed

.buildkite/build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env nix-shell
2-
#! nix-shell -I "nixpkgs=channel:nixos-20.03" --pure -i bash -p nix cabal-install ghc git nix-prefetch-git cacert
2+
#! nix-shell -I "nixpkgs=channel:nixos-21.11" --pure -i bash -p nixUnstable cabal-install ghc git nix-prefetch-git cacert
33

4-
export NIX_PATH="nixpkgs=channel:nixos-20.03"
4+
export NIX_PATH="nixpkgs=channel:nixos-21.11"
55
index_state="2020-01-10T00:00:00Z"
66
expected_hash="0z2jc4fibfxz88pfgjq3wk5j3v7sn34xkwb8h60hbwfwhhy63vx6"
77

@@ -17,7 +17,7 @@ cabal new-configure
1717

1818
echo
1919
echo "+++ Run stable version of plan-to-nix"
20-
nix build '(let haskellNix = import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz") {}; in (import haskellNix.sources.nixpkgs haskellNix.nixpkgsArgs).haskell-nix.nix-tools.ghc8105)' -o nt
20+
nix build --impure --expr '(let haskellNix = import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz") {}; in (import haskellNix.sources.nixpkgs haskellNix.nixpkgsArgs).haskell-nix.nix-tools.ghc8107)' -o nt
2121
./nt/bin/plan-to-nix --output .buildkite/nix1 --plan-json dist-newstyle/cache/plan.json
2222

2323
# Replace currently broken plan-to-nix output

cabal.project

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
index-state: 2021-11-03T00:00:00Z
1+
index-state: 2022-02-02T00:00:00Z
22

33
packages: .
44

5+
allow-newer: hackage-db:Cabal, hpack:Cabal
6+
57
source-repository-package
68
type: git
79
location: https://github.com/hamishmack/hackage-db.git

default.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ in
88
pkgs.haskell-nix.cabalProject {
99
inherit compiler-nix-name;
1010
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; name = "nix-tools"; };
11+
modules = [
12+
{ nonReinstallablePkgs =
13+
[ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base"
14+
"deepseq" "array" "ghc-boot-th" "pretty" "template-haskell"
15+
"ghc-boot"
16+
"ghc" "Win32" "array" "binary" "bytestring" "containers"
17+
"directory" "filepath" "ghc-boot" "ghc-compact" "ghc-prim"
18+
"hpc"
19+
"mtl" "parsec" "process" "text" "time" "transformers"
20+
"unix" "xhtml"
21+
];
22+
}
23+
];
1124
shell = {
1225
tools.cabal = {};
1326
buildInputs = [

lib/Cabal2Nix.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Distribution.PackageDescription.Parsec (readGenericPackageDescription, pa
99
import Distribution.Verbosity (normal)
1010
import Distribution.Pretty (pretty)
1111
import Distribution.Utils.ShortText (fromShortText)
12+
import Distribution.Utils.Path (getSymbolicPath)
1213
import Data.Char (toUpper)
1314
import System.FilePath
1415
import Data.ByteString (ByteString)
@@ -177,7 +178,7 @@ class ToNixBinding a where
177178
toNixBinding :: a -> Binding NExpr
178179

179180
applyMkDefault :: NExpr -> NExpr
180-
applyMkDefault expr = mkSym pkgs @. "lib" @. "mkDefault" @@ expr
181+
applyMkDefault expr = (mkSym pkgs @. "lib") @. "mkDefault" @@ expr
181182

182183
instance ToNixExpr PackageIdentifier where
183184
toNix ident = mkNonRecSet [ "name" $= mkStr (fromString (show (pretty (pkgName ident))))
@@ -208,7 +209,7 @@ toNixPackageDescription isLocal detailLevel pd = mkNonRecSet $
208209
then []
209210
else
210211
[ "detailLevel" $= mkStr (fromString (show detailLevel))
211-
, "licenseFiles" $= toNix (licenseFiles pd)
212+
, "licenseFiles" $= toNix (map getSymbolicPath (licenseFiles pd))
212213
, "dataDir" $= mkStr (fromString (dataDir pd))
213214
, "dataFiles" $= toNix (dataFiles pd)
214215
, "extraSrcFiles" $= toNix (extraSrcFiles pd)
@@ -287,7 +288,7 @@ toNixGenericPackageDescription isLocal detailLevel gpd = mkNonRecSet
287288
[ "cSources" $= toNix src | Just src <- [shakeTree . fmap (cSources . getBuildInfo) $ comp ] ] ++
288289
[ "cxxSources" $= toNix src | Just src <- [shakeTree . fmap (cxxSources . getBuildInfo) $ comp ] ] ++
289290
[ "jsSources" $= toNix src | Just src <- [shakeTree . fmap (jsSources . getBuildInfo) $ comp ] ] ++
290-
[ "hsSourceDirs" $= toNix dir | Just dir <- [shakeTree . fmap (hsSourceDirs . getBuildInfo) $ comp ] ] ++
291+
[ "hsSourceDirs" $= toNix (fmap getSymbolicPath <$> dir) | Just dir <- [shakeTree . fmap (hsSourceDirs . getBuildInfo) $ comp ] ] ++
291292
[ "includeDirs" $= toNix dir | Just dir <- [shakeTree . fmap (includeDirs . getBuildInfo) $ comp] ] ++
292293
[ "includes" $= toNix dir | Just dir <- [shakeTree . fmap (includes . getBuildInfo) $ comp] ] ++
293294
[ "mainPath" $= toNix p | Just p <- [shakeTree . fmap (maybeToList . getMainPath) $ comp] ])
@@ -402,11 +403,11 @@ instance ToNixExpr CompilerFlavor where
402403

403404
instance ToNixExpr (VersionRangeF VersionRange) where
404405
toNix (OrLaterVersionF ver) | ver == version0 = mkBool True
405-
toNix (ThisVersionF ver) = mkSym "compiler" @. "version" @. "eq" @@ mkStr (fromString (show (pretty ver)))
406-
toNix (LaterVersionF ver) = mkSym "compiler" @. "version" @. "gt" @@ mkStr (fromString (show (pretty ver)))
407-
toNix (OrLaterVersionF ver) = mkSym "compiler" @. "version" @. "ge" @@ mkStr (fromString (show (pretty ver)))
408-
toNix (EarlierVersionF ver) = mkSym "compiler" @. "version" @. "lt" @@ mkStr (fromString (show (pretty ver)))
409-
toNix (OrEarlierVersionF ver) = mkSym "compiler" @. "version" @. "le" @@ mkStr (fromString (show (pretty ver)))
406+
toNix (ThisVersionF ver) = (mkSym "compiler" @. "version") @. "eq" @@ mkStr (fromString (show (pretty ver)))
407+
toNix (LaterVersionF ver) = (mkSym "compiler" @. "version") @. "gt" @@ mkStr (fromString (show (pretty ver)))
408+
toNix (OrLaterVersionF ver) = (mkSym "compiler" @. "version") @. "ge" @@ mkStr (fromString (show (pretty ver)))
409+
toNix (EarlierVersionF ver) = (mkSym "compiler" @. "version") @. "lt" @@ mkStr (fromString (show (pretty ver)))
410+
toNix (OrEarlierVersionF ver) = (mkSym "compiler" @. "version") @. "le" @@ mkStr (fromString (show (pretty ver)))
410411
toNix (MajorBoundVersionF ver) = toNix (IntersectVersionRangesF (orLaterVersion ver) (earlierVersion (majorUpperBound ver)))
411412
toNix (IntersectVersionRangesF v1 v2) = toNix (projectVersionRange v1) $&& toNix (projectVersionRange v2)
412413
toNix x = error $ "ToNixExpr VersionRange for `" ++ show x ++ "` not implemented!"
@@ -420,8 +421,8 @@ instance ToNixExpr a => ToNixExpr (Condition a) where
420421

421422
instance (Foldable t, ToNixExpr (t a), ToNixExpr v, ToNixExpr c) => ToNixExpr (CondBranch v c (t a)) where
422423
toNix (CondBranch c t Nothing) = case toNix t of
423-
(Fix (NList [e])) -> mkSym pkgs @. "lib" @. "optional" @@ toNix c @@ e
424-
e -> mkSym pkgs @. "lib" @. "optionals" @@ toNix c @@ e
424+
(Fix (NList [e])) -> (mkSym pkgs @. "lib") @. "optional" @@ toNix c @@ e
425+
e -> (mkSym pkgs @. "lib") @. "optionals" @@ toNix c @@ e
425426
toNix (CondBranch _c t (Just f)) | toNix t == toNix f = toNix t
426427
toNix (CondBranch c t (Just f)) = mkIf (toNix c) (toNix t) (toNix f)
427428

lib/Cabal2Nix/Plan.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data Plan = Plan
2626
data Package = Package
2727
{ packageVersion :: Version
2828
, packageRevision :: Maybe Revision
29-
, packageFlags :: HashMap Text Bool
29+
, packageFlags :: HashMap VarName Bool
3030
}
3131

3232
plan2nix :: Plan -> NExpr
@@ -42,15 +42,17 @@ plan2nix (Plan { packages, compilerVersion, compilerPackages }) =
4242
]
4343
where
4444
quotedPackages = mapKeys quoted packages
45+
bind :: Text -> Maybe Package -> [Binding NExpr]
4546
bind pkg (Just (Package { packageVersion, packageRevision, packageFlags })) =
46-
let verExpr = mkSym "hackage" @. pkg @. quoted packageVersion
47-
revExpr = verExpr @. "revisions" @. maybe "default" quoted packageRevision
47+
let verExpr = (mkSym "hackage" @. pkg) @. quoted packageVersion
48+
revExpr = (verExpr @. "revisions") @. maybe "default" quoted packageRevision
4849
flagBindings = Map.foldrWithKey
49-
(\fname val acc -> bindPath (pkg :| ["flags", fname]) (mkBool val) : acc)
50+
(\fname val acc -> bindPath (VarName pkg :| ["flags", fname]) (mkBool val) : acc)
5051
[]
5152
packageFlags
5253
in revBinding pkg revExpr : flagBindings
5354
bind pkg Nothing = [revBinding pkg mkNull]
54-
revBinding pkg revExpr = bindPath (pkg :| ["revision"]) revExpr
55+
revBinding :: Text -> NExpr -> Binding NExpr
56+
revBinding pkg revExpr = bindPath (VarName pkg :| ["revision"]) revExpr
5557
bind' pkg ver = pkg $= maybe mkNull mkStr ver
5658
mapKeys f = Map.fromList . fmap (\(k, v) -> (f k, v)) . Map.toList

lib/Cabal2Nix/Util.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ quoted :: (IsString a, Semigroup a) => a -> a
2525
quoted str = "\"" <> str <> "\""
2626

2727
selectOr :: NExpr -> NAttrPath NExpr -> NExpr -> NExpr
28-
selectOr obj path alt = Fix (NSelect obj path (Just $ alt))
28+
selectOr obj path alt = Fix (NSelect (Just $ alt) obj path)
2929

3030
mkThrow :: NExpr -> NExpr
3131
mkThrow msg = (mkSym "builtins" @. "throw") @@ msg
3232

3333
sha256 :: String -> String
3434
sha256 = unpack . Base16.encode . hash . pack
3535

36-
bindPath :: NonEmpty Text -> NExpr -> Binding NExpr
36+
bindPath :: NonEmpty VarName -> NExpr -> Binding NExpr
3737
bindPath ks e = NamedVar (fmap StaticKey ks) e nullPos

lib/Stack2nix.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ stack2nix args (Stack resolver compiler pkgs pkgFlags ghcOpts) =
107107
extraDeps2nix :: [Dependency] -> [(T.Text, Binding NExpr)]
108108
extraDeps2nix pkgs =
109109
let extraDeps = [(pkgId, info) | PkgIndex pkgId info <- pkgs]
110-
in [ (toText pkg, quoted (toText pkg) $= (mkSym "hackage" @. toText pkg @. quoted (toText ver) @. "revisions" @. "default"))
110+
in [ (toText pkg, quoted (toText pkg) $= ((((mkSym "hackage" @. toText pkg) @. quoted (toText ver)) @. "revisions") @. "default"))
111111
| (PackageIdentifier pkg ver, Nothing) <- extraDeps ]
112-
++ [ (toText pkg, quoted (toText pkg) $= (mkSym "hackage" @. toText pkg @. quoted (toText ver) @. "revisions" @. quoted (T.pack sha)))
112+
++ [ (toText pkg, quoted (toText pkg) $= ((((mkSym "hackage" @. toText pkg) @. quoted (toText ver)) @. "revisions") @. quoted (T.pack sha)))
113113
| (PackageIdentifier pkg ver, (Just (Left sha))) <- extraDeps ]
114-
++ [ (toText pkg, quoted (toText pkg) $= (mkSym "hackage" @. toText pkg @. quoted (toText ver) @. "revisions" @. toText revNo))
114+
++ [ (toText pkg, quoted (toText pkg) $= ((((mkSym "hackage" @. toText pkg) @. quoted (toText ver)) @. "revisions") @. toText revNo))
115115
| (PackageIdentifier pkg ver, (Just (Right revNo))) <- extraDeps ]
116116
where parsePackageIdentifier :: String -> Maybe PackageIdentifier
117117
parsePackageIdentifier = simpleParse

lts2nix/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ lts2plan compilerPackagesMap lts = Plan { packages, compilerVersion, compilerPac
7676
, packageRevision = case rev of
7777
Just (Left sha) -> Just $ Text.pack sha
7878
_ -> Nothing
79-
, packageFlags = Map.lookupDefault Map.empty name flags
79+
, packageFlags = Map.mapKeys VarName $ Map.lookupDefault Map.empty name flags
8080
})
8181

8282
packages = packages' `Map.union` compilerPackages'

nix-tools.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ library
2929
, Stack2nix.Project
3030
, Stack2nix.Stack
3131
build-depends: base >=4 && <4.15
32-
, Cabal >= 3.4 && <3.5
32+
, Cabal >= 3.6.2 && <3.7
3333
, aeson >= 2.0.0.0
3434
, aeson-pretty
3535
, base16-bytestring

nix/sources.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"homepage": "https://input-output-hk.github.io/haskell.nix",
66
"owner": "input-output-hk",
77
"repo": "haskell.nix",
8-
"rev": "b969bc1b681bddc14d70f14c0dd26ee567fc4464",
9-
"sha256": "0k82j1ndq3rfvznwgvy7qlpm689q0r0619iv4zqp9pbs0ashn6id",
8+
"rev": "355cd3701db115b494b13dbb613175345df059ed",
9+
"sha256": "0lvwnva4g3wjmqpzj9cny7v1wrya4kq5617zxz61fhjhf8z79wk6",
1010
"type": "tarball",
11-
"url": "https://github.com/input-output-hk/haskell.nix/archive/b969bc1b681bddc14d70f14c0dd26ee567fc4464.tar.gz",
11+
"url": "https://github.com/input-output-hk/haskell.nix/archive/355cd3701db115b494b13dbb613175345df059ed.tar.gz",
1212
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
1313
},
1414
"niv": {

plan2nix/Plan2Nix.hs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,18 @@ plan2nix args (Plan { packages, extras, components, compilerVersion, compilerPac
134134
]
135135
where
136136
quotedPackages = mapKeys quoted packages
137+
bind :: Text -> Maybe Package -> [Binding NExpr]
137138
bind pkg (Just (Package { packageVersion, packageRevision, packageFlags })) =
138-
let verExpr = mkSym "hackage" @. pkg @. quoted packageVersion
139-
revExpr = verExpr @. "revisions" @. maybe "default" quoted packageRevision
139+
let verExpr = (mkSym "hackage" @. pkg) @. quoted packageVersion
140+
revExpr = (verExpr @. "revisions") @. maybe "default" quoted packageRevision
140141
flagBindings = Map.foldrWithKey
141-
(\fname val acc -> bindPath (pkg :| ["flags", fname]) (mkBool val) : acc)
142+
(\fname val acc -> bindPath (VarName pkg :| ["flags", fname]) (mkBool val) : acc)
142143
[]
143144
packageFlags
144145
in revBinding pkg revExpr : flagBindings
145146
bind pkg Nothing = [revBinding pkg mkNull]
146-
revBinding pkg revExpr = bindPath (pkg :| ["revision"]) revExpr
147+
revBinding :: Text -> NExpr -> Binding NExpr
148+
revBinding pkg revExpr = bindPath (VarName pkg :| ["revision"]) revExpr
147149
bind' pkg ver = pkg $= maybe mkNull mkStr ver
148150
mapKeys f = Map.fromList . fmap (\(k, v) -> (f k, v)) . Map.toList
149151

@@ -173,13 +175,13 @@ plan2nix args (Plan { packages, extras, components, compilerVersion, compilerPac
173175
return $ fromString pkg $= mkPath False nix
174176

175177
-- | Converts the project flags for a package flags into @{ packageName = { flags = { flagA = BOOL; flagB = BOOL; }; }; }@
176-
flags2nix :: Text -> HashMap Text Bool -> [Binding NExpr]
178+
flags2nix :: Text -> HashMap VarName Bool -> [Binding NExpr]
177179
flags2nix pkgName pkgFlags =
178180
[ quoted pkgName $= mkNonRecSet
179181
-- `mkOverride 900` is used here so that the default values will be replaced (they are 1000).
180182
-- Values without a priority are treated as 100 and will replace these ones.
181183
[ "flags" $= mkNonRecSet [ quoted flag $= ("lib" @. "mkOverride" @@ mkInt 900 @@ mkBool val)
182-
| (flag, val) <- Map.toList pkgFlags
184+
| (VarName flag, val) <- Map.toList pkgFlags
183185
]
184186
]
185187
]
@@ -196,13 +198,13 @@ value2plan plan = Plan { packages, components, extras, compilerVersion, compiler
196198
(_, "global") -> Just $ Package
197199
{ packageVersion = pkg ^. key "pkg-version" . _String
198200
, packageRevision = Nothing
199-
, packageFlags = Map.mapMaybe (^? _Bool) $ pkg ^. key "flags" . _Object
201+
, packageFlags = Map.mapKeys VarName $ Map.mapMaybe (^? _Bool) $ pkg ^. key "flags" . _Object
200202
, packageSrc = Nothing
201203
}
202204
(_, "inplace") -> Just $ Package
203205
{ packageVersion = pkg ^. key "pkg-version" . _String
204206
, packageRevision = Nothing
205-
, packageFlags = Map.mapMaybe (^? _Bool) $ pkg ^. key "flags" . _Object
207+
, packageFlags = Map.mapKeys VarName $ Map.mapMaybe (^? _Bool) $ pkg ^. key "flags" . _Object
206208
, packageSrc = Nothing
207209
}
208210
-- Until we figure out how to force Cabal to reconfigure just about any package
@@ -224,13 +226,13 @@ value2plan plan = Plan { packages, components, extras, compilerVersion, compiler
224226
("local", "local") -> Just $ Package
225227
{ packageVersion = pkg ^. key "pkg-version" . _String
226228
, packageRevision = Nothing
227-
, packageFlags = Map.mapMaybe (^? _Bool) $ pkg ^. key "flags" . _Object
229+
, packageFlags = Map.mapKeys VarName $ Map.mapMaybe (^? _Bool) $ pkg ^. key "flags" . _Object
228230
, packageSrc = Just . LocalPath . Text.unpack $ pkg ^. key "pkg-src" . key "path" . _String
229231
}
230232
(_, "source-repo") -> Just $ Package
231233
{ packageVersion = pkg ^. key "pkg-version" . _String
232234
, packageRevision = Nothing
233-
, packageFlags = Map.mapMaybe (^? _Bool) $ pkg ^. key "flags" . _Object
235+
, packageFlags = Map.mapKeys VarName $ Map.mapMaybe (^? _Bool) $ pkg ^. key "flags" . _Object
234236
, packageSrc = Just . flip DVCS [ Text.unpack $ fromMaybe "." $ pkg ^? key "pkg-src" . key "source-repo" . key "subdir" . _String ] $
235237
Git ( Text.unpack $ pkg ^. key "pkg-src" . key "source-repo" . key "location" . _String )
236238
( Text.unpack $ pkg ^. key "pkg-src" . key "source-repo" . key "tag" . _String )

plan2nix/Plan2Nix/Plan.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Plan2Nix.Plan
1515
import Data.Text ( Text )
1616
import Data.HashMap.Strict ( HashMap )
1717
import Data.HashSet ( HashSet )
18+
import Nix.Expr
1819

1920
type Version = Text
2021
type Revision = Text -- Can be: rNUM, cabal file sha256, or "default"
@@ -44,6 +45,6 @@ data PkgSrc
4445
data Package = Package
4546
{ packageVersion :: Version
4647
, packageRevision :: Maybe Revision
47-
, packageFlags :: HashMap Text Bool
48+
, packageFlags :: HashMap VarName Bool
4849
, packageSrc :: Maybe PkgSrc
4950
} deriving (Show)

0 commit comments

Comments
 (0)