website as flake input, declarative build via wynne-deploy

Source fetched by Nix from Forgejo, build runs on server with
DB access for prerendering. No manual git clone/pull needed.
This commit is contained in:
Lewis Wynne 2026-04-05 02:07:03 +01:00
parent 0c36b497c8
commit f29e88ad1e
3 changed files with 20 additions and 7 deletions

View file

@ -7,11 +7,16 @@
url = "github:Mic92/sops-nix"; url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
website = {
url = "git+ssh://forgejo@git.ily.rs:4201/lew/website.git";
flake = false;
};
}; };
outputs = { self, nixpkgs, sops-nix, ... }: { outputs = { self, nixpkgs, sops-nix, website, ... }: {
nixosConfigurations.lab = nixpkgs.lib.nixosSystem { nixosConfigurations.lab = nixpkgs.lib.nixosSystem {
system = "aarch64-linux"; system = "aarch64-linux";
specialArgs = { inherit website; };
modules = [ modules = [
sops-nix.nixosModules.sops sops-nix.nixosModules.sops
./hosts/lab ./hosts/lab

View file

@ -1,12 +1,15 @@
{ pkgs, ... }: { pkgs, website, ... }:
let let
port = 4322; port = 4322;
dataDir = "/srv/wynne"; dataDir = "/srv/wynne";
buildDir = "${dataDir}/build";
deployScript = pkgs.writeShellScript "wynne-deploy" '' deployScript = pkgs.writeShellScript "wynne-deploy" ''
set -e set -e
cd ${dataDir}/repo rm -rf ${buildDir}
${pkgs.git}/bin/git pull cp -r ${website} ${buildDir}
chmod -R u+w ${buildDir}
cd ${buildDir}
${pkgs.pnpm}/bin/pnpm install --frozen-lockfile ${pkgs.pnpm}/bin/pnpm install --frozen-lockfile
ASTRO_DB_REMOTE_URL=file:${dataDir}/data/guestbook.db ${pkgs.pnpm}/bin/pnpm build ASTRO_DB_REMOTE_URL=file:${dataDir}/data/guestbook.db ${pkgs.pnpm}/bin/pnpm build
''; '';
@ -27,9 +30,9 @@ in
systemd.services.wynne-deploy = { systemd.services.wynne-deploy = {
description = "Build wynne.rs from source"; description = "Build wynne.rs from source";
path = [ pkgs.nodejs ];
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
User = "lew";
ExecStart = deployScript; ExecStart = deployScript;
}; };
}; };
@ -46,12 +49,12 @@ in
}; };
serviceConfig = { serviceConfig = {
Type = "simple"; Type = "simple";
WorkingDirectory = "${dataDir}/repo"; WorkingDirectory = buildDir;
ExecStart = "${pkgs.nodejs}/bin/node dist/server/entry.mjs"; ExecStart = "${pkgs.nodejs}/bin/node dist/server/entry.mjs";
Restart = "on-failure"; Restart = "on-failure";
User = "wynne"; User = "wynne";
Group = "wynne"; Group = "wynne";
ReadWritePaths = [ "${dataDir}/data" ]; ReadWritePaths = [ dataDir ];
}; };
}; };

View file

@ -14,3 +14,8 @@ check:
update: update:
git pull git pull
sudo nixos-rebuild switch --flake /etc/nixos#lab sudo nixos-rebuild switch --flake /etc/nixos#lab
[doc("Pull latest website source, then rebuild and activate")]
update-site:
nix flake update website
sudo nixos-rebuild switch --flake /etc/nixos#lab