Initial commit

This commit is contained in:
iko 2021-12-20 12:37:52 +03:00
parent e09c2d62ec
commit 10ad2cc4e7
Signed by untrusted user: iko
GPG Key ID: 82C257048D1026F2
2 changed files with 114 additions and 0 deletions

46
README.md Normal file
View File

@ -0,0 +1,46 @@
# ❄️ haskell.nix extra Hackage
## How to use it
I suggest you manage dependencies with [niv](https://github.com/nmattia/niv):
```shell
niv add ilyakooo0/haskell-nix-extra-hackage
```
After you import this repo and pass `pkgs`, you can pass a list of package sources that you want to overrides. You then need to add the attribute set to your `haskell.nix` config:
```nix
{ sources ? import ./nix/sources.nix
, haskellNix ? import sources.haskellNix { }
, pkgsSrc ? import haskellNix.sources.nixpkgs-2105
, pkgs ? pkgsSrc (haskellNix.nixpkgsArgs // { })
}:
let
mkHackage = import sources.haskell-nix-extra-hackage { inherit pkgs; };
hsPkgs = pkgs.haskell-nix.cabalProject ({
src = ./.;
index-state = "2021-11-22T00:00:00Z";
compiler-nix-name = "ghc8107";
}
// (mkHackage [
{ src = sources.reflex-dom + "/reflex-dom"; name = "reflex-dom"; }
{ src = sources.reflex-dom + "/reflex-dom-core"; name = "reflex-dom-core"; }
{ src = sources.servant-reflex; name = "servant-reflex"; }
{ src = sources.reflex; name = "reflex"; }
{ src = sources.patch; name = "patch"; }
{ src = sources.jsaddle + "/jsaddle"; name = "jsaddle"; }
{ src = sources.monoidal-containers + "/monoidal-containers"; name = "monoidal-containers"; }
])
);
in
hsPkgs
```
## Precautions
1. You should really only use this for packages that are only in Hackage. If a package is not in Hackage, you I suggest you use `source-repository-package` in `cabal.project`.
2. Only one version of the package is overridden. All other version are left the way they are. For this reason you should probably contraint the versions of packages you override to the specific version you use.

68
default.nix Normal file
View File

@ -0,0 +1,68 @@
{ pkgs }:
# [{ name, src, cabal-file ? "${name}.cabal" }]
pkgSrcs:
let
undefined = builtins.abort "undefined";
mockInput = {
system = undefined;
compiler = undefined;
flags = undefined;
pkgs = undefined;
hsPkgs = undefined;
pkgconfPkgs = undefined;
errorHandler = undefined;
config = undefined;
};
mkPkg = p: {
out = pkgs.haskell-nix.callCabalToNix p;
inherit p;
};
hPkgs = builtins.map mkPkg pkgSrcs;
hPkgsReady = builtins.map
({ p, out }:
let mockPkg = import out mockInput; in
{
"${mockPkg.package.identifier.name}" = {
"${mockPkg.package.identifier.version}" =
{
# this is fine since the path contains the hash
sha256 = builtins.hashString "sha256" (toString p.src);
revisions =
let rev = {
outPath = out;
revNum = 0;
sha256 = builtins.hashFile "sha256" "${p.src}/${p.cabal-file or "${p.name}.cabal"}";
};
in
{ r0 = rev; default = rev; };
};
};
})
hPkgs;
index = pkgs.runCommand "index.tar.gz" { } ''
${ builtins.concatStringsSep "\n"
(builtins.map ({p, out}:
let mockPkg = import out mockInput;
d = "${mockPkg.package.identifier.name}/${mockPkg.package.identifier.version}/";
in ''
mkdir -p ${d}
echo '{"signatures":[],"signed":{"_type":"Targets","expires":null,"targets":{"<repo>/package/${mockPkg.package.identifier.name}-${mockPkg.package.identifier.version}.tar.gz":{"hashes":{"md5":"","sha256":""},"length":0}},"version":0}}' > ${d}/package.json
cp "${p.src}/${p.cabal-file or "${p.name}.cabal"}" ${d}
'')
hPkgs)
}
find . -type f | xargs touch -m -a -t 7101010000
find . -type f -printf '%P\n' | xargs tar czf $out
'';
in
{
extra-hackages = [ (pkgs.lib.foldl (a: b: a // b) { } hPkgsReady) ];
extra-hackage-tarballs = [
{
name = "local-package-overrides-hackage";
inherit index;
}
];
}