-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1a6360
commit 87b4ea9
Showing
4 changed files
with
149 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
let | ||
inherit (import <acm-aws/user-machines/vm/config.nix> { inherit pkgs; }) | ||
hostOrderToIP | ||
ips; | ||
|
||
findUserIDWithIP = | ||
ip: | ||
lib.findFirst (user: user.ip == ip) null config.acm.user-vms.usersInfo; | ||
|
||
vpsFiles = pkgs.runCommand "www-vps.acmcsuf.com" { | ||
nativeBuildInputs = with pkgs; [ | ||
gomplate | ||
]; | ||
} '' | ||
mkdir $out | ||
gomplate \ | ||
--file ${./vps.html} \ | ||
--out $out/index.html \ | ||
--datasource users=file://${pkgs.writeFile "users.json" (builtins.toString config.acm.user-vms.users)} \ | ||
--datasource usersInfo=file://${pkgs.writeFile "usersInfo.json" (builtins.toString config.acm.user-vms.usersInfo)} | ||
''; | ||
in | ||
|
||
{ | ||
imports = [ | ||
<acm-aws/user-machines/vm> | ||
]; | ||
|
||
acm.user-vms = { | ||
enable = true; | ||
users = builtins.fromJSON (builtins.readFile <acm-aws/user-machines/secrets/user-vms.json>); | ||
# Pin all CPU usages to the 4 host cores. | ||
cpuPinning = [4 5 6 7]; | ||
poolDirectory = "/var/lib/acm-vm"; | ||
}; | ||
|
||
services.sshwifty = { | ||
enable = true; | ||
config = { | ||
Servers = [ | ||
{ | ||
ListenInterface = "127.0.0.1"; | ||
ListenPort = 38274; | ||
} | ||
]; | ||
Presets = map | ||
(order: | ||
let | ||
ip = hostOrderToIP order; | ||
user = findUserIDWithIP ip; | ||
in | ||
{ | ||
Title = | ||
if user != null then "${user.id} (${ip})" else "${ip}"; | ||
Type = "SSH"; | ||
Host = "${ip}:22"; | ||
} | ||
) | ||
(ips.range); | ||
OnlyAllowPresetRemotes = true; | ||
}; | ||
}; | ||
|
||
services.diamondburned.caddy.sites = | ||
{ | ||
"http://ssh.acmcsuf.com" = '' | ||
reverse_proxy * localhost:38274 | ||
''; | ||
"http://vps.acmcsuf.com" = '' | ||
header Cache-Control "must-revalidate" | ||
handle /vps.json { | ||
root * ${pkgs.writeTextDir "vps.json" (builtins.toJSON config.acm.user-vms.usersInfo)} | ||
file_server | ||
} | ||
handle { | ||
root * ${vpsFiles} | ||
file_server | ||
} | ||
''; | ||
} // (builtins.listToAttrs (map (user: { | ||
name = ["http://${user.id}.vps.acmcsuf.com"]; | ||
value = '' | ||
reverse_proxy * http://${user.ip}:80 | ||
''; | ||
}) config.acm.user-vms.usersInfo)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" href="https://acmcsuf.com/favicon.png"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css" /> | ||
<title>vps.acmcsuf.com</title> | ||
|
||
<hgroup> | ||
<h1>vps.acmcsuf.com</h1> | ||
<p>Virtual private servers (VPS) provided to members of <a href="https://acmcsuf.com">ACM at CSUF</a>.</p> | ||
</hgroup> | ||
|
||
<section> | ||
<h2>SSH Usage</h2> | ||
<p> | ||
To work around the school's networking policies, SSH access must be done via | ||
<a href="https://ssh.acmcsuf.com">ssh.acmcsuf.com</a>. Simply wait for the | ||
page to load, then click on the <kbd>+</kbd> button and find your username | ||
on the list. | ||
</p> | ||
</section> | ||
|
||
<section> | ||
<h2>Users</h2> | ||
<ol class="users-list"> | ||
{{ range $i := until (len .users) }} | ||
<li> | ||
{{ $user := index .users $i }} | ||
{{ $info := index .usersInfo $i }} | ||
<b class="user-id">{{ $user.id }}</b> | ||
<span>(<span class="user-name">{{ $user.name }}</span>)</span> | ||
<ul class="users-info-list"> | ||
<li> | ||
<b>URL:</b> | ||
<a href="https://{{ $user.id }}.vps.acmcsuf.com">{{ $user.id }}.vps.acmcsuf.com</a> | ||
</li> | ||
<li> | ||
<b>SSH:</b> | ||
Check <a href="https://ssh.acmcsuf.com">ssh.acmcsuf.com</a> for your username. | ||
</li> | ||
</ul> | ||
</li> | ||
{{ end }} | ||
</ol> | ||
</section> | ||
|
||
<section> | ||
<h2>Extras</h2> | ||
<ul> | ||
<li><a href="/vps.json">JSON IP list</a></li> | ||
</ul> | ||
</section> | ||
|
||
<footer> | ||
<p> | ||
<span><a href="https://acmcsuf.com">ACM at CSUF</a></span> • | ||
<span>Provided by <a href="https://libdb.so">Diamond</a> with ❤️ and 🏳️⚧️</span> | ||
</p> | ||
</footer> |