From c08ff9489ff74f9f19d825511427c85d1e27d321 Mon Sep 17 00:00:00 2001 From: Beat Hagenlocher Date: Sun, 13 Oct 2024 16:25:41 +0200 Subject: [PATCH] Add basic haskell-nix setup (#544) * Add basic haskell-nix setup * Add suggested feedback * Add setup to main page & document nix flake --- .gitignore | 4 ++ CONTRIBUTING.md | 8 +++ README.md | 45 ++++++++++++ flake.lock | 186 ++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 51 +++++++++++++ 5 files changed, 294 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..7c45ea73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.direnv +result* +dist-newstyle +.pre-commit-config.yaml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a0418900..9ad6e559 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -182,11 +182,19 @@ but will appear before examples with a greater order. ## Reference: Technology choices +### JS + The website generated by `message-index` uses a few JS components. - [highlight.js](https://highlightjs.org/) for highlighting blocks of code. [License: BSD 3-Clause](https://github.com/highlightjs/highlight.js/blob/main/LICENSE). - [TableFilter](http://www.tablefilter.com/) for the filtering functionality in the error message table. [License: MIT](https://github.com/koalyptus/TableFilter/blob/master/LICENSE). +### Nix flake + +The Nix flake uses [flake-parts](https://flake.parts/), as well as the flake-parts modules for +- [haskell-flake](https://github.com/srid/haskell-flake) ([haskell-flake flake-parts module](https://flake.parts/options/haskell-flake)) +- [devshell](https://github.com/numtide/devshell) ([devshell flake-parts module](https://flake.parts/options/devshell)) + Generally speaking, we choose technology for this site based on the following criteria: * The build process for the site should be simple, relying on no build tools or package managers aside from `cabal` or `stack` diff --git a/README.md b/README.md index 6dd41ed1..b28440d4 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,51 @@ Today, the Haskell Message Index supports three tools. Any user-facing Haskell-r | GHCup | 0.1.19.0 | `GHCup-` | [/ghcup](https://errors.haskell.org/ghcup) | | Cabal | 3.12 | `Cabal-` | [/cabal](https://errors.haskell.org/cabal) | +## Setup + +This site is built with [Haskell](https://haskell.org) using the static-site generator [Hakyll](https://jaspervdj.be/hakyll/). + +### 'Normal' Install + +To run the site locally, you need to +0. [install Haskell & Cabal](https://www.haskell.org/ghcup/): +```shell +curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh +``` +1. Clone the Repo +```shell +git clone https://github.com/haskellfoundation/error-message-index.git +``` +2. Run it +```shell +cd error-message-index # yes, +cd message-index # both of those are needed +cabal update +cabal run -- site watch # Starts a web server on http://localhost:8000 +``` + +### with Nix + +To run the site with Nix, you need to have [Nix](https://nixos.org/) installed. You can install it via the [Determinate Systems installer](https://zero-to-nix.com/start/install): +```shell +curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install +``` +1. Clone the Repo +```shell +git clone https://github.com/haskellfoundation/error-message-index.git +``` +2. Run it +```shell +cd error-message-index # yes, +cd message-index # both of those are needed +nix develop +cabal run -- site watch # Starts a web server on http://localhost:8000 +``` + +For more on the Nix flake, have a look [here](./CONTRIBUTING.md#nix-flake). + +And now, since you're up and running, you can start [contributing](./CONTRIBUTING.md)! :) + ## Contributing to the Message Index Contributions may come in the form of changes to the code base, as well as opening or commenting on issues and pull requests. You are warmly invited to participate! diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..db675611 --- /dev/null +++ b/flake.lock @@ -0,0 +1,186 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1728330715, + "narHash": "sha256-xRJ2nPOXb//u1jaBnDP56M7v5ldavjbtR6lfGqSvcKg=", + "owner": "numtide", + "repo": "devshell", + "rev": "dd6b80932022cea34a019e2bb32f6fa9e494dfef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "haskell-flake": { + "locked": { + "lastModified": 1728227251, + "narHash": "sha256-JLDhMFyGyFe0QJAbCuSxB7/kjUCA7uUAMa6BFRORwXk=", + "owner": "srid", + "repo": "haskell-flake", + "rev": "9cbfbfc38f1fbf9a0f471795c84780211875fd45", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "haskell-flake", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1727825735, + "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1719082008, + "narHash": "sha256-jHJSUH619zBQ6WdC21fFAlDxHErKVDJ5fpN0Hgx4sjs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9693852a2070b398ee123a329e68f0dab5526681", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1728651332, + "narHash": "sha256-lm+asqDSTj0m6j1dtEte1/XG+uzZbwxS3tn7JLaBw84=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "06bb5971c139959d9a951f34e4264d32f5d998e7", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "haskell-flake": "haskell-flake", + "nixpkgs": "nixpkgs", + "parts": "parts", + "pre-commit-hooks": "pre-commit-hooks" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..a868aacd --- /dev/null +++ b/flake.nix @@ -0,0 +1,51 @@ +{ + nixConfig.allow-import-from-derivation = true; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + parts.url = "github:hercules-ci/flake-parts"; + haskell-flake.url = "github:srid/haskell-flake"; + pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + devshell.url = "github:numtide/devshell"; + devshell.inputs.nixpkgs.follows = "nixpkgs"; + }; + outputs = inputs: + inputs.parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; + imports = [ + inputs.devshell.flakeModule + inputs.haskell-flake.flakeModule + inputs.pre-commit-hooks.flakeModule + ]; + + perSystem = { + config, + pkgs, + ... + }: { + devshells.default = { + devshell = { + packagesFrom = [config.devShells.ghc96]; + packages = []; + startup = { + pre-commit.text = config.pre-commit.installationScript; + }; + }; + }; + pre-commit = { + check.enable = true; + settings.hooks = { + cabal-fmt.enable = true; + hlint.enable = true; + ormolu.enable = true; + + alejandra.enable = true; + deadnix.enable = true; + }; + }; + haskellProjects.ghc96 = { + basePackages = pkgs.haskell.packages.ghc96; + projectRoot = ./message-index; + }; + }; + }; +}