From ec7db3ca0400a9806da24617a8d700ca7dbe01f3 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Sat, 17 Dec 2022 12:29:11 -0500 Subject: [PATCH] Nixify scripts using mission-control (#72) https://github.com/Platonic-Systems/mission-control --- .vscode/tasks.json | 12 ++++++++---- README.md | 5 +++-- bin/hoogle | 5 ----- bin/repl | 4 ---- bin/run | 4 ---- flake.lock | 34 ++++++++++++++++++++++++++++++++++ flake.nix | 42 +++++++++++++++++++++++++++++++++++++++--- garnix.yaml | 2 +- src/Main.hs | 2 +- 9 files changed, 86 insertions(+), 24 deletions(-) delete mode 100755 bin/hoogle delete mode 100755 bin/repl delete mode 100755 bin/run diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d300c5a..dcfb5e3 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,10 +6,14 @@ { "label": "Ghcid", "type": "shell", - // You may also use bin/run-via-tmux if you have tmux // This is useful if you often see ghost ghcid left behind by VSCode reloads. - "command": "bin/run", - "args": [], + "command": "nix", + "args": [ + "develop", + "-c", + ",", + "run" + ], "problemMatcher": [], "group": { "kind": "build", @@ -20,4 +24,4 @@ } } ] -} +} \ No newline at end of file diff --git a/README.md b/README.md index f1d32ac..4bf7940 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,13 @@ Get a Haskell development environment up and running quickly. Thanks to Nix, thi - [fourmolu](https://github.com/fourmolu/fourmolu) autoformatting - [Relude](https://github.com/kowainik/relude#relude) as Prelude. - `.hlint.yaml` is [from relude](https://github.com/kowainik/relude/blob/main/.hlint.yaml) +- Devshell scripts (`,` prefixed) are provided via [mission-control](https://github.com/Platonic-Systems/mission-control) If you have an *existing* Haskell project, you should probably use https://github.com/srid/haskell-flake instead. ## Getting Started -*tldr: Install Nix, enable Flakes, open in VSCode and run `bin/run`.* +*tldr: Install Nix, enable Flakes, open in VSCode and run `, run`.* For details, see: https://srid.ca/haskell-template/start @@ -21,7 +22,7 @@ For details, see: https://srid.ca/haskell-template/start - Run `nix flake update` to update all flake inputs. - Run `nix --option sandbox false build .#check -L` to run the flake checks. - Run `treefmt` in nix shell to autoformat the project. This uses [treefmt](https://github.com/numtide/treefmt), which uses `./treefmt.toml` (where fourmolu and nixpkgs-fmt are specified). -- Run `bin/hoogle` to start Hoogle with packages in your cabal file. +- Run `, docs` to start Hoogle with packages in your cabal file. - Run the application without installing: `nix run github:srid/haskell-template` (or `nix run .` from checkout) - Common workflows - Adding library dependencies in Nix: https://srid.ca/haskell-template/dependency diff --git a/bin/hoogle b/bin/hoogle deleted file mode 100755 index e7f8b04..0000000 --- a/bin/hoogle +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -xe - -echo http://127.0.0.1:8888 -exec nix develop -i -c hoogle serve -p 8888 --local diff --git a/bin/repl b/bin/repl deleted file mode 100755 index 7661e72..0000000 --- a/bin/repl +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -xe - -exec nix develop -i -c cabal -- repl diff --git a/bin/run b/bin/run deleted file mode 100755 index 95e6090..0000000 --- a/bin/run +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -xe - -exec nix develop -i -c ghcid -c "cabal repl exe:haskell-template" --warnings -T :main diff --git a/flake.lock b/flake.lock index 0bcefb0..020a03f 100644 --- a/flake.lock +++ b/flake.lock @@ -18,6 +18,21 @@ "type": "github" } }, + "flake-root": { + "locked": { + "lastModified": 1671295174, + "narHash": "sha256-5K+wdsB5TYSmI6HeexOMvJTZTBdXb9RbiFwXRtQkE3M=", + "owner": "srid", + "repo": "flake-root", + "rev": "bb96b89f65d7c47457303f2385798a09f4a1dd5a", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "flake-root", + "type": "github" + } + }, "haskell-flake": { "locked": { "lastModified": 1668167720, @@ -33,6 +48,24 @@ "type": "github" } }, + "mission-control": { + "inputs": { + "flake-root": "flake-root" + }, + "locked": { + "lastModified": 1671297603, + "narHash": "sha256-0fotrPbgV4WyJwh9RZ/eSWALMeAKr+n3JCQZU130BLI=", + "owner": "Platonic-Systems", + "repo": "mission-control", + "rev": "ede1ce90f17223f32ae21f2b12b8c26fd95a707e", + "type": "github" + }, + "original": { + "owner": "Platonic-Systems", + "repo": "mission-control", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1670148586, @@ -71,6 +104,7 @@ "inputs": { "flake-parts": "flake-parts", "haskell-flake": "haskell-flake", + "mission-control": "mission-control", "nixpkgs": "nixpkgs", "treefmt-flake": "treefmt-flake" } diff --git a/flake.nix b/flake.nix index 80d28a0..f136faa 100644 --- a/flake.nix +++ b/flake.nix @@ -5,6 +5,7 @@ flake-parts.url = "github:hercules-ci/flake-parts"; haskell-flake.url = "github:srid/haskell-flake"; treefmt-flake.url = "github:srid/treefmt-flake"; + mission-control.url = "github:Platonic-Systems/mission-control"; }; outputs = inputs@{ self, nixpkgs, flake-parts, ... }: @@ -13,9 +14,11 @@ imports = [ inputs.haskell-flake.flakeModule inputs.treefmt-flake.flakeModule + inputs.mission-control.flakeModule ]; - perSystem = { self', config, pkgs, ... }: { - haskellProjects.default = { + perSystem = { self', lib, config, pkgs, ... }: { + # The "main" project. You can have multiple projects, but this template has only one. + haskellProjects.main = { packages = { haskell-template.root = ./.; }; @@ -34,7 +37,40 @@ cabal-fmt fourmolu; }; - packages.default = self'.packages.haskell-template; + mission-control.scripts = { + docs = { + description = "Start Hoogle server for project dependencies"; + command = '' + echo http://127.0.0.1:8888 + hoogle serve -p 8888 --local + ''; + category = "Dev Tools"; + }; + repl = { + description = "Start the cabal repl"; + command = '' + cabal repl "$@" + ''; + category = "Dev Tools"; + }; + fmt = { + description = "Auto-format the source tree"; + command = "treefmt"; + category = "Dev Tools"; + }; + run = { + description = "Run the project with ghcid auto-recompile"; + command = '' + ghcid -c "cabal repl exe:haskell-template" --warnings -T :main + ''; + category = "Primary"; + }; + }; + packages.default = self'.packages.main-haskell-template; + devShells.default = + config.mission-control.installToDevShell config.devShells.main; }; }; } + + diff --git a/garnix.yaml b/garnix.yaml index 27ddbb5..2239ede 100644 --- a/garnix.yaml +++ b/garnix.yaml @@ -4,4 +4,4 @@ builds: - "*.x86_64-linux.*" exclude: # https://github.com/srid/haskell-flake/issues/21 - - "checks.*.default-hls" + - "checks.*.main-hls" diff --git a/src/Main.hs b/src/Main.hs index e4b7af5..fc5ea8d 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -5,7 +5,7 @@ import Main.Utf8 qualified as Utf8 {- | Main entry point. - The `bin/run` script will invoke this function. + The `, run` script will invoke this function. -} main :: IO () main = do