Skip to content

Commit 57939eb

Browse files
authored
Changes for source-repository-package handling (input-output-hk#107)
Changes needed to support improved handling of `source-repository-package` in `cabal.project`. Currently the `haskell.nix` `cabalProject` functions replace these with regular `packages:` pointing at the downloaded source and these are not treated the same by `cabal`. We are planning to change it so: * `haskell.nix` will use `git` to create local repos and a replacement `source-repoository-package`. * Once the `plan.json` is generated and `plan-to-nix ` has replace these the `/nix/store` paths (so that materialization can work). * Have the src mapped to `fetchgit` in haskell.nix. For this to work we need to be able to identify the `source-repository-packages`. This change added `url`, `rev` and `sha256` attributes to the `src` for `source-repository-packages`. It also fixes an issue where the `source-repository-package` is expected to be in `hackage` and allows fixes a problem with the cache if a `source-repository-package` did not have a sha256 provided (not needed if it is coming from `/nix/store`). Used by input-output-hk#1166
1 parent a640086 commit 57939eb

File tree

7 files changed

+21
-9
lines changed

7 files changed

+21
-9
lines changed

.buildkite/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.ghc883)' -o nt
20+
nix build '(let haskellNix = import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/hkm/use-source-repo.tar.gz") {}; in (import haskellNix.sources.nixpkgs haskellNix.nixpkgsArgs).haskell-nix.nix-tools.ghc8105)' -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

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ compiler-nix-name ? "ghc8104"
1+
{ compiler-nix-name ? "ghc8105"
22
}:
33
let
44
sources = import ./nix/sources.nix {};

lib/Cabal2Nix.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,13 @@ srcToNix _ (Git url rev mbSha256 mbPath)
235235
, "sha256" $= case mbSha256 of
236236
Just sha256 -> mkStr (fromString sha256)
237237
Nothing -> mkNull
238-
])
238+
]) $// mkNonRecSet
239+
[ "url" $= mkStr (fromString url)
240+
, "rev" $= mkStr (fromString rev)
241+
, "sha256" $= case mbSha256 of
242+
Just sha256 -> mkStr (fromString sha256)
243+
Nothing -> mkNull
244+
]
239245
] <>
240246
[ "postUnpack"
241247
$= mkStr (fromString $ "sourceRoot+=/" <> root <> "; echo source root reset to $sourceRoot")

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": "958e9d3e9ec53fbce72ac720b10a6418f3b477f0",
9-
"sha256": "0j9p3xyck636gv87rwd6yl7w9ssv3jwrfqyxvhpchszkj097qwi6",
8+
"rev": "920ac43ee13d95f56d7539bece1f5ee41b10c8a9",
9+
"sha256": "0px60yvag24ayj9zl82cbnpixm41slj2wqw4p2vgbwnbz125hgsx",
1010
"type": "tarball",
11-
"url": "https://github.com/input-output-hk/haskell.nix/archive/958e9d3e9ec53fbce72ac720b10a6418f3b477f0.tar.gz",
11+
"url": "https://github.com/input-output-hk/haskell.nix/archive/920ac43ee13d95f56d7539bece1f5ee41b10c8a9.tar.gz",
1212
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
1313
},
1414
"niv": {

plan2nix/Plan2Nix.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ value2plan plan = Plan { packages, extras, compilerVersion, compilerPackages }
180180
where
181181
packages = fmap Just $ filterInstallPlan $ \pkg -> case ( pkg ^. key "type" . _String
182182
, pkg ^. key "style" . _String) of
183+
-- source-repo packages will be included in `extras`. We do not need them
184+
-- in `packages` as well (this could lead to attribute not found errors looking
185+
-- for them in hackage).
186+
(_, _) | pkg ^. key "pkg-src" . key "type" . _String == "source-repo" -> Nothing
183187
(_, "global") -> Just $ Package
184188
{ packageVersion = pkg ^. key "pkg-version" . _String
185189
, packageRevision = Nothing

plan2nix/Plan2Nix/Cache.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ readCache :: FilePath
1717
)]
1818
readCache f = fmap (toTuple . words) . lines <$> readFile f
1919
where toTuple [ url, rev, subdir, sha256, pkgname, exprPath ]
20-
= ( url, rev, subdir, sha256, pkgname, exprPath )
20+
= ( url, rev, subdir, if sha256 == "NOHASH" then "" else sha256, pkgname, exprPath )
2121

22+
-- When we do not need a hash (when the files are local) we store "NOHASH" instead of ""
23+
-- in the file so that the use of `words` function in `readCache` still works.
2224
appendCache :: FilePath -> String -> String -> String -> String -> String -> String -> IO ()
2325
appendCache f url rev subdir sha256 pkgname exprPath = do
24-
appendFile f $ unwords [ url, rev, subdir, sha256, pkgname, exprPath ]
26+
appendFile f $ unwords [ url, rev, subdir, if null sha256 then "NOHASH" else sha256, pkgname, exprPath ]
2527
appendFile f "\n"
2628

2729
cacheHits :: FilePath -> String -> String -> String -> IO [ (String, String) ]

shell.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{ compiler-nix-name ? "ghc8104" }:
1+
{ compiler-nix-name ? "ghc8105" }:
22
(import ./. { inherit compiler-nix-name; }).shell
33

0 commit comments

Comments
 (0)