Skip to content

Commit

Permalink
Add haskell.nix to release.nix and shell.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
ymeister committed Sep 17, 2024
1 parent bef6f2d commit 21d6eda
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 82 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ hsenv.log
/ghci-tmp
*.dump-*
*.verbose-core2core
.nix
File renamed without changes.
8 changes: 8 additions & 0 deletions nix/deps/haskell.nix/github.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"owner": "input-output-hk",
"repo": "haskell.nix",
"branch": "master",
"private": false,
"rev": "d8c50dcaf3d3d589829ee9be9d5dba8279b8cc59",
"sha256": "0a5hgryz6nszmy67yf1aks399h2aw0nj845518c4prs5c6ns1z7p"
}
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions nix/deps/nix-haskell/github.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"owner": "ymeister",
"repo": "nix-haskell",
"branch": "main",
"private": false,
"rev": "6e8f6d87bda381f40461af5b8f7420fb58c5a1b3",
"sha256": "0scnj4rxfss574cik8bvd6d5xnk2n9jrkhmmfycyxaam8i3srcg6"
}
File renamed without changes.
2 changes: 2 additions & 0 deletions nix/deps/nixpkgs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DO NOT HAND-EDIT THIS FILE
import (import ./thunk.nix)
File renamed without changes.
12 changes: 12 additions & 0 deletions nix/deps/nixpkgs/thunk.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# DO NOT HAND-EDIT THIS FILE
let fetch = { private ? false, fetchSubmodules ? false, owner, repo, rev, sha256, ... }:
if !fetchSubmodules && !private then builtins.fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; inherit sha256;
} else (import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/3aad50c30c826430b0270fcf8264c8c41b005403.tar.gz";
sha256 = "0xwqsf08sywd23x0xvw4c4ghq0l28w2ki22h0bdn766i16z9q2gr";
}) {}).fetchFromGitHub {
inherit owner repo rev sha256 fetchSubmodules private;
};
json = builtins.fromJSON (builtins.readFile ./github.json);
in fetch json
2 changes: 2 additions & 0 deletions nix/deps/reflex-platform/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DO NOT HAND-EDIT THIS FILE
import (import ./thunk.nix)
File renamed without changes.
12 changes: 12 additions & 0 deletions nix/deps/reflex-platform/thunk.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# DO NOT HAND-EDIT THIS FILE
let fetch = { private ? false, fetchSubmodules ? false, owner, repo, rev, sha256, ... }:
if !fetchSubmodules && !private then builtins.fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; inherit sha256;
} else (import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/3aad50c30c826430b0270fcf8264c8c41b005403.tar.gz";
sha256 = "0xwqsf08sywd23x0xvw4c4ghq0l28w2ki22h0bdn766i16z9q2gr";
}) {}).fetchFromGitHub {
inherit owner repo rev sha256 fetchSubmodules private;
};
json = builtins.fromJSON (builtins.readFile ./github.json);
in fetch json
44 changes: 44 additions & 0 deletions nix/release/haskell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{ haskellNix ? ../deps/haskell.nix }:

let haskell = import ../deps/nix-haskell { inherit haskellNix; };
pkgs = haskell.pkgs;

platforms = [
"gnu64"
"ghcjs"
];
compilers = [
"ghc94"
"ghc96"
"ghc98"
"ghc910"
];

project = compiler: (haskell.project {
project = {
src = ../../.;
compiler-nix-name = compiler;
};
});

perCompiler = proj: with pkgs.lib; genAttrs compilers (compiler:
proj compiler
);
perPlatform = with pkgs.lib; genAttrs platforms (platform:
perCompiler (compiler: (project compiler).projectCross.${platform}.projectCoverageReport)
);

in with pkgs.lib; pkgs.runCommand "release" {} ''
mkdir -p $out
${
concatStringsSep "\n"
(forEach platforms (platform:
concatStringsSep "\n"
(forEach compilers (compiler: ''
mkdir -p "$out/${platform}"
ln -s "${perPlatform.${platform}.${compiler}}" "$out/${platform}/${compiler}"
''))
))
}
''
66 changes: 66 additions & 0 deletions nix/release/reflex-platform.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{ reflex-platform-fun ? import ../deps/reflex-platform
}:

let native-reflex-platform = reflex-platform-fun { __useNewerCompiler = true; };
inherit (native-reflex-platform.nixpkgs) lib;
systems = [
"x86_64-linux"
# "x86_64-darwin"
];

perPlatform = lib.genAttrs systems (system: let
srcFilter =
builtins.filterSource (path: type: !(builtins.elem (baseNameOf path) [
"release.nix"
".git"
"dist"
"dist-newstyle"
"cabal.haskell-ci"
"cabal.project"
".travis.yml"
]));
reflex-platform = reflex-platform-fun { inherit system; __useNewerCompiler = true; };
compilers = [
"ghc"
"ghcjs"
] ++ lib.optionals (reflex-platform.androidSupport) [
"ghcAndroidAarch64"
"ghcAndroidAarch32"
] ++ lib.optionals (reflex-platform.iosSupport) [
"ghcIosAarch64"
];
nixpkgsGhcs =
let
pkgs = import ../deps/nixpkgs { inherit system; };
nixGhc945 = pkgs.haskell.packages.ghc945.override {
};
nixGhc961 = pkgs.haskell.packages.ghc961.override {
};
in
{
ghc945 = nixGhc945.callCabal2nix "patch" srcFilter {};
ghc961 = nixGhc961.callCabal2nix "patch" srcFilter {};
};
compilerPkgs = lib.genAttrs compilers (ghc: let
reflex-platform = reflex-platform-fun {
inherit system;
__useNewerCompiler = true;
haskellOverlays = [
# Use this package's source for reflex
(self: super: {
_dep = super._dep // {
patch = srcFilter ../../.;
};
})
];
};
in reflex-platform.${ghc}.patch);
in compilerPkgs // nixpkgsGhcs // {
cache = reflex-platform.pinBuildInputs "patch-${system}"
(builtins.attrValues compilerPkgs);
});

metaCache = native-reflex-platform.pinBuildInputs "patch-everywhere"
(map (a: a.cache) (builtins.attrValues perPlatform));

in perPlatform // { inherit metaCache; }
12 changes: 12 additions & 0 deletions nix/shell/haskell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ haskellNix ? ../deps/haskell.nix }:

let haskell = import ../deps/nix-haskell { inherit haskellNix; };

project = haskell.project {
project = {
src = ../../.;
compiler-nix-name = "ghc910";
};
};

in project
15 changes: 15 additions & 0 deletions nix/shell/reflex-platform.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let
rp = import ../deps/reflex-platform { __useNewerCompiler = true; };
pkgs = rp.nixpkgs;
system = builtins.currentSystem;
in
pkgs.mkShell {
name = "shell";
buildInputs = [
pkgs.cabal-install
pkgs.ghcid
];
inputsFrom = [
(import ../release/reflex-platform.nix {}).${system}.ghc.env
];
}
67 changes: 8 additions & 59 deletions release.nix
Original file line number Diff line number Diff line change
@@ -1,62 +1,11 @@
{ reflex-platform-fun ? import ./dep/reflex-platform
}:
{ pkgs ? import <nixpkgs> {} }:

let
native-reflex-platform = reflex-platform-fun { __useNewerCompiler = true; };
inherit (native-reflex-platform.nixpkgs) lib;
systems = ["x86_64-linux"];
let reflex-platform-release = import ./nix/release/reflex-platform.nix {};
haskell-nix-release = import ./nix/release/haskell.nix {};

perPlatform = lib.genAttrs systems (system: let
reflex-platform = reflex-platform-fun { inherit system; __useNewerCompiler = true; };
compilers = [
"ghc"
"ghcjs"
] ++ lib.optionals (reflex-platform.androidSupport) [
"ghcAndroidAarch64"
"ghcAndroidAarch32"
] ++ lib.optionals (reflex-platform.iosSupport) [
"ghcIosAarch64"
];
nixpkgsGhcs =
let
pkgs = import ./nixpkgs { inherit system; };
nixGhc945 = pkgs.haskell.packages.ghc945.override {
};
nixGhc961 = pkgs.haskell.packages.ghc961.override {
};
in
{
ghc945 = nixGhc945.callCabal2nix "patch" (import ./src.nix) {};
ghc961 = nixGhc961.callCabal2nix "patch" (import ./src.nix) {};
};
compilerPkgs = lib.genAttrs compilers (ghc: let
reflex-platform = reflex-platform-fun {
inherit system;
__useNewerCompiler = true;
haskellOverlays = [
# Use this package's source for reflex
(self: super: {
_dep = super._dep // {
patch = builtins.filterSource (path: type: !(builtins.elem (baseNameOf path) [
"release.nix"
".git"
"dist"
"dist-newstyle"
"cabal.haskell-ci"
"cabal.project"
".travis.yml"
])) ./.;
};
})
];
};
in reflex-platform.${ghc}.patch);
in compilerPkgs // nixpkgsGhcs // {
cache = reflex-platform.pinBuildInputs "patch-${system}"
(builtins.attrValues compilerPkgs);
});
in pkgs.runCommand "release" {} ''
mkdir -p $out
metaCache = native-reflex-platform.pinBuildInputs "patch-everywhere"
(map (a: a.cache) (builtins.attrValues perPlatform));

in perPlatform // { inherit metaCache; }
ln -s ${reflex-platform-release.metaCache} $out/reflex-platform
ln -s ${haskell-nix-release} $out/haskell-nix
''
24 changes: 9 additions & 15 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
let
rp = import ./dep/reflex-platform { __useNewerCompiler = true; };
pkgs = rp.nixpkgs;
system = builtins.currentSystem;
in
pkgs.mkShell {
name = "shell";
buildInputs = [
pkgs.cabal-install
pkgs.ghcid
];
inputsFrom = [
(import ./release.nix {}).${system}.ghc.env
];
}
{ pkgs ? import <nixpkgs> {} }:

let reflex-platform-shell = import ./nix/shell/reflex-platform.nix;
haskell-nix-shell = import ./nix/shell/haskell.nix {};

in {
inherit reflex-platform-shell;
inherit haskell-nix-shell;
}
8 changes: 0 additions & 8 deletions src.nix

This file was deleted.

0 comments on commit 21d6eda

Please sign in to comment.