-
-
Save andreabedini/d726c191fd7b6eb93dd954115d679547 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
outputs = { self, nixpkgs, flake-utils }: | |
flake-utils.lib.eachDefaultSystem (system: | |
let | |
pkgs = import nixpkgs { inherit system; }; | |
httpStoreServer = import ./httpStoreServer.nix { inherit pkgs; }; | |
mkHackage = import ./mkHackage.nix { inherit pkgs; }; | |
inputMap = { | |
"hackage.haskell.org" = mkHackage { | |
url = | |
"https://web.archive.org/web/20230113014059/https://hackage.haskell.org/01-index.tar.gz"; | |
sha256 = "0l6qsivvzs1m2a0zfjdc8qwh8n5rs5f4wzslmwnv8gsj3x6sj2qi"; | |
# it's a bit annoying that we have to hardcode this but as we can know the hash we can know the file size | |
length = 111046817; | |
}; | |
}; | |
thing = pkgs.runCommand "thing" { | |
nativeBuildInputs = with pkgs; [ | |
cabal-install | |
ghc | |
curl | |
(httpStoreServer inputMap) | |
]; | |
} '' | |
mkdir -p $out | |
export CABAL_DIR=$out | |
cat >$CABAL_DIR/config <<EOF | |
repository hackage.haskell.org | |
url: http://hackage.haskell.org/ | |
secure: True | |
root-keys: aaa | |
key-threshold: 0 | |
EOF | |
cabal update -v3 | |
''; | |
in { packages.default = thing; }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs }: | |
inputMap: | |
let | |
caddyConfig = pkgs.writeTextFile { | |
name = "caddy-config"; | |
text = builtins.toJSON { | |
admin.disabled = true; | |
apps.http.servers.srv0 = { | |
automatic_https.disable = true; | |
listen = [ "unix//tmp/caddy" ]; | |
routes = pkgs.lib.mapAttrsToList | |
(host: path: { | |
match = [{ host = [ host ]; }]; | |
handle = [{ | |
handler = "file_server"; | |
root = path; | |
}]; | |
terminal = true; | |
}) | |
inputMap; | |
}; | |
}; | |
}; | |
in | |
pkgs.writeTextFile { | |
name = "httpPathsServer"; | |
destination = "/nix-support/setup-hook"; | |
text = '' | |
set -e | |
if [[ ! -v CURL_HOME || ! -e "$CURL_HOME/.curlrc" ]]; then | |
HOME=$(mktemp -d) ${pkgs.caddy}/bin/caddy start --config ${caddyConfig} | |
export CURL_HOME=$(mktemp -d) | |
echo "unix-socket /tmp/caddy" > $CURL_HOME/.curlrc | |
fi | |
''; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs }: | |
{ url, sha256, length }: | |
let | |
index = builtins.fetchurl { | |
name = "hackage-haskell-org-01-index.tar.gz"; | |
inherit url sha256; | |
}; | |
root = builtins.toJSON { | |
signatures = [ ]; | |
signed = { | |
_type = "Root"; | |
expires = null; | |
keys = { }; | |
roles = { | |
mirrors = { | |
keyids = [ ]; | |
threshold = 0; | |
}; | |
root = { | |
keyids = [ ]; | |
threshold = 0; | |
}; | |
snapshot = { | |
keyids = [ ]; | |
threshold = 0; | |
}; | |
targets = { | |
keyids = [ ]; | |
threshold = 0; | |
}; | |
timestamp = { | |
keyids = [ ]; | |
threshold = 0; | |
}; | |
}; | |
version = 1; | |
}; | |
}; | |
timestamp = builtins.toJSON { | |
signatures = [ ]; | |
signed = { | |
_type = "Timestamp"; | |
expires = null; | |
meta = { | |
"<repo>/snapshot.json" = { | |
hashes = { | |
md5 = builtins.hashString "md5" snapshot; | |
sha256 = builtins.hashString "sha256" snapshot; | |
}; | |
length = builtins.stringLength snapshot; | |
}; | |
}; | |
version = 1; | |
}; | |
}; | |
snapshot = builtins.toJSON { | |
signatures = [ ]; | |
signed = { | |
_type = "Snapshot"; | |
expires = null; | |
meta = { | |
"<repo>/01-index.tar.gz" = { | |
hashes = { | |
md5 = builtins.hashFile "md5" index; | |
sha256 = builtins.hashFile "sha256" index; | |
}; | |
length = length; | |
}; | |
"<repo>/root.json" = { | |
hashes = { | |
md5 = builtins.hashString "md5" root; | |
sha256 = builtins.hashString "sha256" root; | |
}; | |
length = builtins.stringLength root; | |
}; | |
"<repo>/mirrors.json" = { | |
hashes = { | |
md5 = builtins.hashString "md5" mirrors; | |
sha256 = builtins.hashString "sha256" mirrors; | |
}; | |
length = builtins.stringLength mirrors; | |
}; | |
}; | |
version = 1; | |
}; | |
}; | |
mirrors = builtins.toJSON { | |
signatures = [ ]; | |
signed = { | |
_type = "Mirrorlist"; | |
expires = null; | |
mirrors = [ ]; | |
version = 1; | |
}; | |
}; | |
in pkgs.runCommand "hackage.haskell.org" { } '' | |
mkdir $out | |
ln -s ${index} $out/01-index.tar.gz | |
echo -n '${root}' > $out/root.json | |
echo -n '${timestamp}' > $out/timestamp.json | |
echo -n '${snapshot}' > $out/snapshot.json | |
echo -n '${mirrors}' > $out/mirrors.json | |
'' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment