From 1981ee3ee7078a6bc7bb613d871885295c23b603 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Thu, 19 Jan 2017 14:34:12 +0100 Subject: warpspeed: init --- pkgs/profpatsch/warpspeed/default.nix | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pkgs/profpatsch/warpspeed/default.nix (limited to 'pkgs/profpatsch/warpspeed') diff --git a/pkgs/profpatsch/warpspeed/default.nix b/pkgs/profpatsch/warpspeed/default.nix new file mode 100644 index 00000000..a73169b5 --- /dev/null +++ b/pkgs/profpatsch/warpspeed/default.nix @@ -0,0 +1,34 @@ +{ lib, runCommand, ghcWithPackages }: + +let + name = "warpspeed-1.0"; + + script = builtins.toFile "${name}.hs" '' + {-# LANGUAGE OverloadedStrings #-} + module Main where + + import Safe + import System.Environment (getArgs) + import System.Exit (die) + import Network.Wai + import Network.Wai.Middleware.Static + import Network.Wai.Handler.Warp + import Network.HTTP.Types.Status + + main :: IO () + main = do + args <- getArgs + port <- case headMay args >>= readMay of + Just p -> pure $ p + Nothing -> die "please specify a port" + runEnv port $ static $ \_ resp -> resp $ responseLBS notFound404 [] "" + ''; + + deps = hp: with hp; [ wai-middleware-static warp safe ]; + +in runCommand name { + meta.description = "Trivial and very fast static HTTP file server"; +} '' + mkdir -p $out/bin + ${ghcWithPackages deps}/bin/ghc -O2 -Wall -o "$out/bin/warpspeed" ${script} +'' -- cgit 1.4.1