2023-11-30 15:03:01 +00:00
|
|
|
import ../make-test-python.nix ({ pkgs, lib, ... }:
|
2021-12-01 07:08:56 +00:00
|
|
|
let
|
|
|
|
domain = "sourcehut.localdomain";
|
|
|
|
in
|
2021-06-05 18:42:51 +00:00
|
|
|
{
|
|
|
|
name = "sourcehut";
|
|
|
|
|
2023-12-20 01:39:32 +00:00
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ tomberek nessdoor ];
|
2021-06-05 18:42:51 +00:00
|
|
|
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine = { config, pkgs, nodes, ... }: {
|
2023-12-25 02:22:11 +00:00
|
|
|
imports = [
|
|
|
|
./nodes/common.nix
|
|
|
|
];
|
|
|
|
|
2021-12-01 07:08:56 +00:00
|
|
|
networking.domain = domain;
|
|
|
|
networking.extraHosts = ''
|
2022-02-12 00:26:41 +00:00
|
|
|
${config.networking.primaryIPAddress} git.${domain}
|
|
|
|
${config.networking.primaryIPAddress} meta.${domain}
|
2021-12-01 07:08:56 +00:00
|
|
|
'';
|
2021-06-05 18:42:51 +00:00
|
|
|
|
|
|
|
services.sourcehut = {
|
2022-02-12 00:26:41 +00:00
|
|
|
git.enable = true;
|
|
|
|
settings."git.sr.ht" = {
|
|
|
|
oauth-client-secret = pkgs.writeText "gitsrht-oauth-client-secret" "3597288dc2c716e567db5384f493b09d";
|
|
|
|
oauth-client-id = "d07cb713d920702e";
|
|
|
|
};
|
2023-12-19 00:54:46 +00:00
|
|
|
};
|
|
|
|
|
2023-11-30 15:03:01 +00:00
|
|
|
environment.systemPackages = with pkgs; [
|
2023-12-19 00:54:46 +00:00
|
|
|
git
|
2023-11-30 15:03:01 +00:00
|
|
|
];
|
2021-06-05 18:42:51 +00:00
|
|
|
};
|
|
|
|
|
2023-11-30 15:03:01 +00:00
|
|
|
testScript =
|
|
|
|
let
|
|
|
|
userName = "nixos-test";
|
|
|
|
userPass = "AutoNixosTestPwd";
|
2023-12-02 23:34:14 +00:00
|
|
|
hutConfig = pkgs.writeText "hut-config" ''
|
|
|
|
instance "${domain}" {
|
|
|
|
# Will be replaced at runtime with the generated token
|
|
|
|
access-token "OAUTH-TOKEN"
|
|
|
|
}
|
|
|
|
'';
|
2023-12-19 00:54:46 +00:00
|
|
|
sshConfig = pkgs.writeText "ssh-config" ''
|
|
|
|
Host git.${domain}
|
|
|
|
IdentityFile = ~/.ssh/id_rsa
|
|
|
|
'';
|
2023-11-30 15:03:01 +00:00
|
|
|
in
|
|
|
|
''
|
|
|
|
start_all()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
2023-12-19 00:54:46 +00:00
|
|
|
machine.wait_for_unit("sshd.service")
|
2023-11-30 15:03:01 +00:00
|
|
|
|
2023-12-20 01:57:38 +00:00
|
|
|
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_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}");
|
|
|
|
(_, 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.succeed("curl -sL http://git.${domain} | grep git.${domain}")
|
|
|
|
|
|
|
|
with subtest("Add an SSH key for Git access"):
|
|
|
|
machine.execute("ssh-keygen -q -N \"\" -t rsa -f ~/.ssh/id_rsa")
|
|
|
|
machine.execute("cat ${sshConfig} > ~/.ssh/config")
|
|
|
|
machine.succeed("hut meta ssh-key create ~/.ssh/id_rsa.pub")
|
|
|
|
|
|
|
|
with subtest("Create a new repo and push contents to it"):
|
|
|
|
machine.execute("git init test")
|
|
|
|
machine.execute("echo \"Hello world!\" > test/hello.txt")
|
|
|
|
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.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")
|
|
|
|
|
|
|
|
with subtest("Verify that the repo is downloadable and its contents match the original"):
|
|
|
|
machine.succeed("curl https://git.${domain}/~${userName}/test/archive/v0.1.tar.gz | tar -xz")
|
|
|
|
machine.succeed("diff test-v0.1/hello.txt test/hello.txt")
|
2023-11-30 15:03:01 +00:00
|
|
|
'';
|
2021-06-05 18:42:51 +00:00
|
|
|
})
|