Browse Source

fix

Signed-off-by: Christine Dodrill <[email protected]>
main
Cadey Ratio 11 months ago
parent
commit
b1f6e6d823
  1. 38
      default.nix
  2. 20
      docker.nix
  3. 26
      printerfacts.nix
  4. 4
      shell.nix
  5. 8
      src/main.rs

38
default.nix

@ -1,20 +1,26 @@
{ system ? builtins.currentSystem }:
{ sources ? import ./nix/sources.nix, pkgs ? import <nixpkgs> { } }:
let
sources = import ./nix/sources.nix;
pkgs = import <nixpkgs> { };
printerfacts = import ./printerfacts.nix { inherit pkgs sources; };
name = "xena/printerfacts";
tag = "latest";
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";
in pkgs.dockerTools.buildLayeredImage {
inherit name tag;
contents = [ printerfacts ];
installPhase = ''
mkdir -p $out/static
config = {
Cmd = [ "${printerfacts}/bin/printerfacts" ];
Env = [ "RUST_LOG=info" ];
WorkingDir = "/";
};
cp -rf $src/templates $out/templates
cp -rf ${pfacts}/bin $out/bin
cp -rf ${gruvbox-css}/gruvbox.css $out/static/gruvbox.css
'';
}

20
docker.nix

@ -0,0 +1,20 @@
{ system ? builtins.currentSystem }:
let
sources = import ./nix/sources.nix;
pkgs = import <nixpkgs> { };
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 = "/";
};
}

26
printerfacts.nix

@ -1,26 +0,0 @@
{ sources ? import ./nix/sources.nix, pkgs ? import <nixpkgs> { } }:
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
'';
}

4
shell.nix

@ -1,6 +1,5 @@
let
pkgs = import <nixpkgs> { };
dhall = import <dhall> { };
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";

8
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::<u16>()
.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(())
}

Loading…
Cancel
Save