Loading nixos/modules/services/misc/sourcehut/default.nix +111 −105 File changed.Preview size limit exceeded, changes collapsed. Show changes nixos/modules/services/misc/sourcehut/service.nix +12 −9 Original line number Diff line number Diff line srv: { configIniOfService, srvsrht ? "${srv}srht", # Because "buildsrht" does not follow that pattern (missing an "s"). pkgname ? "${srv}srht", # Because "buildsrht" does not follow that pattern (missing an "s"). srvsrht ? "${srv}.sr.ht", iniKey ? "${srv}.sr.ht", webhooks ? false, extraTimers ? { }, Loading @@ -28,7 +29,7 @@ let mkIf mkMerge ; inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption mkPackageOption; inherit (lib.strings) concatStringsSep hasSuffix optionalString; inherit (config.services) postgresql; redis = config.services.redis.servers."sourcehut-${srvsrht}"; Loading Loading @@ -162,6 +163,8 @@ in { enable = mkEnableOption "${srv} service"; package = mkPackageOption pkgs [ "sourcehut" pkgname ] { }; user = mkOption { type = types.str; default = srvsrht; Loading Loading @@ -276,7 +279,7 @@ in forceSSL = mkDefault true; locations."/".proxyPass = "http://${cfg.listenAddress}:${toString srvCfg.port}"; locations."/static" = { root = "${pkgs.sourcehut.${srvsrht}}/${pkgs.sourcehut.python.sitePackages}/${srvsrht}"; root = "${srvCfg.package}/${pkgs.sourcehut.python.sitePackages}/${srvsrht}"; extraConfig = mkDefault '' expires 30d; ''; Loading Loading @@ -367,12 +370,12 @@ in StateDirectory = [ "sourcehut/${srvsrht}" ]; StateDirectoryMode = "2750"; ExecStart = "${cfg.python}/bin/gunicorn ${srvsrht}.app:app --name ${srvsrht} --bind ${cfg.listenAddress}:${toString srvCfg.port} " "${cfg.python}/bin/gunicorn ${pkgname}.app:app --name ${srvsrht} --bind ${cfg.listenAddress}:${toString srvCfg.port} " + concatStringsSep " " srvCfg.gunicorn.extraArgs; }; preStart = let package = pkgs.sourcehut.${srvsrht}; package = srvCfg.package; version = package.version; stateDir = "/var/lib/sourcehut/${srvsrht}"; in Loading @@ -385,7 +388,7 @@ in if test ! -e ${stateDir}/db; then # Setup the initial database. # Note that it stamps the alembic head afterward ${package}/bin/${srvsrht}-initdb ${postgresql.package}/bin/psql -d ${srvsrht} -f ${package}/share/sourcehut/${srvsrht}-schema.sql echo ${version} >${stateDir}/db fi Loading @@ -401,7 +404,7 @@ in # See https://lists.sr.ht/~sircmpwn/sr.ht-admins/<20190302181207.GA13778%40cirno.my.domain> if test ! -e ${stateDir}/webhook; then # Update ${iniKey}'s users' profile copy to the latest ${cfg.python}/bin/srht-update-profiles ${iniKey} ${cfg.python}/bin/sr.ht-update-profiles ${iniKey} touch ${stateDir}/webhook fi ''; Loading @@ -424,7 +427,7 @@ in Type = "simple"; Restart = "always"; ExecStart = "${cfg.python}/bin/celery --app ${srvsrht}.webhooks worker --hostname ${srvsrht}-webhooks@%%h " "${cfg.python}/bin/celery --app ${pkgname}.webhooks worker --hostname ${srvsrht}-webhooks@%%h " + concatStringsSep " " srvCfg.webhooks.extraArgs; # Avoid crashing: os.getloadavg() ProcSubset = mkForce "all"; Loading @@ -443,7 +446,7 @@ in ]; serviceConfig = { Type = "oneshot"; ExecStart = "${pkgs.sourcehut.${srvsrht}}/bin/${timerName}"; ExecStart = "${srvCfg.package}/bin/${timerName}"; }; } (timer.service or { }) Loading nixos/tests/sourcehut/builds.nix +4 −4 Original line number Diff line number Diff line Loading @@ -49,15 +49,15 @@ import ../make-test-python.nix ( machine.wait_for_unit("multi-user.target") with subtest("Check whether meta comes up"): machine.wait_for_unit("metasrht-api.service") machine.wait_for_unit("metasrht.service") machine.wait_for_unit("metasrht-webhooks.service") machine.wait_for_unit("meta.sr.ht-api.service") machine.wait_for_unit("meta.sr.ht.service") machine.wait_for_unit("meta.sr.ht-webhooks.service") machine.wait_for_open_port(5000) machine.succeed("curl -sL http://localhost:5000 | grep meta.${domain}") machine.succeed("curl -sL http://meta.${domain} | grep meta.${domain}") with subtest("Check whether builds comes up"): machine.wait_for_unit("buildsrht.service") machine.wait_for_unit("builds.sr.ht.service") machine.wait_for_open_port(5002) machine.succeed("curl -sL http://localhost:5002 | grep builds.${domain}") #machine.wait_for_unit("buildsrht-worker.service") Loading nixos/tests/sourcehut/git.nix +10 −9 Original line number Diff line number Diff line Loading @@ -63,25 +63,26 @@ import ../make-test-python.nix ( machine.wait_for_unit("sshd.service") with subtest("Check whether meta comes up"): machine.wait_for_unit("metasrht-api.service") machine.wait_for_unit("metasrht.service") machine.wait_for_unit("metasrht-webhooks.service") machine.wait_for_unit("meta.sr.ht-api.service") machine.wait_for_unit("meta.sr.ht.service") machine.wait_for_unit("meta.sr.ht-webhooks.service") machine.wait_for_open_port(5000) machine.succeed("curl -sL http://localhost:5000 | grep meta.${domain}") machine.succeed("curl -sL http://meta.${domain} | grep meta.${domain}") with subtest("Create a new user account and OAuth access key"): machine.succeed("echo ${userPass} | metasrht-manageuser -ps -e ${userName}@${domain}\ -t active_paying ${userName}"); machine.succeed("echo ${userPass} | meta.sr.ht-manageuser -ps -e ${userName}@${domain}\ -t USER ${userName}"); cmd = "srht-gen-oauth-tok -i ${domain} -q ${userName} ${userPass}" (_, token) = machine.execute("srht-gen-oauth-tok -i ${domain} -q ${userName} ${userPass}") token = token.strip().replace("/", r"\\/") # Escape slashes in token before passing it to sed machine.execute("mkdir -p ~/.config/hut/") machine.execute("sed s/OAUTH-TOKEN/" + token + "/ ${hutConfig} > ~/.config/hut/config") with subtest("Check whether git comes up"): machine.wait_for_unit("gitsrht-api.service") machine.wait_for_unit("gitsrht.service") machine.wait_for_unit("gitsrht-webhooks.service") machine.wait_for_unit("git.sr.ht-api.service") machine.wait_for_unit("git.sr.ht.service") machine.wait_for_unit("git.sr.ht-webhooks.service") machine.succeed("curl -sL http://git.${domain} | grep git.${domain}") with subtest("Add an SSH key for Git access"): Loading @@ -95,7 +96,7 @@ import ../make-test-python.nix ( machine.execute("cd test && git add .") machine.execute("cd test && git commit -m \"Initial commit\"") machine.execute("cd test && git tag v0.1") machine.succeed("cd test && git remote add origin gitsrht@git.${domain}:~${userName}/test") machine.succeed("cd test && git remote add origin git.sr.ht@git.${domain}:~${userName}/test") machine.execute("( echo -n 'git.${domain} '; cat /etc/ssh/ssh_host_ed25519_key.pub ) > ~/.ssh/known_hosts") machine.succeed("hut git create test") machine.succeed("cd test && git push --tags --set-upstream origin master") Loading Loading
nixos/modules/services/misc/sourcehut/default.nix +111 −105 File changed.Preview size limit exceeded, changes collapsed. Show changes
nixos/modules/services/misc/sourcehut/service.nix +12 −9 Original line number Diff line number Diff line srv: { configIniOfService, srvsrht ? "${srv}srht", # Because "buildsrht" does not follow that pattern (missing an "s"). pkgname ? "${srv}srht", # Because "buildsrht" does not follow that pattern (missing an "s"). srvsrht ? "${srv}.sr.ht", iniKey ? "${srv}.sr.ht", webhooks ? false, extraTimers ? { }, Loading @@ -28,7 +29,7 @@ let mkIf mkMerge ; inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption mkPackageOption; inherit (lib.strings) concatStringsSep hasSuffix optionalString; inherit (config.services) postgresql; redis = config.services.redis.servers."sourcehut-${srvsrht}"; Loading Loading @@ -162,6 +163,8 @@ in { enable = mkEnableOption "${srv} service"; package = mkPackageOption pkgs [ "sourcehut" pkgname ] { }; user = mkOption { type = types.str; default = srvsrht; Loading Loading @@ -276,7 +279,7 @@ in forceSSL = mkDefault true; locations."/".proxyPass = "http://${cfg.listenAddress}:${toString srvCfg.port}"; locations."/static" = { root = "${pkgs.sourcehut.${srvsrht}}/${pkgs.sourcehut.python.sitePackages}/${srvsrht}"; root = "${srvCfg.package}/${pkgs.sourcehut.python.sitePackages}/${srvsrht}"; extraConfig = mkDefault '' expires 30d; ''; Loading Loading @@ -367,12 +370,12 @@ in StateDirectory = [ "sourcehut/${srvsrht}" ]; StateDirectoryMode = "2750"; ExecStart = "${cfg.python}/bin/gunicorn ${srvsrht}.app:app --name ${srvsrht} --bind ${cfg.listenAddress}:${toString srvCfg.port} " "${cfg.python}/bin/gunicorn ${pkgname}.app:app --name ${srvsrht} --bind ${cfg.listenAddress}:${toString srvCfg.port} " + concatStringsSep " " srvCfg.gunicorn.extraArgs; }; preStart = let package = pkgs.sourcehut.${srvsrht}; package = srvCfg.package; version = package.version; stateDir = "/var/lib/sourcehut/${srvsrht}"; in Loading @@ -385,7 +388,7 @@ in if test ! -e ${stateDir}/db; then # Setup the initial database. # Note that it stamps the alembic head afterward ${package}/bin/${srvsrht}-initdb ${postgresql.package}/bin/psql -d ${srvsrht} -f ${package}/share/sourcehut/${srvsrht}-schema.sql echo ${version} >${stateDir}/db fi Loading @@ -401,7 +404,7 @@ in # See https://lists.sr.ht/~sircmpwn/sr.ht-admins/<20190302181207.GA13778%40cirno.my.domain> if test ! -e ${stateDir}/webhook; then # Update ${iniKey}'s users' profile copy to the latest ${cfg.python}/bin/srht-update-profiles ${iniKey} ${cfg.python}/bin/sr.ht-update-profiles ${iniKey} touch ${stateDir}/webhook fi ''; Loading @@ -424,7 +427,7 @@ in Type = "simple"; Restart = "always"; ExecStart = "${cfg.python}/bin/celery --app ${srvsrht}.webhooks worker --hostname ${srvsrht}-webhooks@%%h " "${cfg.python}/bin/celery --app ${pkgname}.webhooks worker --hostname ${srvsrht}-webhooks@%%h " + concatStringsSep " " srvCfg.webhooks.extraArgs; # Avoid crashing: os.getloadavg() ProcSubset = mkForce "all"; Loading @@ -443,7 +446,7 @@ in ]; serviceConfig = { Type = "oneshot"; ExecStart = "${pkgs.sourcehut.${srvsrht}}/bin/${timerName}"; ExecStart = "${srvCfg.package}/bin/${timerName}"; }; } (timer.service or { }) Loading
nixos/tests/sourcehut/builds.nix +4 −4 Original line number Diff line number Diff line Loading @@ -49,15 +49,15 @@ import ../make-test-python.nix ( machine.wait_for_unit("multi-user.target") with subtest("Check whether meta comes up"): machine.wait_for_unit("metasrht-api.service") machine.wait_for_unit("metasrht.service") machine.wait_for_unit("metasrht-webhooks.service") machine.wait_for_unit("meta.sr.ht-api.service") machine.wait_for_unit("meta.sr.ht.service") machine.wait_for_unit("meta.sr.ht-webhooks.service") machine.wait_for_open_port(5000) machine.succeed("curl -sL http://localhost:5000 | grep meta.${domain}") machine.succeed("curl -sL http://meta.${domain} | grep meta.${domain}") with subtest("Check whether builds comes up"): machine.wait_for_unit("buildsrht.service") machine.wait_for_unit("builds.sr.ht.service") machine.wait_for_open_port(5002) machine.succeed("curl -sL http://localhost:5002 | grep builds.${domain}") #machine.wait_for_unit("buildsrht-worker.service") Loading
nixos/tests/sourcehut/git.nix +10 −9 Original line number Diff line number Diff line Loading @@ -63,25 +63,26 @@ import ../make-test-python.nix ( machine.wait_for_unit("sshd.service") with subtest("Check whether meta comes up"): machine.wait_for_unit("metasrht-api.service") machine.wait_for_unit("metasrht.service") machine.wait_for_unit("metasrht-webhooks.service") machine.wait_for_unit("meta.sr.ht-api.service") machine.wait_for_unit("meta.sr.ht.service") machine.wait_for_unit("meta.sr.ht-webhooks.service") machine.wait_for_open_port(5000) machine.succeed("curl -sL http://localhost:5000 | grep meta.${domain}") machine.succeed("curl -sL http://meta.${domain} | grep meta.${domain}") with subtest("Create a new user account and OAuth access key"): machine.succeed("echo ${userPass} | metasrht-manageuser -ps -e ${userName}@${domain}\ -t active_paying ${userName}"); machine.succeed("echo ${userPass} | meta.sr.ht-manageuser -ps -e ${userName}@${domain}\ -t USER ${userName}"); cmd = "srht-gen-oauth-tok -i ${domain} -q ${userName} ${userPass}" (_, token) = machine.execute("srht-gen-oauth-tok -i ${domain} -q ${userName} ${userPass}") token = token.strip().replace("/", r"\\/") # Escape slashes in token before passing it to sed machine.execute("mkdir -p ~/.config/hut/") machine.execute("sed s/OAUTH-TOKEN/" + token + "/ ${hutConfig} > ~/.config/hut/config") with subtest("Check whether git comes up"): machine.wait_for_unit("gitsrht-api.service") machine.wait_for_unit("gitsrht.service") machine.wait_for_unit("gitsrht-webhooks.service") machine.wait_for_unit("git.sr.ht-api.service") machine.wait_for_unit("git.sr.ht.service") machine.wait_for_unit("git.sr.ht-webhooks.service") machine.succeed("curl -sL http://git.${domain} | grep git.${domain}") with subtest("Add an SSH key for Git access"): Loading @@ -95,7 +96,7 @@ import ../make-test-python.nix ( machine.execute("cd test && git add .") machine.execute("cd test && git commit -m \"Initial commit\"") machine.execute("cd test && git tag v0.1") machine.succeed("cd test && git remote add origin gitsrht@git.${domain}:~${userName}/test") machine.succeed("cd test && git remote add origin git.sr.ht@git.${domain}:~${userName}/test") machine.execute("( echo -n 'git.${domain} '; cat /etc/ssh/ssh_host_ed25519_key.pub ) > ~/.ssh/known_hosts") machine.succeed("hut git create test") machine.succeed("cd test && git push --tags --set-upstream origin master") Loading