Skip to content

Instantly share code, notes, and snippets.

@jaspervdj
Last active June 16, 2023 21:29
Show Gist options
  • Save jaspervdj/f348748276497788530b156f5bb652c3 to your computer and use it in GitHub Desktop.
Save jaspervdj/f348748276497788530b156f5bb652c3 to your computer and use it in GitHub Desktop.
reproducibly build a docker image for tryhaskell
{ }:
let
pkgs = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/17.03.tar.gz) { };
exactOverride = self: pkg: version: pkgs.haskell.lib.dontCheck (self.callCabal2nix
pkg
(builtins.fetchTarball {
url = "https://hackage.haskell.org/package/${pkg}-${version}/${pkg}-${version}.tar.gz";
})
{ }
);
haskellPackages = pkgs.haskell.packages.ghc783.override {
overrides = self: super: rec {
bifunctors = pkgs.haskell.lib.dontCheck super.bifunctors;
aeson = exactOverride self "aeson" "0.8.0.2";
attoparsec = exactOverride self "attoparsec" "0.12.1.2";
blaze-builder = exactOverride self "blaze-builder" "0.3.3.4";
blaze = exactOverride self "blaze" "0.0.1";
case-insensitive = exactOverride self "case-insensitive" "1.2.0.1";
comonad = exactOverride self "comonad" "4.2.2";
distributive = exactOverride self "distributive" "0.5.2";
lucid = exactOverride self "lucid" "2.9.4";
network = exactOverride self "network" "2.5.0.0";
primitive = exactOverride self "primitive" "0.5.4.0";
QuickCheck = exactOverride self "QuickCheck" "2.5.1";
scientific = exactOverride self "scientific" "0.3.3.1";
snap-core = exactOverride self "snap-core" "0.9.6.3";
snap-server = exactOverride self "snap-server" "0.9.4.5";
text = exactOverride self "text" "1.1.1.3";
unordered-containers = exactOverride self "unordered-containers" "0.2.5.1";
vector = exactOverride self "vector" "0.10.12.1";
};
};
tryhaskell = pkgs.fetchFromGitHub {
owner = "chrisdone";
repo = "tryhaskell";
rev = "495fb190a7711ca4d3dea6ae9eac051cf0a89235";
sha256 = "sha256-02snXbcAXvAiEwFPv69aZKsdPF4dL+3joAx7vk5emDc=";
};
runtime = haskellPackages.ghcWithPackages (p: [
p.mtl p.QuickCheck p.show p.simple-reflect p.pure-io
(pkgs.haskell.lib.justStaticExecutables (pkgs.haskell.lib.dontCheck (
haskellPackages.callCabal2nix "tryhaskell" tryhaskell { }
)))
(pkgs.haskell.lib.justStaticExecutables p.mueval)
]);
dockerTools = (import (fetchTarball https://github.com/NixOS/nixpkgs/archive/23.05.tar.gz) { }).dockerTools;
alpine = dockerTools.pullImage {
imageName = "alpine";
imageDigest = "sha256:69e70a79f2d41ab5d637de98c1e0b055206ba40a8145e7bddb55ccc04e13cf8f";
sha256 = "13p8046wx8isw4pi57xaxgrn11d92ql30p0lss090wcaliv7rjmc";
};
in
dockerTools.buildImage {
name = "tryhaskell";
fromImage = alpine;
copyToRoot = pkgs.buildEnv {
name = "runtime";
paths = [ runtime ];
pathsToLink = [ "/bin" "/lib/ghc-${haskellPackages.ghc.version}" ];
};
config = {
ExposedPorts = { "4001" = { }; };
Cmd = [ "/bin/tryhaskell" ];
WorkingDir = "${tryhaskell}"; # Needed for the static files.
Env = [
"NIX_GHC_LIBDIR=/lib/ghc-${haskellPackages.ghc.version}"
];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment