From 6c2454fb9edff9bdd34415e58a2a3782a984ec5a Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sun, 22 Jan 2023 17:22:29 +0100 Subject: switch to ghc 9.0.2 this makes the nix builds /much/ nicer --- default.nix | 50 ++++++++++++++++++++++++++++++----------------- lib/Server/ControlRoom.hs | 28 +------------------------- lib/Yesod/Orphans.hs | 45 ++++++++++++++++++++++++++++++++++++++++++ tracktrain.cabal | 21 +++++--------------- 4 files changed, 83 insertions(+), 61 deletions(-) create mode 100644 lib/Yesod/Orphans.hs diff --git a/default.nix b/default.nix index a8c75d8..f714fdf 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,4 @@ -{ nixpkgs ? import {}, compiler ? "ghc8107", doBenchmark ? false }: +{ nixpkgs ? import {}, compiler ? "ghc902", doBenchmark ? false }: let @@ -7,32 +7,36 @@ let f = { mkDerivation, aeson, base, blaze-html, blaze-markup , bytestring, cassava, conduit, conferer, conferer-aeson , conferer-warp, conferer-yaml, containers, data-default-class - , directory, either, extra, fmt, http-api-data, http-media, lens - , lib, monad-logger, mtl, path-pieces, persistent - , persistent-postgresql, protocol-buffers + , directory, either, exceptions, extra, fmt, hoauth2, http-api-data + , http-media, insert-ordered-containers, lens, lib, monad-logger + , mtl, path-pieces, persistent, persistent-postgresql + , prometheus-client, prometheus-metrics-ghc, protocol-buffers , protocol-buffers-descriptor, regex-tdfa, resource-pool, servant , servant-docs, servant-server, servant-swagger, servant-websockets , shakespeare, stm, swagger2, text, time, timezone-olson - , timezone-series, transformers, unliftio-core, uuid, vector - , vector-algorithms, wai-extra, warp, websockets, yesod, yesod-form - , zip-archive, prometheus-client, prometheus-metrics-ghc + , timezone-series, transformers, unliftio-core, uri-bytestring + , uuid, vector, vector-algorithms, wai-extra, warp, websockets + , yesod, yesod-auth, yesod-auth-oauth2, yesod-core, yesod-form + , zip-archive }: mkDerivation { pname = "tracktrain"; version = "0.1.0.0"; src = ./.; - isLibrary = true; + isLibrary = false; isExecutable = true; libraryHaskellDepends = [ aeson base blaze-html blaze-markup bytestring cassava conduit - conferer conferer-warp containers either extra fmt http-api-data - http-media lens monad-logger mtl path-pieces persistent - persistent-postgresql protocol-buffers protocol-buffers-descriptor - regex-tdfa resource-pool servant servant-docs servant-server - servant-swagger servant-websockets shakespeare stm swagger2 text - time timezone-olson timezone-series transformers unliftio-core uuid - vector vector-algorithms warp websockets yesod yesod-form - zip-archive prometheus-client prometheus-metrics-ghc + conferer conferer-warp containers either exceptions extra fmt + hoauth2 http-api-data http-media insert-ordered-containers lens + monad-logger mtl path-pieces persistent persistent-postgresql + prometheus-client prometheus-metrics-ghc protocol-buffers + protocol-buffers-descriptor regex-tdfa resource-pool servant + servant-docs servant-server servant-swagger servant-websockets + shakespeare stm swagger2 text time timezone-olson timezone-series + transformers unliftio-core uri-bytestring uuid vector + vector-algorithms warp websockets yesod yesod-auth + yesod-auth-oauth2 yesod-core yesod-form zip-archive ]; executableHaskellDepends = [ aeson base bytestring conferer conferer-aeson conferer-yaml @@ -42,7 +46,7 @@ let doHaddock = false; description = "tracktrain tracks trains on their traintracks"; license = "unknown"; - hydraPlatforms = lib.platforms.none; + mainProgram = "tracktrain"; }; haskellPackages = if compiler == "default" @@ -51,7 +55,17 @@ let variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id; - drv = variant (haskellPackages.callPackage f {}); + # we can override haskell packages in nix here; but attempt to minimise that + # since builds get pretty expensive when we do. + hpkgs = haskellPackages.override { + overrides = self: super: with pkgs.haskell.lib; { + # hoauth2 = doDistribute super.hoauth2_2_6_0; + # cryptonite = doDistribute super.cryptonite_0_30; + # memory = doDistribute super.memory_0_18_0; + }; + }; + + drv = variant (hpkgs.callPackage f {}); # this removes the /lib directory from the built derivation, which depends on ghc. # this dramatically reduces closure size diff --git a/lib/Server/ControlRoom.hs b/lib/Server/ControlRoom.hs index 11e72d5..f08abcb 100644 --- a/lib/Server/ControlRoom.hs +++ b/lib/Server/ControlRoom.hs @@ -64,6 +64,7 @@ import Numeric (showFFloat) import Persist import Yesod.Auth.OpenId (IdentifierType (..), authOpenId) import Yesod.Auth.Uffd (UffdUser (..), uffdClient) +import Yesod.Orphans () data ControlRoom = ControlRoom @@ -462,30 +463,3 @@ mightbe :: Maybe Text -> Text mightbe (Just a) = a mightbe Nothing = "" ---- some orphans to make hamlet easier to deal with -instance ToMarkup Time where - toMarkup time = - toMarkup (show time) - -instance ToMarkup Day where - toMarkup day = toMarkup (iso8601Show day) - -instance ToMessage UTCTime where - toMessage = formatW3 - -instance ToMessage Token where - toMessage (Token uuid) = UUID.toText uuid - -instance ToMarkup UTCTime where - toMarkup = toMarkup . formatW3 - -instance ToMarkup Token where - toMarkup (Token uuid) = toMarkup (UUID.toText uuid) - -instance ToMessage Double where - toMessage = T.pack . show - -instance ToMarkup Seconds where - toMarkup (Seconds s) = - if s > 0 then toMarkup ("+"+|s `div` 60|+"" :: Text) - else toMarkup (s `div` 60) diff --git a/lib/Yesod/Orphans.hs b/lib/Yesod/Orphans.hs new file mode 100644 index 0000000..f66f8af --- /dev/null +++ b/lib/Yesod/Orphans.hs @@ -0,0 +1,45 @@ +-- | a module containing orphan shakespeare instances to make writing templates +-- a bit more fun & less of a hassle. +module Yesod.Orphans where + +import Data.Text (Text) +import qualified Data.Text as T +import Data.Time (UTCTime) +import Data.Time.Calendar (Day) +import Data.Time.Format.ISO8601 (iso8601Show) +import Data.UUID (UUID) +import qualified Data.UUID as UUID +import Fmt ((+|), (|+)) +import GTFS +import Persist +import Text.Blaze.Html (ToMarkup (..)) +import Text.Shakespeare.Text +import Yesod + +--- some orphans to make hamlet easier to deal with +instance ToMarkup Time where + toMarkup time = + toMarkup (show time) + +instance ToMarkup Day where + toMarkup day = toMarkup (iso8601Show day) + +instance ToMessage UTCTime where + toMessage = formatW3 + +instance ToMessage Token where + toMessage (Token uuid) = UUID.toText uuid + +instance ToMarkup UTCTime where + toMarkup = toMarkup . formatW3 + +instance ToMarkup Token where + toMarkup (Token uuid) = toMarkup (UUID.toText uuid) + +instance ToMessage Double where + toMessage = T.pack . show + +instance ToMarkup Seconds where + toMarkup (Seconds s) = + if s > 0 then toMarkup ("+"+|s `div` 60|+"" :: Text) + else toMarkup (s `div` 60) diff --git a/tracktrain.cabal b/tracktrain.cabal index c373b66..d1acb1c 100644 --- a/tracktrain.cabal +++ b/tracktrain.cabal @@ -24,7 +24,7 @@ extra-source-files: CHANGELOG.md executable tracktrain main-is: Main.hs ghc-options: -threaded -rtsopts - build-depends: base ^>=4.14.3.0 + build-depends: base ^>=4.15.1.0 , bytestring >= 0.10.10.0 , fmt >= 0.6.3.0 , time @@ -47,21 +47,9 @@ executable tracktrain default-extensions: OverloadedStrings , ScopedTypeVariables --- executable gen-js --- main-is: GenJS.hs --- build-depends: base ^>=4.14.3.0 --- , servant-js --- , tracktrain --- , universum --- hs-source-dirs: app --- default-language: Haskell2010 --- default-extensions: OverloadedStrings --- , ScopedTypeVariables --- , NoImplicitPrelude - library - build-depends: base ^>=4.14.3.0 + build-depends: base ^>=4.15.1.0 , gtfs , protocol-buffers , zip-archive @@ -79,7 +67,7 @@ library , warp , uuid >= 1.3 , stm - , containers >= 0.6.5 + , containers , swagger2 , servant-swagger , servant-docs @@ -128,13 +116,14 @@ library , Config other-modules: Server.Util , Yesod.Auth.Uffd + , Yesod.Orphans default-language: Haskell2010 default-extensions: OverloadedStrings , ScopedTypeVariables , ViewPatterns library gtfs - build-depends: base ^>=4.14.3.0 + build-depends: base ^>=4.15.1.0 , protocol-buffers , protocol-buffers-descriptor , servant -- cgit v1.2.3