diff --git a/default.nix b/default.nix index 846ba81..830d384 100644 --- a/default.nix +++ b/default.nix @@ -1,20 +1,26 @@ -{ system ? builtins.currentSystem }: - +{ sources ? import ./nix/sources.nix, pkgs ? import { } }: let - sources = import ./nix/sources.nix; - pkgs = import { }; - printerfacts = import ./printerfacts.nix { inherit pkgs sources; }; - - name = "xena/printerfacts"; - tag = "latest"; - -in pkgs.dockerTools.buildLayeredImage { - inherit name tag; - contents = [ printerfacts ]; - - config = { - Cmd = [ "${printerfacts}/bin/printerfacts" ]; - Env = [ "RUST_LOG=info" ]; - WorkingDir = "/"; + srcNoTarget = dir: + builtins.filterSource + (path: type: type != "directory" || builtins.baseNameOf path != "target") + dir; + naersk = pkgs.callPackage sources.naersk { }; + gruvbox-css = pkgs.callPackage sources.gruvbox-css { }; + src = srcNoTarget ./.; + pfacts = naersk.buildPackage { + inherit src; + remapPathPrefix = true; }; +in pkgs.stdenv.mkDerivation { + inherit (pfacts) name; + inherit src; + phases = "installPhase"; + + installPhase = '' + mkdir -p $out/static + + cp -rf $src/templates $out/templates + cp -rf ${pfacts}/bin $out/bin + cp -rf ${gruvbox-css}/gruvbox.css $out/static/gruvbox.css + ''; } diff --git a/docker.nix b/docker.nix new file mode 100644 index 0000000..a3413ae --- /dev/null +++ b/docker.nix @@ -0,0 +1,20 @@ +{ system ? builtins.currentSystem }: + +let + sources = import ./nix/sources.nix; + pkgs = import { }; + printerfacts = import ./default.nix { inherit pkgs sources; }; + + name = "xena/printerfacts"; + tag = "latest"; + +in pkgs.dockerTools.buildLayeredImage { + inherit name tag; + contents = [ printerfacts ]; + + config = { + Cmd = [ "${printerfacts}/bin/printerfacts" ]; + Env = [ "RUST_LOG=info" ]; + WorkingDir = "/"; + }; +} diff --git a/printerfacts.nix b/printerfacts.nix deleted file mode 100644 index 830d384..0000000 --- a/printerfacts.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ sources ? import ./nix/sources.nix, pkgs ? import { } }: -let - srcNoTarget = dir: - builtins.filterSource - (path: type: type != "directory" || builtins.baseNameOf path != "target") - dir; - naersk = pkgs.callPackage sources.naersk { }; - gruvbox-css = pkgs.callPackage sources.gruvbox-css { }; - src = srcNoTarget ./.; - pfacts = naersk.buildPackage { - inherit src; - remapPathPrefix = true; - }; -in pkgs.stdenv.mkDerivation { - inherit (pfacts) name; - inherit src; - phases = "installPhase"; - - installPhase = '' - mkdir -p $out/static - - cp -rf $src/templates $out/templates - cp -rf ${pfacts}/bin $out/bin - cp -rf ${gruvbox-css}/gruvbox.css $out/static/gruvbox.css - ''; -} diff --git a/shell.nix b/shell.nix index 9798153..32fcb9e 100644 --- a/shell.nix +++ b/shell.nix @@ -1,6 +1,5 @@ let pkgs = import { }; - dhall = import { }; in pkgs.mkShell { buildInputs = with pkgs; [ rustc @@ -8,9 +7,6 @@ in pkgs.mkShell { cargo-watch rls rustfmt - - dhall.linux-dhall - dhall.linux-dhall-yaml ]; RUST_LOG = "info"; diff --git a/src/main.rs b/src/main.rs index 8a1f781..9dbd382 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,8 +57,12 @@ async fn main() -> anyhow::Result<()> { .and_then(index); let not_found_handler = warp::any().and_then(not_found); + let port = std::env::var("PORT") + .unwrap_or("5000".into()) + .parse::() + .expect("PORT to be a string-encoded u16"); - log::info!("listening on port 5000"); + log::info!("listening on port {}", port); warp::serve( fact_handler .or(index_handler) @@ -66,7 +70,7 @@ async fn main() -> anyhow::Result<()> { .or(not_found_handler) .with(warp::log(APPLICATION_NAME)), ) - .run(([0, 0, 0, 0], 5000)) + .run(([0, 0, 0, 0], port)) .await; Ok(()) }