1 import ../make-test-python.nix ({ pkgs, lib, ... }:
3 domain = "sourcehut.localdomain";
8 meta.maintainers = with pkgs.lib.maintainers; [ tomberek nessdoor ];
10 nodes.machine = { config, pkgs, nodes, ... }: {
15 networking.domain = domain;
16 networking.extraHosts = ''
17 ${config.networking.primaryIPAddress} git.${domain}
18 ${config.networking.primaryIPAddress} meta.${domain}
21 services.sourcehut = {
23 settings."git.sr.ht" = {
24 oauth-client-secret = pkgs.writeText "gitsrht-oauth-client-secret" "3597288dc2c716e567db5384f493b09d";
25 oauth-client-id = "d07cb713d920702e";
29 environment.systemPackages = with pkgs; [
36 userName = "nixos-test";
37 userPass = "AutoNixosTestPwd";
38 hutConfig = pkgs.writeText "hut-config" ''
39 instance "${domain}" {
40 # Will be replaced at runtime with the generated token
41 access-token "OAUTH-TOKEN"
44 sshConfig = pkgs.writeText "ssh-config" ''
46 IdentityFile = ~/.ssh/id_rsa
51 machine.wait_for_unit("multi-user.target")
52 machine.wait_for_unit("sshd.service")
54 with subtest("Check whether meta comes up"):
55 machine.wait_for_unit("metasrht-api.service")
56 machine.wait_for_unit("metasrht.service")
57 machine.wait_for_unit("metasrht-webhooks.service")
58 machine.wait_for_open_port(5000)
59 machine.succeed("curl -sL http://localhost:5000 | grep meta.${domain}")
60 machine.succeed("curl -sL http://meta.${domain} | grep meta.${domain}")
62 with subtest("Create a new user account and OAuth access key"):
63 machine.succeed("echo ${userPass} | metasrht-manageuser -ps -e ${userName}@${domain}\
64 -t active_paying ${userName}");
65 (_, token) = machine.execute("srht-gen-oauth-tok -i ${domain} -q ${userName} ${userPass}")
66 token = token.strip().replace("/", r"\\/") # Escape slashes in token before passing it to sed
67 machine.execute("mkdir -p ~/.config/hut/")
68 machine.execute("sed s/OAUTH-TOKEN/" + token + "/ ${hutConfig} > ~/.config/hut/config")
70 with subtest("Check whether git comes up"):
71 machine.wait_for_unit("gitsrht-api.service")
72 machine.wait_for_unit("gitsrht.service")
73 machine.wait_for_unit("gitsrht-webhooks.service")
74 machine.succeed("curl -sL http://git.${domain} | grep git.${domain}")
76 with subtest("Add an SSH key for Git access"):
77 machine.execute("ssh-keygen -q -N \"\" -t rsa -f ~/.ssh/id_rsa")
78 machine.execute("cat ${sshConfig} > ~/.ssh/config")
79 machine.succeed("hut meta ssh-key create ~/.ssh/id_rsa.pub")
81 with subtest("Create a new repo and push contents to it"):
82 machine.execute("git init test")
83 machine.execute("echo \"Hello world!\" > test/hello.txt")
84 machine.execute("cd test && git add .")
85 machine.execute("cd test && git commit -m \"Initial commit\"")
86 machine.execute("cd test && git tag v0.1")
87 machine.succeed("cd test && git remote add origin gitsrht@git.${domain}:~${userName}/test")
88 machine.execute("( echo -n 'git.${domain} '; cat /etc/ssh/ssh_host_ed25519_key.pub ) > ~/.ssh/known_hosts")
89 machine.succeed("hut git create test")
90 machine.succeed("cd test && git push --tags --set-upstream origin master")
92 with subtest("Verify that the repo is downloadable and its contents match the original"):
93 machine.succeed("curl https://git.${domain}/~${userName}/test/archive/v0.1.tar.gz | tar -xz")
94 machine.succeed("diff test-v0.1/hello.txt test/hello.txt")