From 87b48d473bdb41670c9f3b26a628f34c3c5c9481 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 3 Apr 2020 13:20:29 -0700 Subject: Rewrite buildGhc and buildGhcjs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I wanted to even further simplify the build tooling overhead. My general goal is to not have to think about declaring packages, or dependencies, or really anything that you might find in a cabal file. Not all of these goals are possible, but we can get pretty close. With this commit all I need for the 'buildGhc/buildGhcjs' functions is the path to the entrypoint file; everything else is either inferred by the Nix code or declared in the Haskell code comments. The strategy is to map a Haskell module to an executable artifact, and pass just that module to 'ghc --make'. Then we can rely on ghc to handle walking the local filesystem for imports. The only thing ghc really needs to know is a name for the output executable; it is hard to automatically infer this, so we have a simple comment syntax to declare this in the file. The comment syntax is inspired by existing Haskell 'LANGUAGE' pragmas; having this in the same file keeps the configuration as close to the real code as possible. The Nix code then extracts this info from the code comments, and sets the required ghc flags. Second, we need to declare the set of 3rd-party packages that our program relies on. For this we can re-use the same comment syntax and just list the dependencies, then extract them in Nix and construct a package set as we were before. This reduces the amount of "package declaration" code we have to write in default.nix, and reduces the amount of time we have to spend switching between the Haskell code and the Nix code (I find such context switching super annoying). I also think having the configuration in with the Haskell code encourages us to write smaller, simpler modules and only write code that we need. Additionally, I refactored the bild and ghci (now called 'repl') scripts to work in any directory. The .envrc uses direnv to set the path so that you can run these scripts anywhere. That means the following works: $ cd Run/Que $ bild Website $ repl Server λ> :l Run.Que.Server I find this to be a rather nice workflow. --- default.nix | 118 +++++------------------------------------------------------- 1 file changed, 8 insertions(+), 110 deletions(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index 5199252..41a1f0b 100644 --- a/default.nix +++ b/default.nix @@ -70,114 +70,12 @@ in rec { boot.enableContainers = true; }; }; - Com.InfluencedByBooks.Server = buildGhc { - name = "Com.InfluencedByBooks.Server"; - nick = "ibb"; - deps = [ - "clay" - "miso" - "protolude" - "servant" - "text" - "MonadRandom" - "acid-state" - "blaze-html" - "blaze-markup" - "bytestring" - "ixset" - "random" - "safecopy" - "scotty" - "servant-server" - "text" - ]; - }; - Com.InfluencedByBooks.Client = buildGhcjs { - name = "Com.InfluencedByBooks.Client"; - nick = "ibb"; - deps = [ - "clay" - "miso" - "protolude" - "servant" - "text" - "aeson" - "containers" - "ghcjs-base" - ]; - }; - Com.MusicMeetsComics = { - Server = buildGhc { - name = "Com.MusicMeetsComics.Server"; - nick = "mmc"; - deps = [ - "aeson" - "clay" - "containers" - "miso" - "protolude" - "servant" - "split" - "string-quote" - "text" - "dhall" - "ekg" - "fast-logger" - "http-types" - "katip" - "lucid" - "monad-logger" - "monad-metrics" - "mtl" - "network-uri" - "safe" - "servant-lucid" - "servant-server" - "split" - "wai" - "wai-app-static" - "wai-extra" - "wai-middleware-metrics" - "warp" - ]; - }; - Client = buildGhcjs { - name = "Com.MusicMeetsComics.Client"; - nick = "mmc"; - deps = [ - "aeson" - "clay" - "containers" - "miso" - "protolude" - "servant" - "split" - "string-quote" - "text" - "ghcjs-base" - ]; - }; - }; - Run.Que.Server = buildGhc { - name = "Run.Que.Server"; - nick = "que-server"; - deps = [ - "async" - "protolude" - "scotty" - "stm" - "unagi-chan" - "unordered-containers" - ]; - }; - Run.Que.Website = buildGhc { - name = "Run.Que.Website"; - nick = "que-website"; - deps = [ - "async" - "process" - "protolude" - "req" - ]; - }; + # Haskell targets + # + Com.InfluencedByBooks.Server = buildGhc Com/InfluencedByBooks/Server.hs; + Com.InfluencedByBooks.Client = buildGhcjs Com/InfluencedByBooks/Client.hs; + Com.MusicMeetsComics.Server = buildGhc Com/MusicMeetsComics/Server.hs; + Com.MusicMeetsComics.Client = buildGhcjs Com/MusicMeetsComics/Client.hs; + Run.Que.Server = buildGhc ./Run/Que/Server.hs; + Run.Que.Website = buildGhc ./Run/Que/Website.hs; } -- cgit v1.2.3