127 lines
3.8 KiB
Nix
127 lines
3.8 KiB
Nix
{
|
|
description = "Balle Phenix website — ASP.NET + SQLite";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "nixpkgs/nixos-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils, ... }:
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
let
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
dotnet = pkgs.dotnetCorePackages.sdk_9_0;
|
|
pythonEnv = pkgs.python3.withPackages (ps: [ ps.requests ]);
|
|
|
|
phenix-website = pkgs.buildDotnetModule {
|
|
name = "phenix-website";
|
|
src = ./.;
|
|
projectFile = "Phenix.csproj";
|
|
selfContainedBuild = true;
|
|
dotnet-sdk = dotnet;
|
|
dotnet-runtime = pkgs.dotnetCorePackages.runtime_9_0;
|
|
runtimeIdentifiers = "linux-x64";
|
|
nugetDeps = ./deps.nix;
|
|
|
|
postInstall = ''
|
|
cp -r static $out/lib/static/
|
|
cp appsettings.json $out/lib/
|
|
'';
|
|
meta.mainProgram = "Phenix";
|
|
};
|
|
in {
|
|
packages = {
|
|
default = phenix-website;
|
|
website = phenix-website;
|
|
};
|
|
|
|
devShell = pkgs.mkShell {
|
|
name = "Phenix-Website";
|
|
buildInputs = [ dotnet pkgs.nuget-to-nix pythonEnv ];
|
|
|
|
shellHook = ''
|
|
export PATH="$PWD/dev/populate-db:$PATH"
|
|
'';
|
|
};
|
|
}) // {
|
|
|
|
nixosModules.default = { config, lib, pkgs, ... }:
|
|
let
|
|
cfg = config.services.phenix-website;
|
|
phenix = self.packages.${pkgs.system}.website;
|
|
pythonEnv = pkgs.python3.withPackages (ps: [ ps.requests ]);
|
|
in {
|
|
options.services.phenix-website = {
|
|
enable = lib.mkEnableOption "Balle Phenix website";
|
|
domain = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "ballephenix.com";
|
|
};
|
|
port = lib.mkOption {
|
|
type = lib.types.port;
|
|
default = 8000;
|
|
};
|
|
dataDir = lib.mkOption {
|
|
type = lib.types.path;
|
|
default = "/var/lib/phenix";
|
|
};
|
|
sessionKey = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
systemd.services.phenix-website = {
|
|
description = "Balle Phenix website";
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
|
Type = "simple";
|
|
ExecStart = "${phenix}/lib/Phenix";
|
|
WorkingDirectory = "${phenix}/lib/";
|
|
Restart = "always";
|
|
RestartSec = 5;
|
|
User = "phenix";
|
|
Group = "phenix";
|
|
};
|
|
|
|
environment = {
|
|
ASPNETCORE_URLS = "http://0.0.0.0:${toString cfg.port}";
|
|
ASPNETCORE_ENVIRONMENT = "Production";
|
|
ConnectionStrings__Default = "Data Source=${cfg.dataDir}/phenix.db";
|
|
} // lib.optionalAttrs (cfg.sessionKey != "") {
|
|
SessionKey = cfg.sessionKey;
|
|
};
|
|
|
|
postStart = ''
|
|
mkdir -p ${cfg.dataDir}
|
|
'';
|
|
};
|
|
|
|
users.users.phenix = {
|
|
isSystemUser = true;
|
|
group = "phenix";
|
|
home = cfg.dataDir;
|
|
createHome = true;
|
|
};
|
|
|
|
users.groups.phenix = {};
|
|
|
|
services.nginx = lib.mkIf (cfg.domain != "") {
|
|
enable = true;
|
|
virtualHosts.${cfg.domain} = {
|
|
forceSSL = true;
|
|
enableACME = true;
|
|
locations."/" = {
|
|
proxyPass = "http://127.0.0.1:${toString cfg.port}";
|
|
proxyWebsockets = false;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|