From 82cf960ccde54dfef9f7b3edd9935c0bd0ef16e4 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Tue, 14 Jul 2020 17:40:11 -0400 Subject: [PATCH] prepare for serving in docker --- docker.nix | 8 +++++--- scripts/nixrun.sh | 4 ---- site.nix | 21 ++++++++++++++++++--- src/main.rs | 2 +- 4 files changed, 24 insertions(+), 11 deletions(-) delete mode 100755 scripts/nixrun.sh diff --git a/docker.nix b/docker.nix index 7b4dd30..1dcc5ea 100644 --- a/docker.nix +++ b/docker.nix @@ -1,7 +1,8 @@ { system ? builtins.currentSystem }: let - pkgs = import (import ./nix/sources.nix).nixpkgs { inherit system; }; + sources = import ./nix/sources.nix; + pkgs = import sources.nixpkgs { inherit system; }; callPackage = pkgs.lib.callPackageWith pkgs; site = callPackage ./site.nix { }; @@ -10,11 +11,12 @@ let name = "xena/christinewebsite"; tag = "latest"; - contents = [ pkgs.cacert ]; + contents = [ pkg ]; config = { Cmd = [ "${pkg}/bin/xesite" ]; - WorkingDir = "${pkg}/"; + Env = [ "CONFIG_FNAME=${pkg}/config.dhall" "RUST_LOG=info" ]; + WorkingDir = "/"; }; }; diff --git a/scripts/nixrun.sh b/scripts/nixrun.sh deleted file mode 100755 index 1ea655d..0000000 --- a/scripts/nixrun.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -cd "$(dirname "$0")"/.. -./bin/site diff --git a/site.nix b/site.nix index b96ca86..b917edd 100644 --- a/site.nix +++ b/site.nix @@ -6,24 +6,39 @@ let builtins.filterSource (path: type: type != "directory" || builtins.baseNameOf path != "target") dir; + naersk = pkgs.callPackage sources.naersk { }; - gruvbox-css = pkgs.callPackage sources.gruvbox-css { }; + dhallpkgs = import sources.easy-dhall-nix { inherit pkgs; }; src = srcNoTarget ./.; + xesite = naersk.buildPackage { inherit src; buildInputs = [ pkg-config openssl ]; remapPathPrefix = true; }; + config = stdenv.mkDerivation { + pname = "xesite-config"; + version = "HEAD"; + buildInputs = [ dhallpkgs.dhall-simple ]; + + phases = "installPhase"; + + installPhase = '' + cd ${src} + dhall resolve < ${src}/config.dhall >> $out + ''; + }; + in pkgs.stdenv.mkDerivation { inherit (xesite) name; inherit src; phases = "installPhase"; installPhase = '' - mkdir -p $out $out/blog $out/css $out/gallery $out/static $out/talks $out/bin + mkdir -p $out $out/bin - cp -rf $src/config.dhall $out/config.dhall + cp -rf ${config} $out/config.dhall cp -rf $src/blog $out/blog cp -rf $src/css $out/css cp -rf $src/gallery $out/gallery diff --git a/src/main.rs b/src/main.rs index 8fce749..f961009 100644 --- a/src/main.rs +++ b/src/main.rs @@ -135,7 +135,7 @@ async fn main() -> Result<()> { .with(warp::log(APPLICATION_NAME)) .recover(handlers::rejection); - warp::serve(site).run(([127, 0, 0, 1], 3030)).await; + warp::serve(site).run(([0, 0, 0, 0], 3030)).await; Ok(()) }