diff --git a/config/services/librespeed.nix b/config/services/librespeed.nix index 8ace17d..a09cbd0 100644 --- a/config/services/librespeed.nix +++ b/config/services/librespeed.nix @@ -1,6 +1,7 @@ -{ ... }: { +{ pkgs, ... }: { services.librespeed = { enable = true; + package = pkgs.librespeed-go; domain = "speed.kyouma.net"; }; } diff --git a/config/services/nginx.nix b/config/services/nginx.nix index 6f8e773..1a11e0a 100644 --- a/config/services/nginx.nix +++ b/config/services/nginx.nix @@ -34,5 +34,11 @@ add_header Referrer-Policy "same-origin" always; #add_header Content-Security-Policy "script-src 'self'; object-src 'none'; base-uri 'none';" always; ''; + eventsConfig = '' + multi_accept on; + ''; + appendConfig = '' + worker_processes auto; + ''; }; } diff --git a/modules/graphical/hyprland.nix b/modules/graphical/hyprland.nix index 9c05672..96dafe6 100644 --- a/modules/graphical/hyprland.nix +++ b/modules/graphical/hyprland.nix @@ -119,7 +119,7 @@ #"eDP-1, 2560x1600@60, 0x0, 1, bitdepth, 10" #"eDP-1, 1920x1200@60, 0x0, 1, bitdepth, 10" "desc:Dell Inc. AW3225QF FXK2YZ3, 3840x2160@240,5280x0,1, bitdepth,10, vrr,2" - "desc:GIGA-BYTE TECHNOLOGY CO. LTD. AORUS AD27QD 19320B000455, 2560x1440@144,3840x-350,1, bitdepth,10, transform,1" + "desc:GIGA-BYTE TECHNOLOGY CO. LTD. AORUS AD27QD 19320B000455, 2560x1440@144,3840x-280,1, bitdepth,10, transform,1" ",preferred,auto,1" ]; workspace = [ diff --git a/modules/librespeed/default.nix b/modules/librespeed/default.nix index 2214525..f5ad429 100644 --- a/modules/librespeed/default.nix +++ b/modules/librespeed/default.nix @@ -107,10 +107,10 @@ in { ''; default = {}; type = with types; nullOr (attrsOf (oneOf [ - bool + (nullOr bool) int str - null + package ])); }; }; @@ -130,11 +130,19 @@ in { services.nginx.virtualHosts = lib.mkIf cfg.configureNginx { ${cfg.domain} = { locations."/" = { - proxyPass = "http://${cfg.settings.bind_address}:${toString cfg.settings.listen_port}"; + proxyPass = "http://[::1]:${toString cfg.settings.listen_port}"; recommendedProxySettings = true; + extraConfig = '' + proxy_cache off; + proxy_buffering off; + proxy_request_buffering off; + ''; }; enableACME = true; forceSSL = true; + extraConfig = '' + gzip off; + ''; }; }; security.acme.certs = lib.mkIf cfg.configureNginx { @@ -144,7 +152,7 @@ in { services.librespeed.servers = lib.mkIf (cfg.domain != null) [ { name = cfg.domain; - server = "https://${cfg.domain}"; + server = "//${cfg.domain}${lib.optionalString (!cfg.configureNginx) ":${toString cfg.settings.listen_port}"}"; } ]; services.librespeed.settings = let @@ -153,41 +161,48 @@ in { assets = pkgs.runCommand "librespeed-assets" { preferLocal = true; - serverList = '' + serversList = '' function get_servers() { return ${builtins.toJSON cfg.servers} } ''; } '' cp -r ${pkgs.librespeed-rust}/assets $out - cat >$out/server_list.js <<<"$serverList" + chmod 666 $out/servers_list.js + cat >$out/servers_list.js <<<"$serversList" substitute ${pkgs.librespeed-rust}/assets/index.html $out/index.html \ --replace-fail "LibreSpeed Example" ${lib.escapeShellArg (lib.escapeXML cfg.pageTitle)} \ --replace-fail "PUT@YOUR_EMAIL.HERE" ${lib.escapeShellArg (lib.escapeXML cfg.contactEmail)} \ --replace-fail "TO BE FILLED BY DEVELOPER" ${lib.escapeShellArg (lib.escapeXML cfg.contactEmail)} ''; in { - speed_test_dir = assets; - bind_address = mkDefault (if cfg.configureNginx then "127.0.0.1" else "0.0.0.0"); + #speed_test_dir = assets; + assets_path = assets; + bind_address = mkDefault (if cfg.configureNginx then "::1" else "::"); listen_port = mkDefault 8989; - base_url = mkDefault "backend"; - worker_threads = mkDefault "auto"; + #base_url = mkDefault "backend"; + #worker_threads = mkDefault "auto"; - database_type = mkDefault "none"; - database_file = mkIf (cfg.settings.database_type == "sqlite") mkDefault "/var/lib/librespeed/speedtest.sqlite"; + server_lat = 0; + server_lng = 0; + proxyprotocol_port = 0; + redact_ip_addresses = false; #librespeed-rust will fail to start if the following config parameters are omitted. ipinfo_api_key = mkIf (!cfg.secrets ? "ipinfo_api_key") ""; stats_password = mkIf (!cfg.secrets ? "stats_password") ""; - tls_key_file = mkDefault ""; - tls_cet_file = mkDefault ""; + #tls_key_file = mkDefault ""; + #tls_cet_file = mkDefault ""; enable_tls = mkDefault false; + } // rec { + database_type = mkDefault "none"; + database_file = mkIf (database_type == "sqlite") (mkDefault "/var/lib/librespeed/speedtest.sqlite"); }; systemd.services = let configFile = let - anyToString = arg: if (lib.isBool arg) then + mapValue = arg: if (lib.isBool arg) then lib.boolToString arg else if (lib.isInt arg) then toString arg @@ -195,8 +210,9 @@ in { in with lib; pipe cfg.settings [ (filterAttrs (_: val: val != null)) - (mapAttrs (name: val: "${path}=${anyToString val}")) - (concatLines attrValues) + (mapAttrs (name: val: "${name}=${mapValue val}")) + (attrValues) + (concatLines) (pkgs.writeText "${cfg.package.name}-config.toml") ]; in { @@ -239,7 +255,7 @@ in { DynamicUser = true; - ExecStartPre = lib.mkIf (!cfg.secrets ? "ipinfo_api_key") "${lib.getExe cfg.package} --update-ipdb"; + #ExecStartPre = lib.mkIf (!cfg.secrets ? "ipinfo_api_key") "${lib.getExe cfg.package} --update-ipdb"; ExecStart = "${lib.getExe cfg.package} -c ${if (cfg.secrets == {}) then configFile else "\${RUNTIME_DIRECTORY%%:*}/config.toml"}"; WorkingDirectory = "/var/cache/librespeed"; RuntimeDirectory = "librespeed"; diff --git a/pkgs/librespeed-go/default.nix b/pkgs/librespeed-go/default.nix new file mode 100644 index 0000000..8b096bb --- /dev/null +++ b/pkgs/librespeed-go/default.nix @@ -0,0 +1,34 @@ +{ + lib, + fetchFromGitHub, + buildGoModule, +}: +let + version = "1.1.5"; + src = fetchFromGitHub { + owner = "librespeed"; + repo = "speedtest-go"; + rev = "refs/tags/v${version}"; + hash = "sha256-ywGrodl/mj/WB25F0TKVvaV0PV4lgc+KEj0x/ix9HT8="; + }; +in +buildGoModule { + pname = "librespeed-go"; + inherit version src; + + vendorHash = "sha256-ev5TEv8u+tx7xIvNaK8b5iq2XXF6I37Fnrr8mb+N2WM="; + + ldflags = [ "-w" "-s" ]; + + postInstall = '' + cp -r web/assets $out/ + ''; + + meta = { + description = "A very lightweight speed test implementation in Go."; + homepage = "https://github.com/librespeed/speedtest-go"; + license = lib.licenses.lgpl3Plus; + maintainers = with lib.maintainers; [ snaki ]; + mainProgram = "speedtest"; + }; +} diff --git a/pkgs/librespeed-rust/default.nix b/pkgs/librespeed-rust/default.nix index 8fc838d..a09896b 100644 --- a/pkgs/librespeed-rust/default.nix +++ b/pkgs/librespeed-rust/default.nix @@ -32,5 +32,6 @@ rustPlatform.buildRustPackage { homepage = "https://github.com/librespeed/speedtest-rust"; license = lib.licenses.lgpl3Plus; maintainers = with lib.maintainers; [ snaki ]; + mainProgram = "librespeed-rs"; }; } diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix index 4ffc4eb..644d380 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -4,4 +4,5 @@ final: prev: { update-nixfiles = final.callPackage ./update-nixfiles/default.nix {}; build-worker-oci = final.callPackage ./build-worker-oci/default.nix {}; librespeed-rust = final.callPackage ./librespeed-rust/default.nix {}; + librespeed-go = final.callPackage ./librespeed-go/default.nix {}; }