Skip to content

Commit

Permalink
Merge pull request #269 from SupercedeTech/add-better-nix-infratstruc…
Browse files Browse the repository at this point in the history
…ture

Add better nix infrastructure that doesn't need to be kept up to date with cabal file
  • Loading branch information
jappeace authored May 13, 2022
2 parents 2a4dfde + 3aa1dd5 commit 1bd7e25
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
# signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
# # Only needed for private caches
# #authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
# - run: nix-build nix/ci.nix
- run: nix-build .
- run: nix-shell --run "cd incoming; make all"
8 changes: 8 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ pkgs ? import ./nix/pkgs.nix, ... }:
let
ignore = import (builtins.fetchGit {
url = "https://github.com/hercules-ci/gitignore.nix";
rev = "bff2832ec341cf30acb3a4d3e2e7f1f7b590116a";
}) { inherit (pkgs) lib; };
in
pkgs.haskellPackages.callCabal2nix "keter" (ignore.gitignoreSource ./.) { }
3 changes: 1 addition & 2 deletions incoming/foo/hello.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import Control.Monad.IO.Class
import qualified Data.ByteString.Lazy.Char8 as L8
import Data.Default
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Handler.Warp
Expand All @@ -20,7 +19,7 @@ main = do
portS <- getEnv "PORT"
env <- getEnvironment
let port = read portS
logger <- mkRequestLogger def
logger <- mkRequestLogger defaultRequestLoggerSettings
{ outputFormat = Apache FromHeader
}
run port $ logger $ \req send -> do
Expand Down
3 changes: 1 addition & 2 deletions incoming/foo1_0/hello.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import Control.Monad.IO.Class
import qualified Data.ByteString.Lazy.Char8 as L8
import Data.Default
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Handler.Warp
Expand All @@ -19,7 +18,7 @@ main = do
portS <- getEnv "PORT"
env <- getEnvironment
let port = read portS
logger <- mkRequestLogger def
logger <- mkRequestLogger defaultRequestLoggerSettings
{ outputFormat = Apache FromHeader
}
run port $ logger $ \req send -> do
Expand Down
5 changes: 3 additions & 2 deletions incoming/websockets/chat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import Yesod.WebSockets

data App = App (TChan Text)

instance Yesod App

mkYesod "App" [parseRoutes|
/ HomeR GET
|]

instance Yesod App

chatApp :: WebSocketsT Handler ()
chatApp = do
sendTextData ("Welcome to the chat server, please enter your name." :: Text)
Expand All @@ -35,7 +36,7 @@ chatApp = do
dupTChan writeChan
race_
(forever $ atomically (readTChan readChan) >>= sendTextData)
(sourceWS $$ CL.mapM_ (\msg ->
(runConduit $ sourceWS .| CL.mapM_ (\msg ->
atomically $ writeTChan writeChan $ name <> ": " <> msg))

getHomeR :: Handler Html
Expand Down
4 changes: 2 additions & 2 deletions nix/pin.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import (builtins.fetchGit {
# Descriptive name to make the store path easier to identify
name = "nixos-pin-2022.03.02";
name = "nixos-pin-2022.05.13";
url = "https://github.com/nixos/nixpkgs/";
rev = "5d5de3be19855371eecbea5fd500818925ec109d";
rev = "6925d06dd1e2039835ffe749cda11660431ffefa";
})
13 changes: 13 additions & 0 deletions nix/pkgs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ./pin.nix {
config = {

packageOverrides = pkgs: {

haskell = pkgs.lib.recursiveUpdate pkgs.haskell {
packageOverrides = hpNew: hpOld: {
keter = hpNew.callPackage ../default.nix {};
};
};
};
};
}
67 changes: 14 additions & 53 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,54 +1,15 @@
{ nixpkgs ? import ./nix/pin.nix {}, compiler ? "default", doBenchmark ? false }:

let

inherit (nixpkgs) pkgs;

f = { mkDerivation, aeson, array, async, attoparsec, base
, blaze-builder, bytestring, case-insensitive, conduit
, conduit-extra, containers, data-default, directory, filepath
, fsnotify, hspec, http-client, http-conduit, http-reverse-proxy
, http-types, HUnit, indexed-traversable, lib, lifted-base, mtl
, network, optparse-applicative, process, random, regex-tdfa, stm
, tar, template-haskell, text, time, tls, tls-session-manager
, transformers, unix, unix-compat, unordered-containers, vector
, wai, wai-app-static, wai-extra, warp, warp-tls, yaml, zlib
, cabal-install, yesod, stm-lifted, yesod-websockets
}:
mkDerivation {
pname = "keter";
version = "1.5";
src = ./.;
isLibrary = true;
isExecutable = true;
libraryToolDepends = [ cabal-install ];
libraryHaskellDepends = [
aeson array async attoparsec base blaze-builder bytestring
case-insensitive conduit conduit-extra containers data-default
directory filepath fsnotify http-client http-conduit
http-reverse-proxy http-types indexed-traversable lifted-base mtl
network optparse-applicative process random regex-tdfa stm tar
template-haskell text time tls tls-session-manager transformers
unix unix-compat unordered-containers vector wai wai-app-static
wai-extra warp warp-tls yaml zlib yesod stm-lifted yesod-websockets
{ pkgs ? import ./nix/pkgs.nix, ... }:
pkgs.haskellPackages.shellFor {
packages = ps : [ ps.keter ];
# this is to build the examples from incoming
extraDependencies = ps: {
libraryHaskellDepends = [
ps.yesod-websockets
ps.yesod-core
ps.stm-lifted
];
};
buildInputs = [
pkgs.cabal-install
];
executableHaskellDepends = [ base data-default filepath ];
testHaskellDepends = [
base bytestring conduit hspec HUnit transformers unix
];
homepage = "http://www.yesodweb.com/";
description = "Web application deployment manager, focusing on Haskell web frameworks";
license = lib.licenses.mit;
};

haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};

variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;

drv = variant (haskellPackages.callPackage f {});

in

if pkgs.lib.inNixShell then drv.env else drv
}

0 comments on commit 1bd7e25

Please sign in to comment.