on master help sign in
Merge pull request #28 from abshekh/master

Add `flake.nix`

commit44f2459ce4a3c3292f6bedb17019f1e2564d080e authorSridhar Ratnakumar <3998+srid@users.noreply.github.com> dateSun 12 Mar 2023, 20:27 (4 years ago) parent0bfb2fa7f26cbb
7 files changed+106−57
.github/workflows/ci.yaml+5−13 Setup.hs−2 default.nix−36 flake.lock+64 flake.nix+27 jrec.cabal+4−1 src/JRec/Internal.hs+6−5
.github/workflows/ci.yaml+5−13
@@ -4,20 +4,12 @@ on:
44 push:
55jobs:
66 build:
7− runs-on: ${{ matrix.os }}
8− strategy:
9− matrix:
10− ghc: ['ghc884', 'ghc8101']
11− os: [ubuntu-latest]
12− name: GHC ${{ matrix.ghc }}
7+ runs-on: ubuntu-latest
138 steps:
149 - uses: actions/checkout@v2
15− - uses: cachix/install-nix-action@v10
16− - uses: cachix/cachix-action@v6
10+ - uses: nixbuild/nix-quick-install-action@v21
1711 with:
18− name: juspay-nau
19− signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
20− # Only needed for private caches
21− authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
12+ nix_conf: |
13+ experimental-features = nix-command flakes
2214 - name: Build and test 🔧
23− run: nix-build -j4 --argstr compiler ${{ matrix.ghc }}
15+ run: nix build -j 4 -L
Setup.hsdeleted−2
@@ -1,2 +0,0 @@
1−import Distribution.Simple
2−main = defaultMain
default.nixdeleted−36
@@ -1,36 +0,0 @@
1−let
2− nixpkgsSrc = builtins.fetchTarball {
3− url = "https://github.com/nixos/nixpkgs/archive/76f2e271a2ef.tar.gz";
4− sha256 = "1r4da3kyghqq7vzya5yb295jpnha1fgp755bi6wda4fmhyaynnsp";
5− };
6− gitignoreSrc = builtins.fetchTarball {
7− url = "https://github.com/hercules-ci/gitignore/archive/c4662e6.tar.gz";
8− sha256 = "1npnx0h6bd0d7ql93ka7azhj40zgjp815fw2r6smg8ch9p7mzdlx";
9− };
10− inherit (import gitignoreSrc { inherit (pkgs); }) gitignoreSource;
11−in {
12− compiler ? "default",
13− pkgs ? import nixpkgsSrc {},
14−}:
15− let
16− haskellPackages =
17− if compiler == "default"
18− then pkgs.haskellPackages
19− else pkgs.haskell.packages.${compiler};
20− projectDrv =
21− haskellPackages.override {
22− overrides = self: super: with pkgs.haskell.lib; {
23− jrec = self.callCabal2nix "jrec" (gitignoreSource ./.) {};
24− # https://github.com/lspitzner/data-tree-print/pull/2
25− data-tree-print = doJailbreak super.data-tree-print;
26− };
27− };
28− projectShell =
29− projectDrv.shellFor {
30− packages = p: [ p.jrec ];
31− buildInputs = with projectDrv; [
32− cabal-install
33− ];
34− };
35− in
36− if pkgs.lib.inNixShell then projectShell else projectDrv.jrec
flake.locknew file+64
@@ -0,0 +1,64 @@
1+{
2+ "nodes": {
3+ "flake-parts": {
4+ "inputs": {
5+ "nixpkgs-lib": "nixpkgs-lib"
6+ },
7+ "locked": {
8+ "lastModified": 1678379998,
9+ "narHash": "sha256-TZdfNqftHhDuIFwBcN9MUThx5sQXCTeZk9je5byPKRw=",
10+ "owner": "hercules-ci",
11+ "repo": "flake-parts",
12+ "rev": "c13d60b89adea3dc20704c045ec4d50dd964d447",
13+ "type": "github"
14+ },
15+ "original": {
16+ "owner": "hercules-ci",
17+ "repo": "flake-parts",
18+ "type": "github"
19+ }
20+ },
21+ "nixpkgs": {
22+ "locked": {
23+ "lastModified": 1678594102,
24+ "narHash": "sha256-OHAHYiMWJFPNxuW/PcOMlSD2tvXnEYC1jxREBADHwwQ=",
25+ "owner": "nixos",
26+ "repo": "nixpkgs",
27+ "rev": "796b4a3c1d903c4b9270cd2548fe46f524eeb886",
28+ "type": "github"
29+ },
30+ "original": {
31+ "owner": "nixos",
32+ "ref": "nixpkgs-unstable",
33+ "repo": "nixpkgs",
34+ "type": "github"
35+ }
36+ },
37+ "nixpkgs-lib": {
38+ "locked": {
39+ "dir": "lib",
40+ "lastModified": 1678375444,
41+ "narHash": "sha256-XIgHfGvjFvZQ8hrkfocanCDxMefc/77rXeHvYdzBMc8=",
42+ "owner": "NixOS",
43+ "repo": "nixpkgs",
44+ "rev": "130fa0baaa2b93ec45523fdcde942f6844ee9f6e",
45+ "type": "github"
46+ },
47+ "original": {
48+ "dir": "lib",
49+ "owner": "NixOS",
50+ "ref": "nixos-unstable",
51+ "repo": "nixpkgs",
52+ "type": "github"
53+ }
54+ },
55+ "root": {
56+ "inputs": {
57+ "flake-parts": "flake-parts",
58+ "nixpkgs": "nixpkgs"
59+ }
60+ }
61+ },
62+ "root": "root",
63+ "version": 7
64+}
flake.nixnew file+27
@@ -0,0 +1,27 @@
1+{
2+ inputs = {
3+ nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
4+ flake-parts.url = "github:hercules-ci/flake-parts";
5+ };
6+ outputs = inputs@{ nixpkgs, flake-parts, ... }:
7+ flake-parts.lib.mkFlake { inherit inputs; } {
8+ systems = nixpkgs.lib.systems.flakeExposed;
9+ perSystem = { self', inputs', pkgs, system, ... }:
10+ let
11+ overlay = self: super: {
12+ jrec = self.callCabal2nix "jrec" ./. { };
13+ };
14+ haskellPackages' = pkgs.haskellPackages.extend overlay;
15+ in
16+ {
17+ packages.default = haskellPackages'.jrec;
18+ devShells.default = haskellPackages'.shellFor {
19+ packages = p: [ p.jrec ];
20+ buildInputs = with haskellPackages'; [
21+ cabal-install
22+ haskell-language-server
23+ ];
24+ };
25+ };
26+ };
27+}
jrec.cabal+4−1
@@ -37,7 +37,7 @@ common library-common
3737 default-language: Haskell2010
3838 build-depends:
3939 aeson
40− , base >=4.13 && <4.15
40+ , base >=4.13 && <4.17
4141 , constraints
4242 , deepseq
4343 , generic-data
@@ -97,6 +97,9 @@ test-suite jrec-test
9797 hs-source-dirs: test, src
9898 main-is: Spec.hs
9999 cpp-options: -DWITH_AESON -DWITH_GENERICS
100+ other-modules:
101+ JRecShouldNotTypecheckSpec
102+ JRecSpec
100103 build-depends:
101104 base,
102105 hspec,
src/JRec/Internal.hs+6−5
@@ -46,6 +46,7 @@ import GHC.TypeLits
4646import qualified Optics.Lens as OL
4747import Unsafe.Coerce
4848import Prelude
49+import qualified Data.Aeson.Key as Key
4950
5051-- | Field named @l@ labels value of type @t@ adapted from the awesome /labels/ package.
5152-- Example: @(#name := \"Chris\") :: (\"name\" := String)@
@@ -558,16 +559,16 @@ class ToJSON a => EncodeField a where
558559
559560instance ToJSON a => EncodeField a where
560561 encodeField = pure . toJSON
561− encodeKV = (.=)
562+ encodeKV k v = Key.fromText k .= v
562563
563564instance {-# OVERLAPS #-} ToJSON a => EncodeField (Maybe a) where
564565 encodeField = fmap toJSON
565566 encodeKV _ Nothing = mempty
566− encodeKV k v = k .= v
567+ encodeKV k v = Key.fromText k .= v
567568
568569recToValue :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Value
569570recToValue options r =
570− object $ catMaybes $ reflectRec @EncodeField Proxy (\k v -> (T.pack (fieldTransform options k),) <$> encodeField v) r
571+ object $ catMaybes $ reflectRec @EncodeField Proxy (\k v -> (Key.fromString (fieldTransform options k),) <$> encodeField v) r
571572
572573recToEncoding :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Encoding
573574recToEncoding options r =
@@ -672,10 +673,10 @@ class FromJSON a => ParseField a where
672673 parseField :: Object -> T.Text -> Parser a
673674
674675instance FromJSON a => ParseField a where
675− parseField = (.:)
676+ parseField o k = o .: Key.fromText k
676677
677678instance {-# OVERLAPS #-} FromJSON a => ParseField (Maybe a) where
678− parseField = (.:?)
679+ parseField o k = o .:? Key.fromText k
679680
680681instance
681682 ( KnownSymbol l,