Skip to content

Commit

Permalink
Merge pull request #33 from Liqwid-Labs/seungheonoh/fixLongEval
Browse files Browse the repository at this point in the history
deprecating `haskell-nix-extra-hackage` and using `haskell.nix` tool
  • Loading branch information
emiflake authored Dec 12, 2022
2 parents 5eec525 + 790f0eb commit 3b77398
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 72 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

This format is based on [Keep A Changelog](https://keepachangelog.com/en/1.0.0).

## 2.0.1 -- 2022-12-12

- Vendored version of mkHackage instead of using now deprecated `haskell-nix-extra-hackage`.

- `hlint` and `haskell-language-server` provided using `tools` option of haskell.nix instead
of manually.

## 2.0.0 -- 2022-11-28

- Rework Nix system into using flake-parts.
Expand Down
55 changes: 7 additions & 48 deletions flake.lock

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

5 changes: 0 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
flake-parts.url = "github:hercules-ci/flake-parts";

# On-chain deps
haskell-nix-extra-hackage.url = "github:mlabs-haskell/haskell-nix-extra-hackage";
haskell-nix-extra-hackage.inputs.haskell-nix.follows = "haskell-nix";
haskell-nix-extra-hackage.inputs.nixpkgs.follows = "nixpkgs";
haskell-nix.url = "github:input-output-hk/haskell.nix?rev=cbf1e918b6e278a81c385155605b8504e498efef";
iohk-nix.url = "github:input-output-hk/iohk-nix?rev=4848df60660e21fbb3fe157d996a8bac0a9cf2d6";
iohk-nix.flake = false;

ghc-next-packages.url = "github:input-output-hk/ghc-next-packages?ref=repo";
ghc-next-packages.flake = false;

haskell-language-server.url = "github:haskell/haskell-language-server";
haskell-language-server.flake = false;
plutarch.url = "github:Plutonomicon/plutarch-plutus?ref=master";
};

Expand Down
133 changes: 133 additions & 0 deletions nix/mk-hackage.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{ liqwid-nix, system, pkgs, lib, ... }:
rec {
mkPackageSpec = src:
with lib;
let
cabalFiles = concatLists (mapAttrsToList
(name: type: if type == "regular" && hasSuffix ".cabal" name then [ name ] else [ ])
(builtins.readDir src));

cabalPath =
if length cabalFiles == 1
then src + "/${builtins.head cabalFiles}"
else builtins.abort "Could not find unique file with .cabal suffix in source: ${src}";
cabalFile = builtins.readFile cabalPath;
parse = field:
let
lines = filter (s: if builtins.match "^${field} *:.*$" (toLower s) != null then true else false) (splitString "\n" cabalFile);
line =
if lines != [ ]
then head lines
else builtins.abort "Could not find line with prefix ''${field}:' in ${cabalPath}";
in
replaceStrings [ " " ] [ "" ] (head (tail (splitString ":" line)));
pname = parse "name";
version = parse "version";
in
{ inherit src pname version; };

mkPackageTarball = { pname, version, src }:
pkgs.runCommand "${pname}-${version}.tar.gz" { } ''
tar --sort=name --owner=Hackage:0 --group=Hackage:0 --mtime='UTC 2009-01-01' -czvf $out ${src}
'';

mkHackageDir = { pname, version, src }@spec:
pkgs.runCommand "${pname}-${version}-hackage"
{ } ''
set -e
mkdir -p $out/${pname}/${version}
md5=11111111111111111111111111111111
sha256=1111111111111111111111111111111111111111111111111111111111111111
length=1
cat <<EOF > $out/"${pname}"/"${version}"/package.json
{
"signatures" : [],
"signed" : {
"_type" : "Targets",
"expires" : null,
"targets" : {
"<repo>/package/${pname}-${version}.tar.gz" : {
"hashes" : {
"md5" : "$md5",
"sha256" : "$sha256"
},
"length" : $length
}
},
"version" : 0
}
}
EOF
cp ${src}/*.cabal $out/"${pname}"/"${version}"/
'';

mkHackageTarballFromDirs = hackageDirs:
pkgs.runCommand "01-index.tar.gz" { } ''
mkdir hackage
${builtins.concatStringsSep "" (map (dir: ''
echo ${dir}
ln -s ${dir}/* hackage/
'') hackageDirs)}
cd hackage
tar --sort=name --owner=root:0 --group=root:0 --mtime='UTC 2009-01-01' -hczvf $out */*/*
'';

mkHackageTarball = pkg-specs:
mkHackageTarballFromDirs (map mkHackageDir pkg-specs);

mkHackageNix = compiler-nix-name: hackageTarball:
pkgs.runCommand "hackage-nix" { } ''
set -e
export LC_CTYPE=C.UTF-8
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
cp ${hackageTarball} 01-index.tar.gz
${pkgs.gzip}/bin/gunzip 01-index.tar.gz
${pkgs.haskell-nix.nix-tools.${compiler-nix-name}}/bin/hackage-to-nix $out 01-index.tar "https://mkHackageNix/"
'';

copySrc = src: pkgs.runCommand "copied-src-${builtins.baseNameOf src}"
{
__contentAddressed = true;
} ''
cp -T -r ${src} $out
'';

mkModule = extraHackagePackages: {
# Prevent nix-build from trying to download the packages
packages = lib.listToAttrs (map
(spec: {
name = spec.pname;
value = { src = lib.mkOverride 99 (copySrc spec.src); };
})
extraHackagePackages);
};

mkHackageFromSpec = compiler-nix-name: extraHackagePackages: rec {
extra-hackage-tarball = mkHackageTarball extraHackagePackages;
extra-hackage = mkHackageNix compiler-nix-name extra-hackage-tarball;
module = mkModule extraHackagePackages;
};

mkHackage = compiler-nix-name: srcs:
let
# from mlabs-tooling.nix.
hackages = [ (mkHackageFromSpec compiler-nix-name (map mkPackageSpec srcs)) ];
ifd-parallel =
pkgs.runCommandNoCC "ifd-parallel"
{ myInputs = builtins.foldl' (b: a: b ++ [ a.extra-hackage a.extra-hackage-tarball ]) [ ] hackages; }
"echo $myInputs > $out";
ifdseq = x: builtins.seq (builtins.readFile ifd-parallel.outPath) x;
in
{
modules = ifdseq (builtins.map (x: x.module) hackages);
extra-hackage-tarballs = ifdseq (
lib.listToAttrs (lib.imap0
(i: x: {
name = "_" + builtins.toString i;
value = x.extra-hackage-tarball;
})
hackages));
extra-hackages = ifdseq (builtins.map (x: import x.extra-hackage) hackages);
};
}
25 changes: 6 additions & 19 deletions nix/onchain.nix
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ in
inherit (pkgs) haskell-nix;

utils = import ./utils.nix { inherit pkgs lib; };
hackageUtils = import ./mk-hackage.nix { inherit liqwid-nix system pkgs lib; };
makeProject = projectName: projectConfig:
let

Expand Down Expand Up @@ -233,7 +234,7 @@ in
] ++ projectConfig.extraHackageDeps;

customHackages =
liqwid-nix.haskell-nix-extra-hackage.mkHackagesFor system
hackageUtils.mkHackage
projectConfig.ghc.version
hackageDeps;

Expand Down Expand Up @@ -279,30 +280,13 @@ in
})
];

hls' =
haskell-nix.cabalProject' {
modules = [{
inherit nonReinstallablePkgs;
reinstallableLibGhc = false;
}];

compiler-nix-name = projectConfig.ghc.version;
src = "${liqwid-nix.haskell-language-server}";
sha256map."https://github.com/pepeiborra/ekg-json"."7a0af7a8fd38045fd15fb13445bdcc7085325460" =
"fVwKxGgM0S4Kv/4egVAAiAjV7QB5PBqMVMCfsv7otIQ=";
};
hls =
hls'.hsPkgs.haskell-language-server.components.exes.haskell-language-server;

commandLineTools =
[
pkgs-latest.cabal-install
hlint
cabalFmt
fourmolu
nixpkgsFmt
hasktags
hls
pkgs-latest.fd
pkgs-latest.entr
applyRefact
Expand All @@ -317,6 +301,10 @@ in
shell = {
withHoogle = true;
exactDeps = true;
tools = {
hlint = { };
haskell-language-server = { };
};
nativeBuildInputs = commandLineTools;
shellHook = ''
liqwid(){ c=$1; shift; nix run .#$c -- $@; }
Expand Down Expand Up @@ -536,4 +524,3 @@ in
};
};
}

0 comments on commit 3b77398

Please sign in to comment.