diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 597a6d0..36fc3a8 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,7 @@ e2e/test-results/ e2e/playwright-report/ tmp/ + +result + +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0b7e98c --- /dev/null +++ b/flake.lock @@ -0,0 +1,77 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1782949081, + "narHash": "sha256-vp6Y/Grm98ESt6ceOkWiHWyZRDV3J1RID4w+6NWK9yA=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "17c9d6cdfc60c64f4ee8d306f9bc0b4ccb51481e", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "haskell-flake": { + "locked": { + "lastModified": 1785340889, + "narHash": "sha256-W3VSD3CKNF/WSLwS+A4ru1pXb2J8GN1xi4MjWacpwJA=", + "owner": "srid", + "repo": "haskell-flake", + "rev": "ec69967e95d7e93b58d9f7cdd384432cb42d37ee", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "haskell-flake", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1785301185, + "narHash": "sha256-eoS3KQTO0aPWXZvIaRbRAzSSHW3l5wdMFXtT1ISfoKA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "9bc02893134c733dd85de46ee4fb2fac696b5529", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1782614948, + "narHash": "sha256-ePjCwr1sNm9NYUqywL7QfK3JnlS015msC+eBu2zKlp8=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "db3f255737b94216eb71cce308e2912cf6bc2d7c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "haskell-flake": "haskell-flake", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b3fa8cb --- /dev/null +++ b/flake.nix @@ -0,0 +1,62 @@ +{ + description = "Datastar Haskell SDK"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + haskell-flake.url = "github:srid/haskell-flake"; + }; + + outputs = + inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + imports = [ inputs.haskell-flake.flakeModule ]; + + perSystem = + { self', pkgs, ... }: + { + haskellProjects.default = { + packages = { + # `haskell-flake` ignores `source-repository-package` defined in `cabal.project`. + # That's why `hs-zstd` needs to be pinned here. All because of https://github.com/starfederation/datastar-haskell/issues/3 + # Note: `fetchSubmodules` is needed -> `zstd.cabal` provides `zstd` in a submodule. + zstd.source = pkgs.fetchgit { + url = "https://github.com/luispedro/hs-zstd"; + rev = "59c0d21ab65a6296e06446c8368d78b9b4c7e64d"; + fetchSubmodules = true; + hash = "sha256-jGRiFZf5M/mNOXeWjtEkDQOZEi0Vry+pYRLutJkHuT0="; + }; + + # Note: `WAI.hs` needs `hAcceptEncoding` (from `Network.HTTP.Types`), + # which is available in `http-types` >= `v0.12.5` only. + # Side note: nixpkgs pins to `0.12.4` only. `source = "0.12.5"` does not work either (not available in frozen Hackage index). + http-types.source = pkgs.fetchzip { + url = "https://hackage.haskell.org/package/http-types-0.12.5/http-types-0.12.5.tar.gz"; + hash = "sha256-Y1/wrRFPIVxgTGWgPboRDUht+fzvl3e1jazj+G1pTw0="; + }; + }; + + devShell.tools = hp: { + # cabal-install, haskell-language-server, ghcid and hlint are defaults. + inherit (hp) fourmolu cabal-fmt; + inherit (pkgs) pkg-config nixfmt nixd; + }; + }; + + formatter = pkgs.nixfmt; + + packages.default = self'.packages.datastar-hs; + + # `nix flake check` builds / tests everything (similar to `cabal build all && cabal test all`) + checks.all = pkgs.linkFarmFromDrvs "datastar-hs-all" ( + builtins.attrValues (removeAttrs self'.packages [ "default" ]) + ); + }; + }; +}