diff options
author | Emma@Rory& <root@rory.gay> | 2023-07-24 20:57:56 +0200 |
---|---|---|
committer | Emma@Rory& <root@rory.gay> | 2023-07-24 20:57:56 +0200 |
commit | 1fdcb808607ce0b4d55d6fcf14e7111f1d15f143 (patch) | |
tree | 451cdc1202d42c2da90a7e15e1f113f77f7006ab | |
parent | Start of MRU Desktop (diff) | |
download | MatrixUtils-1fdcb808607ce0b4d55d6fcf14e7111f1d15f143.tar.xz |
Start of nix flake
-rw-r--r-- | flake.lock | 61 | ||||
-rw-r--r-- | flake.nix | 135 | ||||
-rwxr-xr-x | mkdeps | 11 |
3 files changed, 207 insertions, 0 deletions
diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ba339ba --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1689850295, + "narHash": "sha256-fUYf6WdQlhd2H+3aR8jST5dhFH1d0eE22aes8fNIfyk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5df4d78d54f7a34e9ea1f84a22b4fd9baebc68d0", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..34110de --- /dev/null +++ b/flake.nix @@ -0,0 +1,135 @@ +{ + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + let + pkgs = nixpkgs.legacyPackages.x86_64-linux; + in + { + packages.x86_64-linux = { + bots = pkgs.buildDotnetModule rec { + pname = "botcore-v${version}"; + version = "4"; + dotnet-sdk = pkgs.dotnet-sdk_7; + dotnet-runtime = pkgs.dotnet-runtime_7; + src = ./.; + projectFile = [ + "BotCore.Runner/BotCore.Runner.csproj" + "BotCore.SystemdServiceInvoker/BotCore.SystemdServiceInvoker.csproj" + ]; + runtimeDeps = with pkgs; [ yt-dlp ]; + nugetDeps = ./deps.nix; + #nativeBuildInputs = with pkgs; [ + # pkg-config + #]; + }; + frontend = pkgs.buildDotnetModule rec { + pname = "botcore-v${version}"; + version = "4"; + dotnet-sdk = pkgs.dotnet-sdk_7; + dotnet-runtime = pkgs.dotnet-aspnetcore_7; + src = ./.; + projectFile = [ + "BotCore.Web.Legacy/BotCore.Web.Legacy.csproj" + ]; + nugetDeps = ./deps.nix; + #nativeBuildInputs = with pkgs; [ + # pkg-config + #]; + }; + dataupdater = pkgs.buildDotnetModule rec { + pname = "botcore-v${version}"; + version = "4"; + dotnet-sdk = pkgs.dotnet-sdk_7; + dotnet-runtime = pkgs.dotnet-runtime_7; + src = ./.; + projectFile = [ + "BotCore.DataUpdater/BotCore.DataUpdater.csproj" + ]; + nugetDeps = ./deps.nix; + #nativeBuildInputs = with pkgs; [ + # pkg-config + #]; + }; + all = pkgs.buildDotnetModule rec { + pname = "botcore-v${version}"; + version = "4"; + dotnet-sdk = pkgs.dotnet-sdk_7; + dotnet-runtime = pkgs.dotnet-runtime_7; + src = ./.; + projectFile = "DiscordBots.sln"; + nugetDeps = ./deps.nix; + #nativeBuildInputs = with pkgs; [ + # pkg-config + #]; + }; + }; + modules = { + users = { + users.users.botcore = { + isSystemUser = true; + home = "/var/lib/botcore"; + createHome = true; + group = "botcore"; + extraGroups = [ "video" ]; + }; + users.groups.botcore = {}; + security.polkit.extraConfig = '' + polkit.addRule(function(action, subject) { + if (action.id == "org.freedesktop.systemd1.manage-units" && + action.lookup("unit").startsWith("botcore.") && + subject.user == "botcore") { + return polkit.Result.YES; + } + }); + ''; + }; + bots = { + systemd.services = { + "botcore.bot@" = { + serviceConfig = { + ExecStart = "${self.packages.x86_64-linux.bots}/bin/BotCore.Runner %i"; + Restart = "always"; + RestartSec = "5"; + User = "botcore"; + }; + }; + "botcore.systemdserviceinvoker" = { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${self.packages.x86_64-linux.bots}/bin/BotCore.SystemdServiceInvoker"; + User = "botcore"; + }; + }; + }; + }; + frontend = { + systemd.services = { + "botcore.web" = { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${self.packages.x86_64-linux.frontend}/bin/BotCore.Web.Legacy"; + Restart = "always"; + RestartSec = "5"; + User = "botcore"; + }; + }; + }; + }; + dataupdater = { + systemd.services = { + "botcore.dataupdater" = { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${self.packages.x86_64-linux.dataupdater}/bin/BotCore.DataUpdater"; + Restart = "always"; + RestartSec = "15min"; + User = "botcore"; + }; + }; + }; + }; + }; + }; +} diff --git a/mkdeps b/mkdeps new file mode 100755 index 0000000..b577e03 --- /dev/null +++ b/mkdeps @@ -0,0 +1,11 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i "bash -x" -p bash nuget-to-nix +find . | grep -E '(bin|obj)$' | while read d; do rm -rf $d & done +wait + +MSBUILDLIVELOGGER=false dotnet restore --packages=packages -v n --ucr +nuget-to-nix packages | tee deps.nix +du -sh packages +rm -rf packages +nix flake update +git add deps.nix flake.lock |