Files
website/flake.nix
T
2026-07-13 20:20:33 -04:00

128 lines
3.9 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.all-dressed-programming.phenix-website;
phenix = self.packages.${pkgs.system}.website;
pythonEnv = pkgs.python3.withPackages (ps: [ ps.requests ]);
in {
options.services.all-dressed-programming.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";
};
databaseUrl = lib.mkOption {
type = lib.types.str;
default = "";
};
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";
}
// lib.optionalAttrs (cfg.databaseUrl == "") {
ConnectionStrings__Default = "Data Source=${cfg.dataDir}/phenix.db";
}
// lib.optionalAttrs (cfg.databaseUrl != "") {
DatabaseProvider = "Postgres";
ConnectionStrings__Default = cfg.databaseUrl;
}
// 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 = {};
};
};
};
}