diff --git a/flake.nix b/flake.nix index 61c9066e..4d307848 100644 --- a/flake.nix +++ b/flake.nix @@ -32,219 +32,221 @@ }; outputs = inputs@{ self, flake-utils, haskell-nix, ... }: - flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: - let - # TODO: Perhaps cleanSource - src = ./.; - - # Nixpkgs from bot-plutus-interface - inherit (inputs.bot-plutus-interface.inputs) nixpkgs; - - # Reliably cached - pkgs = import nixpkgs { inherit system; }; - - # # Poor caching due to overlay - pkgs' = import nixpkgs { - overlays = - [ haskell-nix.overlay (import "${inputs.iohk-nix}/overlays/crypto") ]; - inherit system; - inherit (haskell-nix) config; - }; - - easy-ps = import inputs.easy-ps { inherit pkgs; }; - - # Haskell.nix project and flake - # Filter out purescript-bridge - extraSources' = builtins.filter (e: e.src.rev != "47a1f11825a0f9445e0f98792f79172efef66c00") inputs.bot-plutus-interface.extraSources; - # Use our servant-purescript fork - extraSources'' = builtins.map - (e: - if e.src.rev == "44e7cacf109f84984cd99cd3faf185d161826963" - then { src = inputs.servant-purescript; subdirs = e.subdirs; } - else e) - extraSources'; - - extraSources = - [ + builtins.mapAttrs # FIXME: https://github.com/mlabs-haskell/purescript-bridge/issues/36 + (name: value: if name == "hydraJobs" then builtins.removeAttrs value [ "x86_64-darwin" ] else value) + (flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system: + let + # TODO: Perhaps cleanSource + src = ./.; + + # Nixpkgs from bot-plutus-interface + inherit (inputs.bot-plutus-interface.inputs) nixpkgs; + + # Reliably cached + pkgs = import nixpkgs { inherit system; }; + + # # Poor caching due to overlay + pkgs' = import nixpkgs { + overlays = + [ haskell-nix.overlay (import "${inputs.iohk-nix}/overlays/crypto") ]; + inherit system; + inherit (haskell-nix) config; + }; + + easy-ps = import inputs.easy-ps { inherit pkgs; }; + + # Haskell.nix project and flake + # Filter out purescript-bridge + extraSources' = builtins.filter (e: e.src.rev != "47a1f11825a0f9445e0f98792f79172efef66c00") inputs.bot-plutus-interface.extraSources; + # Use our servant-purescript fork + extraSources'' = builtins.map + (e: + if e.src.rev == "44e7cacf109f84984cd99cd3faf185d161826963" + then { src = inputs.servant-purescript; subdirs = e.subdirs; } + else e) + extraSources'; + + extraSources = + [ + { + src = inputs.plutus-extra; + subdirs = [ + "quickcheck-plutus-instances" + ]; + } + ] + ++ extraSources''; + haskellProject = import ./nix/haskell.nix { + inherit src system pkgs pkgs' easy-ps extraSources; + rtPurs = roundTripTestPursFlake.packages.roundtrip-test-run-with-node; + }; + + haskellFlake = haskellProject.flake { }; + + # Code quality + cq = import ./nix/code-quality.nix { inherit pkgs easy-ps; }; + fileCheckers = cq.checkers pkgs; + fileFixers = cq.fixers pkgs; + + pursVersion = "purs-0_14_5"; + + # Generated plutus-ledger-api Purescript typelib + generatedLedgerPursFiles = pkgs.runCommand "generate-plutus-ledger-api-purs-files" { - src = inputs.plutus-extra; - subdirs = [ - "quickcheck-plutus-instances" - ]; + cli = haskellProject.getComponent "purescript-bridge:exe:cli"; } - ] - ++ extraSources''; - haskellProject = import ./nix/haskell.nix { - inherit src system pkgs pkgs' easy-ps extraSources; - rtPurs = roundTripTestPursFlake.packages.roundtrip-test-run-with-node; - }; - - haskellFlake = haskellProject.flake { }; - - # Code quality - cq = import ./nix/code-quality.nix { inherit pkgs easy-ps; }; - fileCheckers = cq.checkers pkgs; - fileFixers = cq.fixers pkgs; - - pursVersion = "purs-0_14_5"; - - # Generated plutus-ledger-api Purescript typelib - generatedLedgerPursFiles = pkgs.runCommand "generate-plutus-ledger-api-purs-files" - { - cli = haskellProject.getComponent "purescript-bridge:exe:cli"; - } - '' - mkdir $out - $cli/bin/cli generate-types --generated-dir $out - ''; - - generatedLedgerTypelib = - let - spago = easy-ps.spago; - ctl = inputs.cardano-transaction-lib; - purs = easy-ps.${pursVersion}; - typelibName = "generated-ledger"; - in - import ./nix/purescript-bridge.nix ctl { - inherit pkgs purs spago typelibName; - generatedPursFiles = generatedLedgerPursFiles; + '' + mkdir $out + $cli/bin/cli generate-types --generated-dir $out + ''; + + generatedLedgerTypelib = + let + spago = easy-ps.spago; + ctl = inputs.cardano-transaction-lib; + purs = easy-ps.${pursVersion}; + typelibName = "generated-ledger"; + in + import ./nix/purescript-bridge.nix ctl { + inherit pkgs purs spago typelibName; + generatedPursFiles = generatedLedgerPursFiles; + }; + + sampleLedgerTypelib = + let + spago = easy-ps.spago; + ctl = inputs.cardano-transaction-lib; + purs = easy-ps.${pursVersion}; + typelibName = "sample-ledger"; + in + import ./nix/purescript-bridge.nix ctl { + inherit pkgs purs spago typelibName; + generatedPursFiles = ./generated; + }; + + # Purescript - Haskell round trip generated typelib + generatedRoundTripPursFiles = pkgs.runCommand "generate-roundtrip-test-purescript-files" + { + cli = haskellProject.getComponent "purescript-bridge:exe:roundtrip"; + } + '' + mkdir $out + $cli/bin/roundtrip generate-types --generated-dir $out + ''; + + generatedRoundTripTypelib = + let + spago = easy-ps.spago; + ctl = inputs.cardano-transaction-lib; + purs = easy-ps.${pursVersion}; + typelibName = "roundtrip-test"; + in + import ./nix/purescript-bridge.nix ctl { + inherit pkgs purs spago typelibName; + generatedPursFiles = generatedRoundTripPursFiles; + }; + + # Purescript - Haskell round trip test purs flake + roundTripTestPursFlake = + let + inherit pkgs easy-ps; + src = ./roundtrip/RoundTripPurs; + workDir = "./roundtrip/RoundTripPurs"; + pursSubDirs = [ "/src" ]; + pursSubDirsTest = [ "/test" ]; + nodejs = pkgs.nodejs-14_x; + spagoLocalPkgs = [ inputs.cardano-transaction-lib generatedRoundTripTypelib ]; + purs = easy-ps.${pursVersion}; + projectName = "roundtrip-test"; + in + import ./nix/purescript-flake.nix { + inherit src workDir pursSubDirs pursSubDirsTest pkgs system easy-ps spagoLocalPkgs + nodejs purs projectName; + }; + # purescript-bridge.nix flake + purescriptBridgeNixFlake = + let + inherit pkgs easy-ps; + src = ./nix/purescript-bridge-nix-spago; + workDir = "./nix/purescript-bridge-nix-spago"; + pursSubDirs = [ "/src" ]; + pursSubDirsTest = [ "/test" ]; + nodejs = pkgs.nodejs-14_x; + spagoLocalPkgs = [ inputs.cardano-transaction-lib ]; + purs = easy-ps.${pursVersion}; + mainModule = "PureScriptBridge.Main"; + projectName = "purescript-bridge-nix"; + in + import ./nix/purescript-flake.nix { + inherit src workDir pursSubDirs pursSubDirsTest pkgs system easy-ps spagoLocalPkgs + nodejs purs mainModule projectName; + }; + in + rec { + # Useful attributes + inherit pkgs easy-ps haskellProject haskellFlake; + + # Flake standard attributes + packages = haskellFlake.packages // purescriptBridgeNixFlake.packages // roundTripTestPursFlake.packages // { + sample-plutus-ledger-api-typelib = sampleLedgerTypelib; + plutus-ledger-api-typelib = generatedLedgerTypelib; }; - - sampleLedgerTypelib = - let - spago = easy-ps.spago; - ctl = inputs.cardano-transaction-lib; - purs = easy-ps.${pursVersion}; - typelibName = "sample-ledger"; - in - import ./nix/purescript-bridge.nix ctl { - inherit pkgs purs spago typelibName; - generatedPursFiles = ./generated; + checks = haskellFlake.checks // purescriptBridgeNixFlake.checks // roundTripTestPursFlake.checks; + devShells = { + default = roundTripTestPursFlake.devShellComposeWith haskellFlake.devShell; + typelibNix = purescriptBridgeNixFlake.devShell; }; - # Purescript - Haskell round trip generated typelib - generatedRoundTripPursFiles = pkgs.runCommand "generate-roundtrip-test-purescript-files" - { - cli = haskellProject.getComponent "purescript-bridge:exe:roundtrip"; - } - '' - mkdir $out - $cli/bin/roundtrip generate-types --generated-dir $out - ''; - - generatedRoundTripTypelib = - let - spago = easy-ps.spago; - ctl = inputs.cardano-transaction-lib; - purs = easy-ps.${pursVersion}; - typelibName = "roundtrip-test"; - in - import ./nix/purescript-bridge.nix ctl { - inherit pkgs purs spago typelibName; - generatedPursFiles = generatedRoundTripPursFiles; + # Used by CI + build-all = pkgs.runCommand "build-all" + (self.packages.${system} // self.devShells.${system}) + "touch $out"; + + test-all = pkgs.runCommand "check-all" + { + nativeBuildInputs = builtins.attrValues self.checks.${system}; + } "touch $out"; + + # Check files + check-files = pkgs.runCommand "check-files" + ({ + checks = [ + (fileCheckers.checkNixFiles src) + (fileCheckers.checkHaskellFiles src) + (fileCheckers.checkCabalFiles src) + (fileCheckers.checkShellFiles src) + (fileCheckers.checkDhallFiles src) + (fileCheckers.checkPurescriptFiles ./generated) + (fileCheckers.checkPurescriptFiles ./roundtrip/RoundTripPurs) + ]; + }) + "touch $out"; + + # Fix files + fix-files = cq.makeBundle { + myScriptName = "fix-files"; + myScript = '' + ${fileFixers.fixNixFiles}/bin/fix-nix-files-bundle $@ + ${fileFixers.fixHaskellFiles}/bin/fix-haskell-files-bundle $@ + ${fileFixers.fixCabalFiles}/bin/fix-cabal-files-bundle $@ + ${fileFixers.fixShellFiles}/bin/fix-shell-files-bundle $@ + ${fileFixers.fixDhallFiles}/bin/fix-dhall-files-bundle $@ + ${fileFixers.fixPurescriptFiles}/bin/fix-purescript-files-bundle $@/generated + ${fileFixers.fixPurescriptFiles}/bin/fix-purescript-files-bundle $@/roundtrip/RoundTripPurs + ''; }; - # Purescript - Haskell round trip test purs flake - roundTripTestPursFlake = - let - inherit pkgs easy-ps; - src = ./roundtrip/RoundTripPurs; - workDir = "./roundtrip/RoundTripPurs"; - pursSubDirs = [ "/src" ]; - pursSubDirsTest = [ "/test" ]; - nodejs = pkgs.nodejs-14_x; - spagoLocalPkgs = [ inputs.cardano-transaction-lib generatedRoundTripTypelib ]; - purs = easy-ps.${pursVersion}; - projectName = "roundtrip-test"; - in - import ./nix/purescript-flake.nix { - inherit src workDir pursSubDirs pursSubDirsTest pkgs system easy-ps spagoLocalPkgs - nodejs purs projectName; + # Purescript and bridge Nix libs + lib = { + bridgeTypelib = (import ./nix/purescript-bridge.nix) inputs.cardano-transaction-lib; + pursFlake = import ./nix/purescript-flake.nix; + pursLib = import ./nix/purescript-lib.nix; + codeQualityLib = import ./nix/code-quality.nix; }; - # purescript-bridge.nix flake - purescriptBridgeNixFlake = - let - inherit pkgs easy-ps; - src = ./nix/purescript-bridge-nix-spago; - workDir = "./nix/purescript-bridge-nix-spago"; - pursSubDirs = [ "/src" ]; - pursSubDirsTest = [ "/test" ]; - nodejs = pkgs.nodejs-14_x; - spagoLocalPkgs = [ inputs.cardano-transaction-lib ]; - purs = easy-ps.${pursVersion}; - mainModule = "PureScriptBridge.Main"; - projectName = "purescript-bridge-nix"; - in - import ./nix/purescript-flake.nix { - inherit src workDir pursSubDirs pursSubDirsTest pkgs system easy-ps spagoLocalPkgs - nodejs purs mainModule projectName; + + hydraJobs = { + inherit build-all checks check-files; }; - in - rec - { - # Useful attributes - inherit pkgs easy-ps haskellProject haskellFlake; - - # Flake standard attributes - packages = haskellFlake.packages // purescriptBridgeNixFlake.packages // roundTripTestPursFlake.packages // { - sample-plutus-ledger-api-typelib = sampleLedgerTypelib; - plutus-ledger-api-typelib = generatedLedgerTypelib; - }; - checks = haskellFlake.checks // purescriptBridgeNixFlake.checks // roundTripTestPursFlake.checks; - devShells = { - default = roundTripTestPursFlake.devShellComposeWith haskellFlake.devShell; - typelibNix = purescriptBridgeNixFlake.devShell; - }; - - # Used by CI - build-all = pkgs.runCommand "build-all" - (self.packages.${system} // self.devShells.${system}) - "touch $out"; - - test-all = pkgs.runCommand "check-all" - { - nativeBuildInputs = builtins.attrValues self.checks.${system}; - } "touch $out"; - - # Check files - check-files = pkgs.runCommand "check-files" - ({ - checks = [ - (fileCheckers.checkNixFiles src) - (fileCheckers.checkHaskellFiles src) - (fileCheckers.checkCabalFiles src) - (fileCheckers.checkShellFiles src) - (fileCheckers.checkDhallFiles src) - (fileCheckers.checkPurescriptFiles ./generated) - (fileCheckers.checkPurescriptFiles ./roundtrip/RoundTripPurs) - ]; - }) - "touch $out"; - - # Fix files - fix-files = cq.makeBundle { - myScriptName = "fix-files"; - myScript = '' - ${fileFixers.fixNixFiles}/bin/fix-nix-files-bundle $@ - ${fileFixers.fixHaskellFiles}/bin/fix-haskell-files-bundle $@ - ${fileFixers.fixCabalFiles}/bin/fix-cabal-files-bundle $@ - ${fileFixers.fixShellFiles}/bin/fix-shell-files-bundle $@ - ${fileFixers.fixDhallFiles}/bin/fix-dhall-files-bundle $@ - ${fileFixers.fixPurescriptFiles}/bin/fix-purescript-files-bundle $@/generated - ${fileFixers.fixPurescriptFiles}/bin/fix-purescript-files-bundle $@/roundtrip/RoundTripPurs - ''; - }; - - # Purescript and bridge Nix libs - lib = { - bridgeTypelib = (import ./nix/purescript-bridge.nix) inputs.cardano-transaction-lib; - pursFlake = import ./nix/purescript-flake.nix; - pursLib = import ./nix/purescript-lib.nix; - }; - - hydraJobs = { - inherit build-all checks check-files; - }; - } - ); + } + )); } diff --git a/nix/purescript-flake.nix b/nix/purescript-flake.nix index 0fc032f8..9ce322e9 100644 --- a/nix/purescript-flake.nix +++ b/nix/purescript-flake.nix @@ -2,6 +2,7 @@ , src , pursSubDirs ? [ "/src" ] , pursSubDirsTest ? [ "/test" ] +, resourceDirs ? [ ] , workDir # FIXME: This is awkward; to cd into and attach a locals.dhall link , pkgs , system @@ -24,7 +25,7 @@ let }; nodeModules = nodePkgs'.shell.nodeDependencies; ps-lib = import ./purescript-lib.nix { - inherit pkgs projectName spagoPkgs spagoLocalPkgs nodejs nodeModules purs mainModule testModule; + inherit pkgs projectName spagoPkgs spagoLocalPkgs nodejs nodeModules purs mainModule testModule resourceDirs; spago = easy-ps.spago; }; projectDir = src; diff --git a/nix/purescript-lib.nix b/nix/purescript-lib.nix index 50ee168d..bb29b333 100644 --- a/nix/purescript-lib.nix +++ b/nix/purescript-lib.nix @@ -3,6 +3,7 @@ , spago , spagoPkgs , spagoLocalPkgs ? [ ] +, resourceDirs ? [ ] , nodejs , purs , nodeModules @@ -51,7 +52,7 @@ rec { outputs = [ "out" "compilationOut" ]; pursDirs = (builtins.map (sd: projectDir + sd) pursSubDirs); src = pursFilterSource pursDirs; - inherit spagoLocalPkgs; + inherit spagoLocalPkgs resourceDirs; buildInputs = with spagoPkgs; [ installSpagoStyle buildFromNixStore @@ -66,6 +67,9 @@ rec { buildPhase = '' set -vox mkdir $out + for resDir in $resourceDirs; do + cp -r $resDir $out/ + done cp -r ${projectDir}/* $out ln -s ${localsDhall} $out/locals.dhall @@ -142,6 +146,7 @@ rec { buildInputs = [ nodejs ]; checkPhase = '' export NODE_PATH=${nodeModules}/lib/node_modules + cp -r ${pursProject.out} . node -e 'require("${pursProject.compilationOut}/output/${testModule}").main()' > out.log ''; installPhase = ''