From 5c1f09360a280977655c57381693bca4216414fa Mon Sep 17 00:00:00 2001 From: xenofem Date: Thu, 28 Apr 2022 00:48:47 -0400 Subject: [PATCH 1/3] nix flakes --- .gitignore | 1 + flake.lock | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 59 ++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 6966f46..3e42fc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target /storage +/result \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ade9ae6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,111 @@ +{ + "nodes": { + "crate2nix": { + "flake": false, + "locked": { + "lastModified": 1650460722, + "narHash": "sha256-jk4SZ8iOnfJEceVULjyOAq4MrX9CfU5bCWMyZP9nJVA=", + "owner": "kolloch", + "repo": "crate2nix", + "rev": "78258f27fc3121562a44eb02c652a5ec77cf8d02", + "type": "github" + }, + "original": { + "owner": "kolloch", + "repo": "crate2nix", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1637014545, + "narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1651007983, + "narHash": "sha256-GNay7yDPtLcRcKCNHldug85AhAvBpTtPEJWSSDYBw8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e10da1c7f542515b609f8dfbcf788f3d85b14936", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1637453606, + "narHash": "sha256-Gy6cwUswft9xqsjWxFYEnx/63/qzaFUwatcbV5GF/GQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8afc4e543663ca0a6a4f496262cd05233737e732", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crate2nix": "crate2nix", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay", + "utils": "utils" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1651114831, + "narHash": "sha256-fbztwl7iIvnFwcm/u0Eigcvkl6uH97tEXUJqizbyl1k=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "89e658c1c8d81eeaad78750ab29975594f57eda2", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "utils": { + "locked": { + "lastModified": 1649676176, + "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b1d4057 --- /dev/null +++ b/flake.nix @@ -0,0 +1,59 @@ +{ + description = "transbeam: a low-latency file drop web app"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; + crate2nix = { + url = "github:kolloch/crate2nix"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, utils, rust-overlay, crate2nix }: let + name = "transbeam"; + in + utils.lib.eachDefaultSystem + (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ + rust-overlay.overlay + (final: prev: { + rustc = final.rust-bin.stable.latest.default; + cargo = final.rust-bin.stable.latest.default; + }) + ]; + }; + inherit (import "${crate2nix}/tools.nix" { inherit pkgs; }) + generatedCargoNix; + project = import + (generatedCargoNix { + inherit name; + src = ./.; + }) + { inherit pkgs; }; + in rec { + packages.${name} = pkgs.symlinkJoin { + inherit name; + paths = [ packages."${name}-unwrapped" ]; + buildInputs = [ pkgs.makeWrapper ]; + postBuild = '' + wrapProgram $out/bin/${name} \ + --set STATIC_DIR ${./static} + ''; + }; + + defaultPackage = packages.${name}; + + packages."${name}-unwrapped" = project.rootCrate.build; + + devShell = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ rustc cargo cargo-audit stdenv.cc ]; + RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + }; + } + ); +} From 720a4431a78f27f3d3263b84a7b1d2a57766865c Mon Sep 17 00:00:00 2001 From: xenofem Date: Thu, 28 Apr 2022 00:49:03 -0400 Subject: [PATCH 2/3] add more config/setup info to readme --- README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1cd25c6..f18d93e 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,30 @@ transbeam is configured with the following environment variables: - `STATIC_DIR`: path where the web app's static files live (default: `./static`) - `PORT`: port to listen on localhost for http requests (default: 8080) -## installation +It also uses the +[`env_logger`](https://docs.rs/env_logger/latest/env_logger/) crate +for logging; log levels are configured via the `RUST_LOG` variable, +see `env_logger`'s documentation for details. + +## running + +### nix flakes + +``` +nix run git+https://git.xeno.science/xenofem/transbeam?ref=main +``` + +(The Nix package is wrapped with `STATIC_DIR` set automatically to the +correct Nix store path, so it'll serve the static files properly +no matter what directory you run it from.) + +### non-nix + +``` +git clone https://git.xeno.science/xenofem/transbeam +cd transbeam +cargo run --release +``` ## todo From f68eb5f817d6aeb97904fcca9b9dddcf6fcbce46 Mon Sep 17 00:00:00 2001 From: xenofem Date: Thu, 28 Apr 2022 00:49:21 -0400 Subject: [PATCH 3/3] MIT license --- LICENSE | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..28f5d73 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright © 2022 xenofem + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.