diff --git a/default.nix b/default.nix
index d644acc9..4281e30c 100644
--- a/default.nix
+++ b/default.nix
@@ -61,7 +61,7 @@ let
'';
buildPhase = ''
- npm run build:tsgo
+ npm run build:src:tsgo
'';
installPhase = ''
@@ -72,7 +72,7 @@ let
npm prune --omit dev --no-save --offline
rm -v dist/src.tsbuildinfo
rm -rv scripts
- time ${./nix/trimNodeModules.sh}
+ # time ${./nix/trimNodeModules.sh}
# Copy outputs
echo "Installing package into $out"
diff --git a/flake.lock b/flake.lock
index a97533e7..a7b675ae 100644
--- a/flake.lock
+++ b/flake.lock
@@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1773436484,
- "narHash": "sha256-SeGjOJJBrsTSa13z/Cu5ucQUo1qlIPwXfR7AeeOBoew=",
+ "lastModified": 1774704740,
+ "narHash": "sha256-8jdUhQQuUGVFHfqRouJuaPMFdT3TP6fgW0CFVIyHGxQ=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "97715a1ceaf42795d7eb751872f7f8e1d317e6e1",
+ "rev": "e4d1aaf1b4f61cf588bf2d02750a08d815b051be",
"type": "github"
},
"original": {
@@ -44,11 +44,11 @@
]
},
"locked": {
- "lastModified": 1773624569,
- "narHash": "sha256-CKfTu9nDD85yv7hHxCKl8tGv4R+/Yj44ANAwvqSO2q4=",
+ "lastModified": 1774417406,
+ "narHash": "sha256-0yXitmNAqgbCFY5xeg10P83h1ExcjLKKOtpxZ6LtmTg=",
"owner": "spacebarchat",
"repo": "pion-webrtc",
- "rev": "5382e83ccbb0305a91b9ae92eae2ee9f5ac39398",
+ "rev": "f69636f4fb3a08c94df68c509302def0cc6cc864",
"type": "github"
},
"original": {
diff --git a/nix/modules/default/cs/admin-api.nix b/nix/modules/default/cs/admin-api.nix
index 531b50aa..dad45b68 100644
--- a/nix/modules/default/cs/admin-api.nix
+++ b/nix/modules/default/cs/admin-api.nix
@@ -13,7 +13,9 @@ let
jsonFormat = pkgs.formats.json { };
in
{
- imports = [ ];
+ imports = [
+ ./shared-config.nix
+ ];
options.services.spacebarchat-server.adminApi = lib.mkOption {
default = { };
description = "Configuration for admin api.";
@@ -22,7 +24,7 @@ in
enable = lib.mkEnableOption "Enable admin api.";
extraConfiguration = lib.mkOption {
type = jsonFormat.type;
- default = import ./default-appsettings-json.nix;
+ default = { };
description = "Extra appsettings.json configuration for the gateway offload daemon.";
};
};
@@ -35,7 +37,7 @@ in
in
{
assertions = [
- (import ./assert-has-connection-string.nix "Admin API" cfg.adminApi.extraConfiguration)
+ (import ./assert-has-connection-string.nix "Admin API" cfg)
];
services.spacebarchat-server.settings.admin = {
@@ -58,7 +60,7 @@ in
CONFIG_READONLY = 1;
ASPNETCORE_URLS = "http://0.0.0.0:${toString cfg.adminApiEndpoint.localPort}";
STORAGE_LOCATION = cfg.cdnPath;
- APPSETTINGS_PATH = jsonFormat.generate "appsettings.spacebar-adminapi.json" (lib.recursiveUpdate (import ./default-appsettings-json.nix) cfg.adminApi.extraConfiguration);
+ APPSETTINGS_PATH = jsonFormat.generate "appsettings.spacebar-adminapi.json" (lib.recursiveUpdate cfg.cs.defaultAppsettings cfg.adminApi.extraConfiguration);
}
);
serviceConfig = {
diff --git a/nix/modules/default/cs/assert-has-connection-string.nix b/nix/modules/default/cs/assert-has-connection-string.nix
index 4066c893..45b8237c 100644
--- a/nix/modules/default/cs/assert-has-connection-string.nix
+++ b/nix/modules/default/cs/assert-has-connection-string.nix
@@ -1,4 +1,8 @@
-name: extraConfig: {
+name: cfg:
+let
+ extraConfig = cfg.cs.defaultAppsettings;
+in
+{
assertion = extraConfig ? ConnectionStrings && extraConfig.ConnectionStrings ? Spacebar && extraConfig.ConnectionStrings.Spacebar != null;
message = ''
${name}: Setting a database connection string in extraConfiguration (`extraConfiguration.ConnectionStrings.Spacebar`) is required when using C# services.
diff --git a/nix/modules/default/cs/cdn-cs.nix b/nix/modules/default/cs/cdn-cs.nix
index 42432dab..91d95b16 100644
--- a/nix/modules/default/cs/cdn-cs.nix
+++ b/nix/modules/default/cs/cdn-cs.nix
@@ -13,7 +13,9 @@ let
jsonFormat = pkgs.formats.json { };
in
{
- imports = [ ];
+ imports = [
+ ./shared-config.nix
+ ];
options.services.spacebarchat-server.cdnCs = lib.mkOption {
default = { };
description = "Configuration for C# cdn.";
@@ -22,7 +24,7 @@ in
enable = lib.mkEnableOption "Enable experimental C# CDN.";
extraConfiguration = lib.mkOption {
type = jsonFormat.type;
- default = import ./default-appsettings-json.nix;
+ default = { };
description = "Extra appsettings.json configuration for the gateway offload daemon.";
};
};
@@ -35,7 +37,7 @@ in
in
{
assertions = [
- (import ./assert-has-connection-string.nix "Admin API" cfg.adminApi.extraConfiguration)
+ (import ./assert-has-connection-string.nix "C# CDN" cfg)
];
systemd.services.spacebar-cdn = makeServerTsService {
@@ -53,7 +55,7 @@ in
CONFIG_READONLY = 1;
ASPNETCORE_URLS = "http://0.0.0.0:${toString cfg.cdnEndpoint.localPort}";
STORAGE_LOCATION = cfg.cdnPath;
- APPSETTINGS_PATH = jsonFormat.generate "appsettings.spacebar-cdn.json" (lib.recursiveUpdate (import ./default-appsettings-json.nix) cfg.cdnCs.extraConfiguration);
+ APPSETTINGS_PATH = jsonFormat.generate "appsettings.spacebar-cdn.json" (lib.recursiveUpdate cfg.cs.defaultAppsettings cfg.cdnCs.extraConfiguration);
}
);
serviceConfig = {
diff --git a/nix/modules/default/cs/offload-cs.nix b/nix/modules/default/cs/offload-cs.nix
index 9186edcb..e1f1fd9b 100644
--- a/nix/modules/default/cs/offload-cs.nix
+++ b/nix/modules/default/cs/offload-cs.nix
@@ -14,7 +14,9 @@ let
jsonFormat = pkgs.formats.json { };
in
{
- imports = [ ];
+ imports = [
+ ./shared-config.nix
+ ];
options.services.spacebarchat-server.offload = lib.mkOption {
default = { };
description = "Configuration for C# offload daemon.";
@@ -28,7 +30,7 @@ in
};
extraConfiguration = lib.mkOption {
type = jsonFormat.type;
- default = import ./default-appsettings-json.nix;
+ default = { };
description = "Extra appsettings.json configuration for the offload daemon.";
};
gateway = lib.mkOption {
@@ -54,7 +56,7 @@ in
in
{
assertions = [
- (import ./assert-has-connection-string.nix "Gateway Offload" offloadCfg.extraConfiguration)
+ (import ./assert-has-connection-string.nix "Gateway Offload" cfg)
];
services.spacebarchat-server.settings.offload = {
@@ -83,9 +85,7 @@ in
CONFIG_READONLY = 1;
ASPNETCORE_URLS = "http://0.0.0.0:${toString offloadCfg.listenPort}";
STORAGE_LOCATION = cfg.cdnPath;
- APPSETTINGS_PATH = jsonFormat.generate "appsettings.spacebar-offload.json" (
- lib.recursiveUpdate (import ./default-appsettings-json.nix) offloadCfg.extraConfiguration
- );
+ APPSETTINGS_PATH = jsonFormat.generate "appsettings.spacebar-offload.json" (lib.recursiveUpdate cfg.cs.defaultAppsettings offloadCfg.extraConfiguration);
}
);
serviceConfig = {
diff --git a/nix/modules/default/cs/shared-config.nix b/nix/modules/default/cs/shared-config.nix
new file mode 100644
index 00000000..a5ca64f6
--- /dev/null
+++ b/nix/modules/default/cs/shared-config.nix
@@ -0,0 +1,31 @@
+{
+ config,
+ lib,
+ pkgs,
+ ...
+}:
+
+let
+ secrets = import ../secrets.nix { inherit lib config; };
+ cfg = config.services.spacebarchat-server;
+ jsonFormat = pkgs.formats.json { };
+in
+{
+ options.services.spacebarchat-server.cs = lib.mkOption {
+ default = { };
+ description = "Configuration for C# cdn.";
+ type = lib.types.submodule {
+ options = {
+ defaultAppsettings = lib.mkOption {
+ type = jsonFormat.type;
+ default = import ./default-appsettings-json.nix;
+ description = "Extra appsettings.json configuration for all C#-based services.";
+ };
+ };
+ };
+ };
+
+ config = {
+ services.spacebarchat-server.cs.defaultAppsettings = import ./default-appsettings-json.nix;
+ };
+}
diff --git a/nix/modules/default/cs/uapi.nix b/nix/modules/default/cs/uapi.nix
index 00caa214..2df0535f 100644
--- a/nix/modules/default/cs/uapi.nix
+++ b/nix/modules/default/cs/uapi.nix
@@ -13,7 +13,9 @@ let
jsonFormat = pkgs.formats.json { };
in
{
- imports = [ ];
+ imports = [
+ ./shared-config.nix
+ ];
options.services.spacebarchat-server.uApi = lib.mkOption {
default = { };
description = "Configuration for C# API overlay.";
@@ -27,7 +29,7 @@ in
};
extraConfiguration = lib.mkOption {
type = jsonFormat.type;
- default = import ./default-appsettings-json.nix;
+ default = { };
description = "Extra appsettings.json configuration for the C# API overlay.";
};
};
@@ -40,7 +42,7 @@ in
in
{
assertions = [
- (import ./assert-has-connection-string.nix "uAPI" cfg.uApi.extraConfiguration)
+ (import ./assert-has-connection-string.nix "uAPI" cfg)
];
systemd.services.spacebar-uapi = makeServerTsService {
@@ -59,7 +61,7 @@ in
CONFIG_READONLY = 1;
ASPNETCORE_URLS = "http://0.0.0.0:${toString cfg.uApi.listenPort}";
STORAGE_LOCATION = cfg.cdnPath;
- APPSETTINGS_PATH = jsonFormat.generate "appsettings.spacebar-uapi.json" (lib.recursiveUpdate (import ./default-appsettings-json.nix) cfg.uApi.extraConfiguration);
+ APPSETTINGS_PATH = jsonFormat.generate "appsettings.spacebar-uapi.json" (lib.recursiveUpdate cfg.cs.defaultAppsettings cfg.uApi.extraConfiguration);
}
);
serviceConfig = {
diff --git a/nix/modules/default/pion-sfu.nix b/nix/modules/default/pion-sfu.nix
index aa2fbf24..306699b6 100644
--- a/nix/modules/default/pion-sfu.nix
+++ b/nix/modules/default/pion-sfu.nix
@@ -13,25 +13,21 @@ let
configFile = (import ./config-file.nix { inherit config lib pkgs; });
in
{
- options.services.spacebarchat-server.pion-sfu =
- let
- mkEndpointOptions = import ./options-subtypes/mkEndpointOptions.nix { inherit lib; };
- in
- {
- enable = lib.mkEnableOption "Enable Spacebar Pion SFU";
- openFirewall = lib.mkEnableOption "Allow SFU port in firewall";
- package = lib.mkPackageOption self.packages.${pkgs.stdenv.hostPlatform.system} "Pion SFU" { default = "pion-sfu"; };
+ options.services.spacebarchat-server.pion-sfu = {
+ enable = lib.mkEnableOption "Enable Spacebar Pion SFU";
+ openFirewall = lib.mkEnableOption "Allow SFU port in firewall";
+ package = lib.mkPackageOption self.packages.${pkgs.stdenv.hostPlatform.system} "Pion SFU" { default = "pion-sfu"; };
- publicIp = lib.mkOption {
- type = lib.types.str;
- description = "Public IP address of the server.";
- };
- listenPort = lib.mkOption {
- type = lib.types.port;
- default = 6000;
- description = "UDP port the SFU will listen on.";
- };
+ publicIp = lib.mkOption {
+ type = lib.types.str;
+ description = "Public IP address of the server.";
+ };
+ listenPort = lib.mkOption {
+ type = lib.types.port;
+ default = 6000;
+ description = "UDP port the SFU will listen on.";
};
+ };
config = lib.mkIf cfg.pion-sfu.enable (
let
diff --git a/nix/testVm/configuration.nix b/nix/testVm/configuration.nix
index 1e70da99..ad862a01 100644
--- a/nix/testVm/configuration.nix
+++ b/nix/testVm/configuration.nix
@@ -58,6 +58,7 @@ in
};
};
+ cs.defaultAppsettings.ConnectionStrings.Spacebar = csConnectionString;
offload = {
enable = true;
gateway = {
@@ -68,23 +69,11 @@ in
enableChannelStatuses = true;
enableChannelInfo = true;
};
- extraConfiguration.ConnectionStrings.Spacebar = csConnectionString;
};
- adminApi = {
- enable = true;
- extraConfiguration.ConnectionStrings.Spacebar = csConnectionString;
- };
-
- cdnCs = {
- enable = false;
- extraConfiguration.ConnectionStrings.Spacebar = csConnectionString;
- };
-
- uApi = {
- enable = true;
- extraConfiguration.ConnectionStrings.Spacebar = csConnectionString;
- };
+ adminApi.enable = true;
+ cdnCs.enable = false;
+ uApi.enable = true;
pion-sfu = {
enable = true;
@@ -105,14 +94,17 @@ in
};
in
lib.trace ("Testing with config: " + builtins.toJSON cfg) cfg;
- services.nginx.enable = true;
- services.nginx.recommendedOptimisation = true;
- services.nginx.appendConfig = ''
- worker_processes 6;
- '';
- services.nginx.eventsConfig = ''
- worker_connections 512;
- '';
+
+ services.nginx = {
+ enable = true;
+ recommendedOptimisation = true;
+ appendConfig = ''
+ worker_processes 6;
+ '';
+ eventsConfig = ''
+ worker_connections 512;
+ '';
+ };
users.users.root.initialPassword = "root";
services.getty.autologinUser = "root";
diff --git a/nix/testVm/default.nix b/nix/testVm/default.nix
index 3b67f492..cdacc3da 100644
--- a/nix/testVm/default.nix
+++ b/nix/testVm/default.nix
@@ -6,7 +6,6 @@ nixpkgs.lib.nixosSystem {
self.nixosModules.default
./configuration.nix
./postgres.nix
- ./perlless.nix
./vm.nix
];
specialArgs = { inherit self nixpkgs; };
diff --git a/nix/testVm/musl.nix b/nix/testVm/musl.nix
new file mode 100644
index 00000000..0a272c95
--- /dev/null
+++ b/nix/testVm/musl.nix
@@ -0,0 +1,77 @@
+# https://github.com/MatthewCroughan/nixos-musl/blob/master/musl.nix
+{ pkgs, lib, ... }:
+let
+ glibcPkgs = (import pkgs.path { system = pkgs.stdenv.hostPlatform.system; });
+in
+{
+ # Fails to build, and doesn't make sense on musl anyway
+ services.nscd.enableNsncd = false;
+ services.nscd.enable = false;
+ system.nssModules = lib.mkForce [];
+
+ # wrappers use pkgsStatic which has issues on native musl at this time
+ security.enableWrappers = pkgs.stdenv.buildPlatform.isGnu;
+
+ xdg.mime.enable = if (pkgs.stdenv.buildPlatform != pkgs.stdenv.hostPlatform) then false else true;
+
+ # stub-ld doesn't make sense with musl
+ environment.stub-ld.enable = false;
+
+ # Fails unless neutered error: expected a set but found null: null
+ i18n.glibcLocales = pkgs.runCommand "neutered" { } "mkdir -p $out";
+
+ # Perl stuff just fails too hard these days
+ # services.userborn.enable = true;
+
+ nixpkgs.overlays = [
+ (self: super: {
+ # qemu doesn't build for musl, and if we want to run the
+ # config.system.build.vm, we need a glibc qemu, doens't impact anything
+ # else
+ qemu = glibcPkgs.qemu;
+
+ ## But the qemu_test binary is fine on musl
+ qemu_test = glibcPkgs.qemu_test;
+
+ # Tests are so flaky...
+ git = super.git.overrideAttrs { doInstallCheck = false; };
+
+ # https://github.com/NixOS/nixpkgs/pull/451147
+ diffutils = super.diffutils.overrideAttrs (old: {
+ postPatch =
+ if (super.stdenv.buildPlatform.isGnu && super.stdenv.hostPlatform.isMusl) then
+ ''
+ sed -i -E 's:test-getopt-gnu::g' gnulib-tests/Makefile.in
+ sed -i -E 's:test-getopt-posix::g' gnulib-tests/Makefile.in
+ '' else null;
+ });
+
+ # checks fail on musl
+ logrotate = super.logrotate.overrideAttrs {
+ doCheck = false;
+ };
+ rsync = super.rsync.overrideAttrs {
+ doCheck = false;
+ };
+ spdlog = super.spdlog.overrideAttrs {
+ doCheck = false;
+ };
+ })
+ ];
+
+ # These options sometimes work, and sometimes don't, because of perl
+ nix.enable = lib.mkForce false;
+ system = {
+ tools.nixos-generate-config.enable = lib.mkForce false;
+ switch.enable = lib.mkForce false;
+ disableInstallerTools = lib.mkForce false;
+ tools.nixos-option.enable = lib.mkForce false;
+ };
+ documentation = {
+ enable = false;
+ doc.enable = false;
+ info.enable = false;
+ man.enable = false;
+ nixos.enable = false;
+ };
+}
\ No newline at end of file
diff --git a/nix/testVm/perlless.nix b/nix/testVm/perlless.nix
deleted file mode 100644
index 669be83c..00000000
--- a/nix/testVm/perlless.nix
+++ /dev/null
@@ -1,26 +0,0 @@
-{ lib, ... }:
-{
- #perlless profile
- #system.switch.enable = lib.mkForce false;
-
- # Remove perl from activation
- #system.etc.overlay.enable = lib.mkForce true;
- #systemd.sysusers.enable = lib.mkForce true;
-
- # Random perl remnants
- programs.less.lessopen = lib.mkForce null;
- programs.command-not-found.enable = lib.mkForce false;
- environment.defaultPackages = lib.mkForce [ ];
- documentation.info.enable = lib.mkForce false;
- documentation.man.enable = false;
-
- system = {
- #activatable = false;
- copySystemConfiguration = false;
- includeBuildDependencies = false;
- disableInstallerTools = lib.mkForce true;
- build = {
- separateActivationScript = true;
- };
- };
-}
diff --git a/nix/testVm/vm.nix b/nix/testVm/vm.nix
index 0c61aa83..3f2e9311 100644
--- a/nix/testVm/vm.nix
+++ b/nix/testVm/vm.nix
@@ -1,4 +1,5 @@
{
+ config,
pkgs,
lib,
modulesPath,
@@ -6,7 +7,8 @@
}:
{
imports = [
-# (modulesPath + "/virtualisation/qemu-vm.nix")
+ # (modulesPath + "/virtualisation/qemu-vm.nix")
+ ./musl.nix
];
virtualisation.vmVariant = {
@@ -59,4 +61,67 @@
font = "${pkgs.cozette}/share/consolefonts/cozette6x13.psfu";
packages = with pkgs; [ cozette ];
};
+
+ # Remove perl from activation
+ system.etc.overlay.enable = lib.mkForce true;
+ systemd.sysusers.enable = lib.mkForce true;
+
+ programs.less.lessopen = lib.mkForce null;
+ programs.command-not-found.enable = lib.mkForce false;
+ environment.defaultPackages = lib.mkForce [ ];
+ documentation.info.enable = lib.mkForce false;
+ documentation.man.enable = false;
+
+ system = {
+ copySystemConfiguration = false;
+ includeBuildDependencies = false;
+ disableInstallerTools = lib.mkForce true;
+ build = {
+ separateActivationScript = true;
+ };
+ switch.enable = lib.mkForce false;
+ nixos-init.enable = true;
+ };
+
+ nixpkgs.hostPlatform = {
+ system = "x86_64-linux";
+ config = "x86_64-unknown-linux-musl";
+ };
+
+ boot.loader.grub.enable = lib.mkDefault false;
+ fileSystems."/".device = lib.mkDefault "/dev/disk/by-label/nixos";
+ # https://github.com/NixOS/nixpkgs/pull/496852/changes
+ boot.postBootCommands = lib.mkForce "";
+ systemd.services.register-nix-paths = lib.mkIf config.nix.enable {
+ # Run early during boot so the nix store DB is populated before any
+ # service (or test backdoor) tries to use nix commands.
+ # nix-store --load-db writes to the SQLite DB directly, so it does not
+ # need the nix-daemon.
+ unitConfig.DefaultDependencies = false;
+ wantedBy = [
+ "sysinit.target"
+ ];
+ before = [
+ "sysinit.target"
+ "shutdown.target"
+ "nix-daemon.socket"
+ "nix-daemon.service"
+ ];
+ after = [
+ "local-fs.target"
+ ];
+ conflicts = [
+ "shutdown.target"
+ ];
+ restartIfChanged = false;
+ serviceConfig = {
+ Type = "oneshot";
+ RemainAfterExit = true;
+ };
+ script = ''
+ if [[ "$(cat /proc/cmdline)" =~ regInfo=([^ ]*) ]]; then
+ ${lib.getExe' config.nix.package.out "nix-store"} --load-db < "''${BASH_REMATCH[1]}"
+ fi
+ '';
+ };
}
|