diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index fe779a928f..fb457e2a83 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -20,10 +20,11 @@ jobs: uses: actions/checkout@v3 - name: Set up Nix with caching - uses: kadena-io/setup-nix-with-cache/by-root@v3 + uses: kadena-io/setup-nix-with-cache/by-root@v3.1 with: cache_url: s3://nixcache.chainweb.com?region=us-east-1 signing_private_key: ${{ secrets.NIX_CACHE_PRIVATE_KEY }} + additional_experimental_features: recursive-nix - name: Set up AWS credentials uses: aws-actions/configure-aws-credentials@v2 @@ -33,9 +34,12 @@ jobs: aws-region: us-east-1 - name: Give root user AWS credentials - uses: kadena-io/setup-nix-with-cache/copy-root-aws-credentials@v3 - + uses: kadena-io/setup-nix-with-cache/copy-root-aws-credentials@v3.1 + - name: Build and cache artifacts run: | echo Building the project and its devShell nix build .#check --log-lines 500 --show-trace --accept-flake-config + + echo Build the recursive output + nix build .#recursive.allDerivations --accept-flake-config --log-lines 500 --show-trace diff --git a/default.nix b/default.nix index 2cd18719d9..c04e975b1c 100644 --- a/default.nix +++ b/default.nix @@ -6,15 +6,18 @@ let flakeDefaultNix = (import ( src = ./.; }).defaultNix; inputs = flakeDefaultNix.inputs; - pkgsDef = import inputs.nixpkgs { - config = inputs.haskellNix.config; - overlays = [ inputs.haskellNix.overlay] ; + hs-nix-infra = inputs.hs-nix-infra; + pkgsDef = import hs-nix-infra.nixpkgs { + config = hs-nix-infra.haskellNix.config; + overlays = [ hs-nix-infra.haskellNix.overlay] ; }; in { pkgs ? pkgsDef , compiler ? "ghc963" , flakePath ? flakeDefaultNix.outPath , nix-filter ? inputs.nix-filter +, pact ? null +, enablePactBuildTool ? false , ... }: let haskellSrc = with nix-filter.lib; filter { @@ -31,10 +34,41 @@ let haskellSrc = with nix-filter.lib; filter { "dist-newstyle" ]; }; - chainweb = pkgs.haskell-nix.project' { + overridePact = pkgs.lib.optionalString (pact != null) '' + # Remove the source-repository-package section for pact and inject the + # override as a packages section + ${pkgs.gawk}/bin/awk -i inplace ' + BEGINFILE { delete_block=0; buffer = ""; } + /^$/ { + if (delete_block == 0) print buffer "\n"; + buffer=""; + delete_block=0; + next; + } + /location: https:\/\/github.com\/kadena-io\/pact.git/ { delete_block=1; } + { + if (delete_block == 0) { + if (buffer != "") buffer = buffer "\n"; + buffer = buffer $0; + } + } + ENDFILE { if (delete_block == 0) print buffer "\n"; } + ' $out + echo 'packages: ${pact}' >> $out + ''; + overridePactBuildTool = pkgs.lib.optionalString enablePactBuildTool '' + # Remove the -build-tool flag from the pact package section, this allows + # us to build the pact executable through the chainweb project + sed -i '/package pact/,/^[^\ ]/{/^[ \t]/!b; s/-build-tool//}' $out + ''; + chainweb = pkgs.haskell-nix.cabalProject' { src = haskellSrc; compiler-nix-name = compiler; - projectFileName = "cabal.project"; + cabalProject = builtins.readFile (pkgs.runCommand "cabal.project" {} '' + cat ${./cabal.project} > $out + ${overridePact} + ${overridePactBuildTool} + '').outPath; shell.tools = { cabal = {}; haskell-language-server = {}; @@ -50,7 +84,25 @@ let haskellSrc = with nix-filter.lib; filter { ]; }; flake = chainweb.flake {}; - default = pkgs.runCommandCC "chainweb" {} '' + pactFromCached = pkgs: pactInput: cached: { + version = cached.meta.pact.version; + src = if pactInput == null then pkgs.fetchgit cached.meta.pact.src else pactInput; + }; + passthru = { + version = flake.packages."chainweb:exe:chainweb-node".version; + # cached.meta gets propagated through the recursive outputs + cached.paths.pactSrc = chainweb.hsPkgs.pact.src; + cached.meta.pact = { + version = chainweb.hsPkgs.pact.identifier.version; + src = if pact != null then {} else with chainweb.hsPkgs.pact.src; { + url = gitRepoUrl; + hash = outputHash; + inherit rev; + }; + }; + pact = pactFromCached pkgs pact passthru.cached; + }; + default = pkgs.runCommandCC "chainweb" { inherit passthru; } '' mkdir -pv $out/bin cp ${flake.packages."chainweb:exe:chainweb-node"}/bin/chainweb-node $out/bin/chainweb-node cp ${flake.packages."chainweb:exe:cwtool"}/bin/cwtool $out/bin/cwtool @@ -75,6 +127,8 @@ in { # $ ls $(nix-instantiate default.nix -A haskellSrc --eval) inherit haskellSrc; + inherit pactFromCached; + # The haskell.nix Haskell project (executables, libraries, etc) # Also contains the `flake` attribute, and many useful things. # diff --git a/flake.lock b/flake.lock index e6b4196596..b91e89d0ec 100644 --- a/flake.lock +++ b/flake.lock @@ -1,89 +1,53 @@ { "nodes": { - "HTTP": { + "empty": { "flake": false, "locked": { - "lastModified": 1451647621, - "narHash": "sha256-oHIyw3x0iKBexEo49YeUDV1k74ZtyYKGR2gNJXXRxts=", - "owner": "phadej", - "repo": "HTTP", - "rev": "9bc0996d412fef1787449d841277ef663ad9a915", + "lastModified": 1683033565, + "narHash": "sha256-UZ2dz7/RzJKTw/8uqLu6biAbb3xNk23xUHb5/oAYWsw=", + "owner": "kadena-io", + "repo": "empty", + "rev": "c30c041f692678788a294069c95677774be2dff3", "type": "github" }, "original": { - "owner": "phadej", - "repo": "HTTP", + "owner": "kadena-io", + "repo": "empty", "type": "github" } }, - "cabal-32": { + "empty_2": { "flake": false, "locked": { - "lastModified": 1603716527, - "narHash": "sha256-X0TFfdD4KZpwl0Zr6x+PLxUt/VyKQfX7ylXHdmZIL+w=", - "owner": "haskell", - "repo": "cabal", - "rev": "48bf10787e27364730dd37a42b603cee8d6af7ee", + "lastModified": 1683033565, + "narHash": "sha256-UZ2dz7/RzJKTw/8uqLu6biAbb3xNk23xUHb5/oAYWsw=", + "owner": "kadena-io", + "repo": "empty", + "rev": "c30c041f692678788a294069c95677774be2dff3", "type": "github" }, "original": { - "owner": "haskell", - "ref": "3.2", - "repo": "cabal", + "owner": "kadena-io", + "repo": "empty", "type": "github" } }, - "cabal-34": { - "flake": false, - "locked": { - "lastModified": 1645834128, - "narHash": "sha256-wG3d+dOt14z8+ydz4SL7pwGfe7SiimxcD/LOuPCV6xM=", - "owner": "haskell", - "repo": "cabal", - "rev": "5ff598c67f53f7c4f48e31d722ba37172230c462", - "type": "github" - }, - "original": { - "owner": "haskell", - "ref": "3.4", - "repo": "cabal", - "type": "github" - } - }, - "cabal-36": { - "flake": false, - "locked": { - "lastModified": 1669081697, - "narHash": "sha256-I5or+V7LZvMxfbYgZATU4awzkicBwwok4mVoje+sGmU=", - "owner": "haskell", - "repo": "cabal", - "rev": "8fd619e33d34924a94e691c5fea2c42f0fc7f144", - "type": "github" - }, - "original": { - "owner": "haskell", - "ref": "3.6", - "repo": "cabal", - "type": "github" - } - }, - "cardano-shell": { - "flake": false, + "flake-compat": { "locked": { - "lastModified": 1608537748, - "narHash": "sha256-PulY1GfiMgKVnBci3ex4ptk2UNYMXqGjJOxcPy2KYT4=", - "owner": "input-output-hk", - "repo": "cardano-shell", - "rev": "9392c75087cb9a3d453998f4230930dea3a95725", + "lastModified": 1699384378, + "narHash": "sha256-jI0nYllONVrNnyOYrvQMIEJQJuNeKnfJo5keRxWMcWs=", + "owner": "kadena-io", + "repo": "flake-compat", + "rev": "6ef9397736efb0f6075188aa3488022d1b85c11d", "type": "github" }, "original": { - "owner": "input-output-hk", - "repo": "cardano-shell", + "owner": "kadena-io", + "repo": "flake-compat", "type": "github" } }, - "flake-compat": { + "flake-compat_2": { "flake": false, "locked": { "lastModified": 1672831974, @@ -118,60 +82,6 @@ "type": "github" } }, - "ghc-8.6.5-iohk": { - "flake": false, - "locked": { - "lastModified": 1600920045, - "narHash": "sha256-DO6kxJz248djebZLpSzTGD6s8WRpNI9BTwUeOf5RwY8=", - "owner": "input-output-hk", - "repo": "ghc", - "rev": "95713a6ecce4551240da7c96b6176f980af75cae", - "type": "github" - }, - "original": { - "owner": "input-output-hk", - "ref": "release/8.6.5-iohk", - "repo": "ghc", - "type": "github" - } - }, - "ghc980": { - "flake": false, - "locked": { - "lastModified": 1692910316, - "narHash": "sha256-Qv8I3GzzIIN32RTEKI38BW5nO1f7j6Xm+dDeDUyYZWo=", - "ref": "ghc-9.8", - "rev": "249aa8193e4c5c1ee46ce29b39d2fffa57de7904", - "revCount": 61566, - "submodules": true, - "type": "git", - "url": "https://gitlab.haskell.org/ghc/ghc" - }, - "original": { - "ref": "ghc-9.8", - "submodules": true, - "type": "git", - "url": "https://gitlab.haskell.org/ghc/ghc" - } - }, - "ghc99": { - "flake": false, - "locked": { - "lastModified": 1695427505, - "narHash": "sha256-j0hXl6uEI+Uwf37z3WLuQZN4S0XqGtiepELv2Gl2aHU=", - "ref": "refs/heads/master", - "rev": "b8e4fe2318798185228fb5f8214ba2384ac95b4f", - "revCount": 61951, - "submodules": true, - "type": "git", - "url": "https://gitlab.haskell.org/ghc/ghc" - }, - "original": { - "submodules": true, - "type": "git", - "url": "https://gitlab.haskell.org/ghc/ghc" - } - }, "hackage": { "flake": false, "locked": { @@ -190,38 +100,106 @@ }, "haskellNix": { "inputs": { - "HTTP": "HTTP", - "cabal-32": "cabal-32", - "cabal-34": "cabal-34", - "cabal-36": "cabal-36", - "cardano-shell": "cardano-shell", - "flake-compat": "flake-compat", - "ghc-8.6.5-iohk": "ghc-8.6.5-iohk", - "ghc980": "ghc980", - "ghc99": "ghc99", + "HTTP": [ + "hs-nix-infra", + "empty" + ], + "cabal-32": [ + "hs-nix-infra", + "empty" + ], + "cabal-34": [ + "hs-nix-infra", + "empty" + ], + "cabal-36": [ + "hs-nix-infra", + "empty" + ], + "cardano-shell": [ + "hs-nix-infra", + "empty" + ], + "flake-compat": "flake-compat_2", + "ghc-8.6.5-iohk": [ + "hs-nix-infra", + "empty" + ], + "ghc980": [ + "hs-nix-infra", + "empty" + ], + "ghc99": [ + "hs-nix-infra", + "empty" + ], "hackage": [ + "hs-nix-infra", "hackage" ], - "hls-1.10": "hls-1.10", - "hls-2.0": "hls-2.0", - "hls-2.2": "hls-2.2", + "hls-1.10": [ + "hs-nix-infra", + "empty" + ], + "hls-2.0": [ + "hs-nix-infra", + "empty" + ], + "hls-2.2": [ + "hs-nix-infra", + "empty" + ], "hls-2.3": "hls-2.3", - "hpc-coveralls": "hpc-coveralls", - "hydra": "hydra", - "iserv-proxy": "iserv-proxy", + "hpc-coveralls": [ + "hs-nix-infra", + "empty" + ], + "hydra": [ + "hs-nix-infra", + "empty" + ], + "iserv-proxy": [ + "hs-nix-infra", + "empty" + ], "nixpkgs": [ + "hs-nix-infra", "haskellNix", "nixpkgs-unstable" ], - "nixpkgs-2003": "nixpkgs-2003", - "nixpkgs-2105": "nixpkgs-2105", - "nixpkgs-2111": "nixpkgs-2111", - "nixpkgs-2205": "nixpkgs-2205", - "nixpkgs-2211": "nixpkgs-2211", - "nixpkgs-2305": "nixpkgs-2305", + "nixpkgs-2003": [ + "hs-nix-infra", + "empty" + ], + "nixpkgs-2105": [ + "hs-nix-infra", + "empty" + ], + "nixpkgs-2111": [ + "hs-nix-infra", + "empty" + ], + "nixpkgs-2205": [ + "hs-nix-infra", + "empty" + ], + "nixpkgs-2211": [ + "hs-nix-infra", + "empty" + ], + "nixpkgs-2305": [ + "hs-nix-infra", + "empty" + ], "nixpkgs-unstable": "nixpkgs-unstable", - "old-ghc-nix": "old-ghc-nix", - "stackage": "stackage" + "old-ghc-nix": [ + "hs-nix-infra", + "empty" + ], + "stackage": [ + "hs-nix-infra", + "empty" + ] }, "locked": { "lastModified": 1697195891, @@ -237,57 +215,6 @@ "type": "github" } }, - "hls-1.10": { - "flake": false, - "locked": { - "lastModified": 1680000865, - "narHash": "sha256-rc7iiUAcrHxwRM/s0ErEsSPxOR3u8t7DvFeWlMycWgo=", - "owner": "haskell", - "repo": "haskell-language-server", - "rev": "b08691db779f7a35ff322b71e72a12f6e3376fd9", - "type": "github" - }, - "original": { - "owner": "haskell", - "ref": "1.10.0.0", - "repo": "haskell-language-server", - "type": "github" - } - }, - "hls-2.0": { - "flake": false, - "locked": { - "lastModified": 1687698105, - "narHash": "sha256-OHXlgRzs/kuJH8q7Sxh507H+0Rb8b7VOiPAjcY9sM1k=", - "owner": "haskell", - "repo": "haskell-language-server", - "rev": "783905f211ac63edf982dd1889c671653327e441", - "type": "github" - }, - "original": { - "owner": "haskell", - "ref": "2.0.0.1", - "repo": "haskell-language-server", - "type": "github" - } - }, - "hls-2.2": { - "flake": false, - "locked": { - "lastModified": 1693064058, - "narHash": "sha256-8DGIyz5GjuCFmohY6Fa79hHA/p1iIqubfJUTGQElbNk=", - "owner": "haskell", - "repo": "haskell-language-server", - "rev": "b30f4b6cf5822f3112c35d14a0cba51f3fe23b85", - "type": "github" - }, - "original": { - "owner": "haskell", - "ref": "2.2.0.0", - "repo": "haskell-language-server", - "type": "github" - } - }, "hls-2.3": { "flake": false, "locked": { @@ -305,96 +232,28 @@ "type": "github" } }, - "hpc-coveralls": { - "flake": false, - "locked": { - "lastModified": 1607498076, - "narHash": "sha256-8uqsEtivphgZWYeUo5RDUhp6bO9j2vaaProQxHBltQk=", - "owner": "sevanspowell", - "repo": "hpc-coveralls", - "rev": "14df0f7d229f4cd2e79f8eabb1a740097fdfa430", - "type": "github" - }, - "original": { - "owner": "sevanspowell", - "repo": "hpc-coveralls", - "type": "github" - } - }, - "hydra": { - "inputs": { - "nix": "nix", - "nixpkgs": [ - "haskellNix", - "hydra", - "nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1671755331, - "narHash": "sha256-hXsgJj0Cy0ZiCiYdW2OdBz5WmFyOMKuw4zyxKpgUKm4=", - "owner": "NixOS", - "repo": "hydra", - "rev": "f48f00ee6d5727ae3e488cbf9ce157460853fea8", - "type": "github" - }, - "original": { - "id": "hydra", - "type": "indirect" - } - }, - "iserv-proxy": { - "flake": false, - "locked": { - "lastModified": 1691634696, - "narHash": "sha256-MZH2NznKC/gbgBu8NgIibtSUZeJ00HTLJ0PlWKCBHb0=", - "ref": "hkm/remote-iserv", - "rev": "43a979272d9addc29fbffc2e8542c5d96e993d73", - "revCount": 14, - "type": "git", - "url": "https://gitlab.haskell.org/hamishmack/iserv-proxy.git" - }, - "original": { - "ref": "hkm/remote-iserv", - "type": "git", - "url": "https://gitlab.haskell.org/hamishmack/iserv-proxy.git" - } - }, - "lowdown-src": { - "flake": false, - "locked": { - "lastModified": 1633514407, - "narHash": "sha256-Dw32tiMjdK9t3ETl5fzGrutQTzh2rufgZV4A/BbxuD4=", - "owner": "kristapsdz", - "repo": "lowdown", - "rev": "d2c2b44ff6c27b936ec27358a2653caaef8f73b8", - "type": "github" - }, - "original": { - "owner": "kristapsdz", - "repo": "lowdown", - "type": "github" - } - }, - "nix": { + "hs-nix-infra": { "inputs": { - "lowdown-src": "lowdown-src", + "empty": "empty_2", + "flake-compat": "flake-compat", + "hackage": [ + "hackage" + ], + "haskellNix": "haskellNix", "nixpkgs": "nixpkgs", - "nixpkgs-regression": "nixpkgs-regression" + "nixpkgs-rec": "nixpkgs-rec" }, "locked": { - "lastModified": 1661606874, - "narHash": "sha256-9+rpYzI+SmxJn+EbYxjGv68Ucp22bdFUSy/4LkHkkDQ=", - "owner": "NixOS", - "repo": "nix", - "rev": "11e45768b34fdafdcf019ddbd337afa16127ff0f", + "lastModified": 1699970998, + "narHash": "sha256-NgvBCRIB+lvcxJWMpU8Mulx8PG8s5jtqSR8K/natoTA=", + "owner": "kadena-io", + "repo": "hs-nix-infra", + "rev": "a69071dafa3f0d12edf30ecc5a562aee1f7d138d", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "2.11.0", - "repo": "nix", + "owner": "kadena-io", + "repo": "hs-nix-infra", "type": "github" } }, @@ -415,129 +274,33 @@ }, "nixpkgs": { "locked": { - "lastModified": 1657693803, - "narHash": "sha256-G++2CJ9u0E7NNTAi9n5G8TdDmGJXcIjkJ3NF8cetQB8=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "365e1b3a859281cf11b94f87231adeabbdd878a2", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-22.05-small", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-2003": { - "locked": { - "lastModified": 1620055814, - "narHash": "sha256-8LEHoYSJiL901bTMVatq+rf8y7QtWuZhwwpKE2fyaRY=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "1db42b7fe3878f3f5f7a4f2dc210772fd080e205", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-20.03-darwin", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-2105": { - "locked": { - "lastModified": 1659914493, - "narHash": "sha256-lkA5X3VNMKirvA+SUzvEhfA7XquWLci+CGi505YFAIs=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "022caabb5f2265ad4006c1fa5b1ebe69fb0c3faf", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-21.05-darwin", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-2111": { - "locked": { - "lastModified": 1659446231, - "narHash": "sha256-hekabNdTdgR/iLsgce5TGWmfIDZ86qjPhxDg/8TlzhE=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "eabc38219184cc3e04a974fe31857d8e0eac098d", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-21.11-darwin", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-2205": { - "locked": { - "lastModified": 1685573264, - "narHash": "sha256-Zffu01pONhs/pqH07cjlF10NnMDLok8ix5Uk4rhOnZQ=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "380be19fbd2d9079f677978361792cb25e8a3635", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-22.05-darwin", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-2211": { - "locked": { - "lastModified": 1688392541, - "narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-22.11-darwin", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-2305": { - "locked": { - "lastModified": 1695416179, - "narHash": "sha256-610o1+pwbSu+QuF3GE0NU5xQdTHM3t9wyYhB9l94Cd8=", + "lastModified": 1669833724, + "narHash": "sha256-/HEZNyGbnQecrgJnfE8d0WC5c1xuPSD2LUpB6YXlg4c=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "715d72e967ec1dd5ecc71290ee072bcaf5181ed6", + "rev": "4d2b37a84fad1091b9de401eb450aae66f1a741e", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixpkgs-23.05-darwin", "repo": "nixpkgs", + "rev": "4d2b37a84fad1091b9de401eb450aae66f1a741e", "type": "github" } }, - "nixpkgs-regression": { + "nixpkgs-rec": { "locked": { - "lastModified": 1643052045, - "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "lastModified": 1669833724, + "narHash": "sha256-/HEZNyGbnQecrgJnfE8d0WC5c1xuPSD2LUpB6YXlg4c=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "rev": "4d2b37a84fad1091b9de401eb450aae66f1a741e", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "rev": "4d2b37a84fad1091b9de401eb450aae66f1a741e", "type": "github" } }, @@ -557,62 +320,16 @@ "type": "github" } }, - "nixpkgs_2": { - "locked": { - "lastModified": 1669833724, - "narHash": "sha256-/HEZNyGbnQecrgJnfE8d0WC5c1xuPSD2LUpB6YXlg4c=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "4d2b37a84fad1091b9de401eb450aae66f1a741e", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "4d2b37a84fad1091b9de401eb450aae66f1a741e", - "type": "github" - } - }, - "old-ghc-nix": { - "flake": false, - "locked": { - "lastModified": 1631092763, - "narHash": "sha256-sIKgO+z7tj4lw3u6oBZxqIhDrzSkvpHtv0Kki+lh9Fg=", - "owner": "angerman", - "repo": "old-ghc-nix", - "rev": "af48a7a7353e418119b6dfe3cd1463a657f342b8", - "type": "github" - }, - "original": { - "owner": "angerman", - "ref": "master", - "repo": "old-ghc-nix", - "type": "github" - } - }, "root": { "inputs": { + "empty": "empty", "flake-utils": "flake-utils", "hackage": "hackage", - "haskellNix": "haskellNix", + "hs-nix-infra": "hs-nix-infra", "nix-filter": "nix-filter", - "nixpkgs": "nixpkgs_2" - } - }, - "stackage": { - "flake": false, - "locked": { - "lastModified": 1696982937, - "narHash": "sha256-KASiTJAbIDfiMhHcoi2qtCYeTvRhZpR5PKzWQCteih4=", - "owner": "input-output-hk", - "repo": "stackage.nix", - "rev": "5531e02e80e9eeec3c817d24660e8e58e2f05703", - "type": "github" - }, - "original": { - "owner": "input-output-hk", - "repo": "stackage.nix", - "type": "github" + "pact": [ + "empty" + ] } }, "systems": { diff --git a/flake.nix b/flake.nix index ebc72eacf3..8ec23908c2 100644 --- a/flake.nix +++ b/flake.nix @@ -2,17 +2,22 @@ description = "Chainweb"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs?rev=4d2b37a84fad1091b9de401eb450aae66f1a741e"; hackage = { url = "github:input-output-hk/hackage.nix"; flake = false; }; - haskellNix = { - url = "github:input-output-hk/haskell.nix"; + hs-nix-infra = { + url = "github:kadena-io/hs-nix-infra"; inputs.hackage.follows = "hackage"; }; flake-utils.url = "github:numtide/flake-utils"; nix-filter.url = "github:numtide/nix-filter"; + empty = { + url = "github:kadena-io/empty"; + flake = false; + }; + # By default we use the pact specified in the cabal.project + pact.follows = "empty"; }; nixConfig = { @@ -20,21 +25,35 @@ trusted-public-keys = "nixcache.chainweb.com:FVN503ABX9F8x8K0ptnc99XEz5SaA4Sks6kNcZn2pBY= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="; }; - outputs = { self, nixpkgs, flake-utils, haskellNix, nix-filter, ... }: + outputs = inputs@{ self, hs-nix-infra, flake-utils, nix-filter, ... }: flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ] (system: let + inherit (hs-nix-infra) nixpkgs haskellNix; + # The pactInput is non-null only if the pact input was overridden + pactInput = if inputs.pact.outPath != inputs.empty.outPath then inputs.pact else null; + basePkgs = hs-nix-infra.nixpkgs.legacyPackages.${system}; pkgs = import nixpkgs { inherit system; inherit (haskellNix) config; overlays = [ haskellNix.overlay ]; }; - defaultNix = import ./default.nix { - inherit pkgs nix-filter; - flakePath = self.outPath; - }; + mkDefaultNix = { + pact ? pactInput, + enablePactBuildTool ? false, + }: import ./default.nix { + inherit pkgs nix-filter pact enablePactBuildTool; + flakePath = self.outPath; + }; + defaultNix = mkDefaultNix {}; flake = defaultNix.flake; + mkRecursive = { pact ? pactInput }: with hs-nix-infra.lib.recursive system; + let args = if pact == null then "{}" else "{ pact = builtins.storePath ${pact}; }"; + recursive = wrapRecursiveWithMeta "chainweb-node" '' + (${wrapFlake self}.lib.${system}.mkDefaultNix ${args}).default + ''; + in recursive // { pact = defaultNix.pactFromCached pkgs-rec pact recursive.cached; }; executables = defaultNix.default; # This package depends on other packages at buildtime, but its output does not # depend on them. This way, we don't have to download the entire closure to verify @@ -43,12 +62,32 @@ echo ${name}: ${package} echo works > $out ''; - in nixpkgs.lib.recursiveUpdate flake { - packages.default = executables; - packages.check = pkgs.runCommand "check" {} '' - echo ${mkCheck "chainweb" executables} - echo ${mkCheck "devShell" flake.devShell} - echo works > $out - ''; + in { + packages = { + default = executables; + + # This package is equivalent to the default package, but it offloads the + # evaluation of the haskellNix project to a recursive nix-build. If you expect to + # find this package in your nix store or a binary cache, using this package will + # significantly reduce your nix eval times and the amount of data you download. + recursive = mkRecursive {}; + + check = pkgs.runCommand "check" {} '' + echo ${mkCheck "chainweb" executables} + echo ${mkCheck "devShell" flake.devShell} + echo works > $out + ''; + }; + + # Used by nix develop + devShell = flake.devShell; + + # Not used by standard Nix tooling, but could be useful for downstream users + project = defaultNix.chainweb; + + lib = { + inherit mkDefaultNix mkRecursive; + mkChainwebProject = args: (mkDefaultNix args).chainweb; + }; }); }