unsplash / intlc

Compile ICU messages into code. Supports TypeScript and JSX. No runtime.
MIT License
56 stars 2 forks source link

Nix flakes & GHC 9.2.3 #161

Closed samhh closed 2 years ago

samhh commented 2 years ago

This PR includes several small quality of life improvements.

Nix

Flakes

https://nixos.wiki/wiki/Flakes

shell.nix has been replaced with flake.nix and flake.lock. This gives us fixed dependencies, but in a more ergonomic, standard, and safe way than how we've solved this in Web. The lockfile can be updated at any time with nix flake update.

The use of flake-utils in flake.nix is configuring a distinct setup for each possible system architecture. To not do so would require the use of --impure, which is best avoided as this offers us some guarantees about the reproducibility of our flake.

cc @unsplash/web Flakes are still technically considered experimental, so you'll need to enable flakes in your Nix installations like so:

If you're using direnv, you'll need to replace use nix with use flake and run direnv allow again.

This won't affect your usage of any projects not using flakes, such as Web. This repo can serve as a testbed for our use thereof.

Haskell

GHC 9.2

We've upgraded to GHC 9.2.3. Those of you on M1 Macs should experience faster compilation as per the release notes: https://www.haskell.org/ghc/blog/20211029-ghc-9.2.1-released.html

The new default set of language extensions, GHC2021, has been enabled.

The compiler and other build dependencies are available via Nix, however the language server needs to be installed externally. Ensure you're using at least version 1.7.0.0 of haskell-language-server, which should include a binary for 9.2.3.

If you've installed your Haskell stuff via ghcup you should be good to install what's needed provided you're on at least ghcup 0.0.7.

If you're using Nix for everything including the language server then a recent-ish nixpkgs should include support for 9.2.3.

Record dot syntax

The new OverloadedRecordDot extension has been enabled. This allows us to do the following:

data MyType = MyType { myField :: Int }

f :: MyType -> Int
f x = x.myField

Revolutionary.

Updating fields

A new extension for updating record fields has been created, OverloadedRecordUpdate, however this is still considered experimental so I've neglected to enable it.

Generated field selectors

GHC 9.2 includes support for the NoFieldSelectors extension. This prevents the compiler from automatically generating functions for all record fields, which in turn enables the use of field names such as id.

This caused a bit too much breakage to include in this PR.

OliverJAsh commented 2 years ago

@samhh I had a go at installing Flakes but I might need your help. Can we huddle sometime?