forked from garnix-io/nixcon-2024-player-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
89 lines (80 loc) · 3.84 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{
description = "NixCon 2024 - NixOS on garnix: Production-grade hosting as a game";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.garnix-lib = {
url = "github:garnix-io/garnix-lib";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, garnix-lib, flake-utils }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
webserver = let
pyFile = ''
#!${pkgs.python3}/bin/python3
import http.server
import socketserver
from http.server import BaseHTTPRequestHandler
PORT = 8080 # You can change this to any port you prefer
# Handler to serve files from the current directory
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/":
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(b"Hello, world! This is a 200 OK response.")
else:
self.send_response(404) # Not found for other paths.
self.end_headers()
# Setting up the HTTP server
with socketserver.TCPServer(("", PORT), SimpleHTTPRequestHandler) as httpd:
print(f"Serving at port {PORT}")
httpd.serve_forever()
'';
in
pkgs.stdenv.mkDerivation {
name = "webserver";
src = ./.;
unpackPhase = "true";
buildPhase = ":";
installPhase = ''
mkdir -p $out/bin
echo -e '${pyFile}' > $out/bin/webserver
chmod +x $out/bin/webserver
'';
};
in
{
inherit webserver;
nixosConfigurations.server = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
garnix-lib.nixosModules.garnix
self.nixosModules.nixcon-garnix-player-module
({ pkgs, ... }: {
playerConfig = {
# Your github user:
githubLogin = "oscar-schwarz";
# You only need to change this if you changed the forked repo name.
githubRepo = "nixcon-2024-player-template";
# The nix derivation that will be used as the server process. It
# should open a webserver on port 8080.
# The port is also provided to the process as the environment variable "PORT".
webserver = webserver;
# If you want to log in to your deployed server, put your SSH key
# here:
sshKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIENriTFSJUHgHp+fGE2FjssfvIl6DoCTxLZj5I0ihjf4";
};
})
];
};
nixosModules.nixcon-garnix-player-module = ./nixcon-garnix-player-module.nix;
nixosModules.default = self.nixosModules.nixcon-garnix-player-module;
# Remove before starting the workshop - this is just for development
#checks = import ./checks.nix { inherit nixpkgs self; };
};
}