server-configuration/services/website.nix
2025-03-31 00:12:43 +02:00

51 lines
1.1 KiB
Nix
Executable file

{
fetchFromGitLab,
pkgs,
...
}: let
host = "127.0.0.1";
port = 8080;
user = "website-host-user";
uid = 1900;
in {
imports = [./nginx.nix];
services.nginx.virtualHosts."spoodythe.one" = {
enableACME = true;
forceSSL = true;
default = true;
locations."/" = {
proxyPass = "http://${host}:${toString port}";
};
};
users.users."website-host-user" = {
isNormalUser = true;
inherit uid;
};
systemd.services."website" = {
description = "Service for running my website";
wants = ["network-online.target"];
after = ["network-online.target"];
wantedBy = ["multi-user.target"];
preStart = ''
if [ ! -d "/home/${user}/website" ]; then
${pkgs.git}/bin/git clone https://gitlab.com/SpoodyTheOne/webbisitey/ "/home/${user}/website"
fi
'';
script = ''
cd /home/${user}/website
${pkgs.git}/bin/git pull
${pkgs.nix}/bin/nix run
'';
serviceConfig = {
Restart = "always";
User = user;
# WorkingDirectory = "/home/${user}/website";
};
};
}