110 lines
3.0 KiB
Nix
110 lines
3.0 KiB
Nix
{
|
|
description = "FollieHiyuki's stupid CDN";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
gitignore = {
|
|
url = "github:hercules-ci/gitignore.nix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
templ-src = {
|
|
url = "github:a-h/templ";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
inputs.gitignore.follows = "gitignore";
|
|
};
|
|
};
|
|
|
|
outputs = { nixpkgs, templ-src, flake-utils, gitignore, ... }:
|
|
flake-utils.lib.eachSystem [
|
|
"x86_64-linux"
|
|
"x86_64-darwin"
|
|
"aarch64-linux"
|
|
"aarch64-darwin"
|
|
]
|
|
(system:
|
|
let
|
|
inherit (nixpkgs) lib;
|
|
pkgs = nixpkgs.legacyPackages."${system}" // templ-src.packages."${system}";
|
|
|
|
buildInputs = with pkgs; [ go templ ];
|
|
shellHook = ''
|
|
export GOTOOLCHAIN=local
|
|
export CGO_ENABLED=0
|
|
'';
|
|
|
|
tasks = with pkgs; {
|
|
gen = {
|
|
runtimeInputs = [ templ ];
|
|
script = "templ generate";
|
|
};
|
|
preview = {
|
|
runtimeInputs = [ go templ ];
|
|
script = ''
|
|
templ generate
|
|
go run . -preview result/
|
|
'';
|
|
};
|
|
publish = {
|
|
runtimeInputs = [ nodePackages.wrangler ];
|
|
|
|
# NOTE: need to login beforehand, or export CLOUDFLARE_API_TOKEN first
|
|
script = ''
|
|
wrangler pages deploy \
|
|
--project-name=folliehiyuki-cdn \
|
|
--branch=main \
|
|
result/
|
|
'';
|
|
};
|
|
update-src = {
|
|
runtimeInputs = [ curl openssl unzip ];
|
|
script = builtins.readFile ./update-src.sh;
|
|
};
|
|
};
|
|
in
|
|
{
|
|
apps = (lib.attrsets.mapAttrs
|
|
(k: v: flake-utils.lib.mkApp {
|
|
drv = pkgs.writeShellApplication {
|
|
name = k;
|
|
runtimeInputs = v.runtimeInputs;
|
|
text = v.script;
|
|
};
|
|
})
|
|
tasks);
|
|
|
|
packages = rec {
|
|
default = bundle;
|
|
bundle = with pkgs; stdenv.mkDerivation {
|
|
inherit buildInputs;
|
|
name = "cdn.folliehiyuki.com";
|
|
src = lib.cleanSource (gitignore.lib.gitignoreSource ./.);
|
|
configurePhase = ''
|
|
${shellHook}
|
|
export HOME="$TMPDIR"
|
|
export GOCACHE="$PWD/go-cache"
|
|
export GOTMPDIR="$PWD"
|
|
export GOMODCACHE="$PWD/go"
|
|
|
|
templ generate
|
|
'';
|
|
buildPhase = ''
|
|
go run . -minify -gen src
|
|
'';
|
|
installPhase = ''
|
|
mkdir -p "$out"
|
|
cp -r ./src/* "$out"/
|
|
'';
|
|
};
|
|
};
|
|
|
|
devShells.default = with pkgs; mkShell {
|
|
inherit shellHook;
|
|
packages = buildInputs ++ [ nodePackages.wrangler ];
|
|
};
|
|
}
|
|
);
|
|
}
|