From e5350d2d5060b5d79315e6a2c2d1455f6f34e97f Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Mon, 19 Apr 2021 20:38:43 +0200 Subject: [PATCH] nix(refactor): Split cabalTools from devtools This allows to use `postgrest-build` in CI without pulling in a lot of dependencies. --- default.nix | 11 ++-- nix/tools/cabalTools.nix | 57 +++++++++++++++++++ nix/tools/{devtools.nix => devTools.nix} | 43 +------------- .../{nixpkgstools.nix => nixpkgsTools.nix} | 2 +- nix/tools/{withtools.nix => withTools.nix} | 2 +- shell.nix | 3 +- 6 files changed, 69 insertions(+), 49 deletions(-) create mode 100644 nix/tools/cabalTools.nix rename nix/tools/{devtools.nix => devTools.nix} (77%) rename nix/tools/{nixpkgstools.nix => nixpkgsTools.nix} (97%) rename nix/tools/{withtools.nix => withTools.nix} (99%) diff --git a/default.nix b/default.nix index 05cc88508..662c89c8c 100644 --- a/default.nix +++ b/default.nix @@ -113,9 +113,12 @@ rec { ### Tools + cabalTools = + pkgs.callPackage nix/tools/cabalTools.nix { inherit devCabalOptions postgrest; }; + # Development tools. - devtools = - pkgs.callPackage nix/tools/devtools.nix { inherit tests style devCabalOptions hsie; }; + devTools = + pkgs.callPackage nix/tools/devTools.nix { inherit tests style devCabalOptions hsie; }; # Docker images and loading script. docker = @@ -127,7 +130,7 @@ rec { # Utility for updating the pinned version of Nixpkgs. nixpkgsTools = - pkgs.callPackage nix/tools/nixpkgstools.nix { }; + pkgs.callPackage nix/tools/nixpkgsTools.nix { }; # Scripts for publishing new releases. release = @@ -149,5 +152,5 @@ rec { }; withTools = - pkgs.callPackage nix/tools/withtools.nix { inherit postgresqlVersions; }; + pkgs.callPackage nix/tools/withTools.nix { inherit postgresqlVersions; }; } diff --git a/nix/tools/cabalTools.nix b/nix/tools/cabalTools.nix new file mode 100644 index 000000000..210b4502e --- /dev/null +++ b/nix/tools/cabalTools.nix @@ -0,0 +1,57 @@ +{ buildToolbox +, cabal-install +, checkedShellScript +, devCabalOptions +, postgrest +}: +let + build = + checkedShellScript + { + name = "postgrest-build"; + docs = "Build PostgREST interactively using cabal-install."; + args = [ "ARG_LEFTOVERS([Cabal arguments])" ]; + inRootDir = true; + withEnv = postgrest.env; + } + '' + exec ${cabal-install}/bin/cabal v2-build ${devCabalOptions} "''${_arg_leftovers[@]}" + ''; + + clean = + checkedShellScript + { + name = "postgrest-clean"; + docs = "Clean the PostgREST project, including all cabal-install artifacts."; + inRootDir = true; + } + '' + # clean old coverage data, too + rm -rf .hpc coverage + exec ${cabal-install}/bin/cabal v2-clean + ''; + + run = + checkedShellScript + { + name = "postgrest-run"; + docs = "Run PostgREST after buidling it interactively with cabal-install"; + args = [ "ARG_LEFTOVERS([PostgREST arguments])" ]; + inRootDir = true; + withEnv = postgrest.env; + } + '' + exec ${cabal-install}/bin/cabal v2-run ${devCabalOptions} --verbose=0 -- \ + postgrest "''${_arg_leftovers[@]}" + ''; + +in +buildToolbox +{ + name = "postgrest-cabal"; + tools = [ + build + clean + run + ]; +} diff --git a/nix/tools/devtools.nix b/nix/tools/devTools.nix similarity index 77% rename from nix/tools/devtools.nix rename to nix/tools/devTools.nix index 0d480d2c7..a6d9364ea 100644 --- a/nix/tools/devtools.nix +++ b/nix/tools/devTools.nix @@ -57,44 +57,6 @@ let | ${cachix}/bin/cachix push postgrest ''; - build = - checkedShellScript - { - name = "postgrest-build"; - docs = "Build PostgREST interactively using cabal-install."; - args = [ "ARG_LEFTOVERS([Cabal arguments])" ]; - inRootDir = true; - } - '' - ${cabal-install}/bin/cabal v2-build ${devCabalOptions} "''${_arg_leftovers[@]}" - ''; - - run = - checkedShellScript - { - name = "postgrest-run"; - docs = "Run PostgREST after buidling it interactively with cabal-install"; - args = [ "ARG_LEFTOVERS([PostgREST arguments])" ]; - inRootDir = true; - } - '' - ${cabal-install}/bin/cabal v2-run ${devCabalOptions} --verbose=0 -- \ - postgrest "''${_arg_leftovers[@]}" - ''; - - clean = - checkedShellScript - { - name = "postgrest-clean"; - docs = "Clean the PostgREST project, including all cabal-install artifacts."; - inRootDir = true; - } - '' - ${cabal-install}/bin/cabal v2-clean - # clean old coverage data, too - rm -rf .hpc coverage - ''; - check = checkedShellScript { @@ -176,13 +138,10 @@ let in buildToolbox { - name = "postgrest-devtools"; + name = "postgrest-dev"; tools = [ watch pushCachix - build - run - clean check dumpMinimalImports hsieMinimalImports diff --git a/nix/tools/nixpkgstools.nix b/nix/tools/nixpkgsTools.nix similarity index 97% rename from nix/tools/nixpkgstools.nix rename to nix/tools/nixpkgsTools.nix index 7d33ab379..faab6bfc9 100644 --- a/nix/tools/nixpkgstools.nix +++ b/nix/tools/nixpkgsTools.nix @@ -48,6 +48,6 @@ let in buildToolbox { - name = "postgrest-nixpkgstools"; + name = "postgrest-nixpkgs"; tools = [ upgrade ]; } diff --git a/nix/tools/withtools.nix b/nix/tools/withTools.nix similarity index 99% rename from nix/tools/withtools.nix rename to nix/tools/withTools.nix index 38209b9f1..ea9085d37 100644 --- a/nix/tools/withtools.nix +++ b/nix/tools/withTools.nix @@ -127,7 +127,7 @@ let in buildToolbox { - name = "postgrest-withtools"; + name = "postgrest-with"; tools = [ withAll ] ++ withVersions; extra = { # make withTools.latest available for other nix files diff --git a/shell.nix b/shell.nix index 13c4c8139..bedab0ccf 100644 --- a/shell.nix +++ b/shell.nix @@ -25,7 +25,8 @@ let toolboxes = [ - postgrest.devtools + postgrest.cabalTools + postgrest.devTools postgrest.nixpkgsTools postgrest.style postgrest.tests