From 337ca2f7b6c5d117d6ec5e600b05daf3cf78281b Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Sun, 29 Dec 2024 03:00:01 -0800 Subject: [PATCH] feat: add nix build files --- flake.lock | 27 ++++++++++++++++++++++++ flake.nix | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ site.nix | 24 +++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 site.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..369a3b3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1735291276, + "narHash": "sha256-NYVcA06+blsLG6wpAbSPTCyLvxD/92Hy4vlY9WxFI1M=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "634fd46801442d760e09493a794c4f15db2d0cbb", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..872be44 --- /dev/null +++ b/flake.nix @@ -0,0 +1,62 @@ +{ + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + outputs = + { nixpkgs, self, ... }: + let + forAllSystems = nixpkgs.lib.genAttrs [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + in + { + packages = forAllSystems ( + system: + let + pkgs = import nixpkgs { inherit system; }; + inherit (pkgs) callPackage; + in + { + default = callPackage ./site.nix { }; + } + ); + apps = forAllSystems ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + default = { + type = "app"; + + program = + let + caddyfile = pkgs.writeText "Caddyfile" '' + :8080 { + root * ${self.packages.${system}.default}/public/ + file_server + try_files {path} {path}.html {path}/ =404 + } + ''; + + formattedCaddyfile = pkgs.runCommand "Caddyfile" { + nativeBuildInputs = [ pkgs.caddy ]; + } ''(caddy fmt ${caddyfile} || :) > "$out"''; + + script = pkgs.writeShellApplication { + name = "logbook"; + + runtimeInputs = [ pkgs.caddy ]; + + text = "caddy run --config ${formattedCaddyfile} --adapter caddyfile"; + }; + + in + "${pkgs.lib.getExe script}"; + }; + } + ); + }; +} diff --git a/site.nix b/site.nix new file mode 100644 index 0000000..2b804b4 --- /dev/null +++ b/site.nix @@ -0,0 +1,24 @@ +{ + buildNpmPackage, + ... +}: +buildNpmPackage { + pname = "quartz"; + version = "4.4.0"; + + src = ./.; + dontNpmBuild = true; + makeCacheWritable = true; + + npmDepsHash = "sha256-zMabk+Tynp7VhFc9M9dNqix33Hm3lAb4CqcEMoHzrz0="; + + installPhase = '' + runHook preInstall + npmInstallHook + + node ./quartz/bootstrap-cli.mjs build + mv public/ $out/public/ + + runHook postInstall + ''; +}