cloudflare-workers/flake.nix

67 lines
1.9 KiB
Nix

{
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1";
outputs =
{ self, nixpkgs }:
let
systems = [
"x86_64-linux"
"aarch64-darwin"
];
forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
in
{
packages = forAllSystems (pkgs: {
nix-cache = pkgs.buildNpmPackage {
pname = "nix-cache";
version = "0.1.3";
src = ./nix-cache;
npmDepsHash = "sha256-bIujU7pZa1ExCZOMOoxsTeLDSF1GuPN/oMSgiMhY/04=";
buildPhase = ''
npx wrangler deploy --dry-run --outdir dist
'';
installPhase = ''
mkdir -p $out
cp dist/index.js $out/
'';
};
});
checks = forAllSystems (pkgs: {
nix-cache-tests = pkgs.buildNpmPackage {
pname = "nix-cache-tests";
version = "0.0.0";
src = ./nix-cache;
npmDepsHash = "sha256-bIujU7pZa1ExCZOMOoxsTeLDSF1GuPN/oMSgiMhY/04=";
dontBuild = true;
doCheck = true;
nativeBuildInputs = [ pkgs.patchelf ];
checkPhase = ''
runHook preCheck
binary=$(find node_modules -path '*/workerd-linux-64/bin/workerd' -type f)
if [ -n "$binary" ]; then
patchelf --set-interpreter "$(cat ${pkgs.stdenv.cc}/nix-support/dynamic-linker)" "$binary"
fi
npm test -- --run
runHook postCheck
'';
installPhase = ''
touch $out
'';
};
devShell = self.devShells.${pkgs.stdenv.hostPlatform.system}.default;
});
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
wrangler
nodejs_22
];
shellHook = ''
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
'';
};
});
};
}