feat: add nix build files

This commit is contained in:
Youwen Wu 2024-12-29 03:00:01 -08:00
parent 0d9ada6d04
commit 337ca2f7b6
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
3 changed files with 113 additions and 0 deletions

27
flake.lock Normal file
View file

@ -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
}

62
flake.nix Normal file
View file

@ -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}";
};
}
);
};
}

24
site.nix Normal file
View file

@ -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
'';
}