Start project by uncommenting section 1
Change-Id: Id3a4f213f5a1b0626b8183818c2a67b3ea22c4f0
Reviewed-on: https://git.clicks.codes/c/Clicks/BYO/HttpServer/rust/+/245
Tested-by: Skyler Grey <minion@clicks.codes>
Reviewed-by: Skyler Grey <minion@clicks.codes>
diff --git a/.envrc b/.envrc
new file mode 100644
index 0000000..443b0ee
--- /dev/null
+++ b/.envrc
@@ -0,0 +1 @@
+use_flake .
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 73fab07..8ed082c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,5 @@
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
+
+.direnv/
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..f3770be
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "nixEnvSelector.nixFile": "${workspaceRoot}/flake.nix"
+}
\ No newline at end of file
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..55e027b
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,100 @@
+{
+ "nodes": {
+ "fenix": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ],
+ "rust-analyzer-src": "rust-analyzer-src"
+ },
+ "locked": {
+ "lastModified": 1704867811,
+ "narHash": "sha256-pG4O1vPpNSMjz7p/5x+/OH4tXC0thzAPbJ55kI/W5dU=",
+ "owner": "nix-community",
+ "repo": "fenix",
+ "rev": "93e89638c15512db65e931f26ce36edf8cfbb4a5",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-community",
+ "repo": "fenix",
+ "type": "github"
+ }
+ },
+ "flake-utils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1701680307,
+ "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1704842529,
+ "narHash": "sha256-OTeQA+F8d/Evad33JMfuXC89VMetQbsU4qcaePchGr4=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "eabe8d3eface69f5bb16c18f8662a702f50c20d5",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixpkgs-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "fenix": "fenix",
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs"
+ }
+ },
+ "rust-analyzer-src": {
+ "flake": false,
+ "locked": {
+ "lastModified": 1704833483,
+ "narHash": "sha256-Ox01mpYmjapNYaqOu4fMS/4Ma9NLd2rVNz6d4rJmcf4=",
+ "owner": "rust-lang",
+ "repo": "rust-analyzer",
+ "rev": "ae6e73772432cfe35bb0ff6de6fdcfa908642b67",
+ "type": "github"
+ },
+ "original": {
+ "owner": "rust-lang",
+ "ref": "nightly",
+ "repo": "rust-analyzer",
+ "type": "github"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..efbc84d
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,35 @@
+{
+ description = "A basic flake with a shell";
+ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+ inputs.flake-utils.url = "github:numtide/flake-utils";
+ inputs.fenix = {
+ url = "github:nix-community/fenix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+
+ outputs = { nixpkgs, flake-utils, fenix, ... }:
+ flake-utils.lib.eachDefaultSystem (system:
+ let
+ pkgs = import nixpkgs {
+ inherit system;
+ overlays = [ fenix.overlays.default ];
+ };
+ in
+ {
+ devShells.default = pkgs.mkShell {
+ packages = [
+ (pkgs.fenix.stable.withComponents [
+ "cargo"
+ "clippy"
+ "rust-src"
+ "rustc"
+ "rustfmt"
+ "rust-analyzer"
+ ])
+ pkgs.bacon
+ pkgs.pkg-config
+ pkgs.openssl
+ ];
+ };
+ });
+}
diff --git a/src/main.rs b/src/main.rs
index 01f209e..f85bd02 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,22 +1,16 @@
-// Uncomment this block to pass the first stage
-// use std::net::TcpListener;
+use std::net::TcpListener;
fn main() {
- // You can use print statements as follows for debugging, they'll be visible when running tests.
- println!("Logs from your program will appear here!");
-
- // Uncomment this block to pass the first stage
- //
- // let listener = TcpListener::bind("127.0.0.1:4221").unwrap();
- //
- // for stream in listener.incoming() {
- // match stream {
- // Ok(_stream) => {
- // println!("accepted new connection");
- // }
- // Err(e) => {
- // println!("error: {}", e);
- // }
- // }
- // }
+ let listener = TcpListener::bind("127.0.0.1:4221").unwrap();
+
+ for stream in listener.incoming() {
+ match stream {
+ Ok(_stream) => {
+ println!("accepted new connection");
+ }
+ Err(e) => {
+ println!("error: {}", e);
+ }
+ }
+ }
}