diff --git a/default.nix b/default.nix index 71e94c938..85fb530a3 100644 --- a/default.nix +++ b/default.nix @@ -31,6 +31,7 @@ let overlays = [ + allOverlays.build-toolbox allOverlays.checked-shell-script allOverlays.ghr allOverlays.gitignore @@ -109,8 +110,8 @@ rec { postgrest.env; # Utility for updating the pinned version of Nixpkgs. - nixpkgsUpgrade = - pkgs.callPackage nix/nixpkgs-upgrade.nix { }; + nixpkgsTools = + pkgs.callPackage nix/nixpkgstools.nix { }; withTools = pkgs.callPackage nix/withtools.nix { inherit postgresqlVersions; }; diff --git a/nix/devtools.nix b/nix/devtools.nix index a0db42ce1..c7b02199f 100644 --- a/nix/devtools.nix +++ b/nix/devtools.nix @@ -1,4 +1,4 @@ -{ buildEnv +{ buildToolbox , cabal-install , checkedShellScript , devCabalOptions @@ -171,6 +171,10 @@ let ${hsieMinimalImports} graph-symbols | ${graphviz}/bin/dot -Tpng -o "$_arg_outfile" ''; +in +buildToolbox +{ + name = "postgrest-devtools"; tools = [ watch pushCachix @@ -183,12 +187,4 @@ let hsieGraphModules hsieGraphSymbols ]; - - bashCompletion = builtins.map (tool: tool.bashCompletion) tools; - -in -buildEnv - { - name = "postgrest-devtools"; - paths = builtins.map (tool: tool.bin) tools; - } // { inherit bashCompletion; } +} diff --git a/nix/docker/default.nix b/nix/docker/default.nix index baf827768..2873225b3 100644 --- a/nix/docker/default.nix +++ b/nix/docker/default.nix @@ -1,4 +1,4 @@ -{ buildEnv +{ buildToolbox , postgrest , dockerTools , checkedShellScript @@ -37,9 +37,13 @@ let '' docker load -i ${image} ''; + in -buildEnv - { - name = "postgrest-docker"; - paths = [ load.bin ]; - } // { inherit image; bashCompletion = load.bashCompletion; } +buildToolbox +{ + name = "postgrest-docker"; + tools = [ load ]; + extra = { + inherit image; + }; +} diff --git a/nix/memory.nix b/nix/memory.nix index 4a923ef40..064cec8f1 100644 --- a/nix/memory.nix +++ b/nix/memory.nix @@ -1,7 +1,7 @@ # The memory tests have large dependencies (a profiled build of PostgREST) # and are run less often than the spec tests, so we don't include them in # the default test environment. We make them available through a separate module. -{ buildEnv +{ buildToolbox , checkedShellScript , curl , postgrestProfiled @@ -22,9 +22,8 @@ let ''; in -buildEnv - { - name = "postgrest-memory"; - - paths = [ test.bin ]; - } // { bashCompletion = test.bashCompletion; } +buildToolbox +{ + name = "postgrest-memory"; + tools = [ test ]; +} diff --git a/nix/nixpkgs-upgrade.nix b/nix/nixpkgstools.nix similarity index 90% rename from nix/nixpkgs-upgrade.nix rename to nix/nixpkgstools.nix index b49b97a66..7d33ab379 100644 --- a/nix/nixpkgs-upgrade.nix +++ b/nix/nixpkgstools.nix @@ -1,4 +1,5 @@ -{ checkedShellScript +{ buildToolbox +, checkedShellScript , curl , jq , nix @@ -21,7 +22,7 @@ let tarballUrlBase = https://github.com/nixos/nixpkgs/archive/; - script = + upgrade = checkedShellScript { inherit name; @@ -43,5 +44,10 @@ let } EOF ''; + in -script +buildToolbox +{ + name = "postgrest-nixpkgstools"; + tools = [ upgrade ]; +} diff --git a/nix/overlays/build-toolbox/build-toolbox.nix b/nix/overlays/build-toolbox/build-toolbox.nix new file mode 100644 index 000000000..a170f9a24 --- /dev/null +++ b/nix/overlays/build-toolbox/build-toolbox.nix @@ -0,0 +1,16 @@ +# Creates an environment that exposes bashCompletion arguments from all checkedShellScripts +{ buildEnv }: +{ name +, tools +, extra ? { } +}: +let + bashCompletion = builtins.map (tool: tool.bashCompletion) tools; + + env = buildEnv { + inherit name; + paths = builtins.map (tool: tool.bin) tools; + }; + +in +env // { inherit bashCompletion; } // extra diff --git a/nix/overlays/build-toolbox/default.nix b/nix/overlays/build-toolbox/default.nix new file mode 100644 index 000000000..201b2e953 --- /dev/null +++ b/nix/overlays/build-toolbox/default.nix @@ -0,0 +1,5 @@ +self: super: +# Overlay that adds `buildToolbox`, an enhanced version of `buildEnv` +{ + buildToolbox = super.callPackage ./build-toolbox.nix { }; +} diff --git a/nix/overlays/default.nix b/nix/overlays/default.nix index 780841760..8ad1f714b 100644 --- a/nix/overlays/default.nix +++ b/nix/overlays/default.nix @@ -1,4 +1,5 @@ { + build-toolbox = import ./build-toolbox; checked-shell-script = import ./checked-shell-script; ghr = import ./ghr; gitignore = import ./gitignore.nix; diff --git a/nix/release/default.nix b/nix/release/default.nix index c777f5807..8c9cfac77 100644 --- a/nix/release/default.nix +++ b/nix/release/default.nix @@ -1,4 +1,4 @@ -{ buildEnv +{ buildToolbox , checkedShellScript , curl , docker @@ -166,13 +166,9 @@ let [ "$responseCode" -eq 200 ] ''; - tools = [ github dockerLogin dockerHub dockerHubDescription ]; - - bashCompletion = builtins.map (tool: tool.bashCompletion) tools; - in -buildEnv - { - name = "postgrest-release"; - paths = builtins.map (tool: tool.bin) tools; - } // { inherit bashCompletion; } +buildToolbox +{ + name = "postgrest-release"; + tools = [ github dockerLogin dockerHub dockerHubDescription ]; +} diff --git a/nix/style.nix b/nix/style.nix index 3cfda243a..1ea78ffa5 100644 --- a/nix/style.nix +++ b/nix/style.nix @@ -1,5 +1,5 @@ { black -, buildEnv +, buildToolbox , checkedShellScript , git , hlint @@ -60,13 +60,9 @@ let ${shellcheck}/bin/shellcheck test/create_test_db test/memory-tests.sh test/with_tmp_db ''; - tools = [ style styleCheck lint ]; - - bashCompletion = builtins.map (tool: tool.bashCompletion) tools; - in -buildEnv - { - name = "postgrest-style"; - paths = builtins.map (tool: tool.bin) tools; - } // { inherit bashCompletion; } +buildToolbox +{ + name = "postgrest-style"; + tools = [ style styleCheck lint ]; +} diff --git a/nix/tests.nix b/nix/tests.nix index 361465136..67c8b6bfd 100644 --- a/nix/tests.nix +++ b/nix/tests.nix @@ -1,6 +1,4 @@ -# Utilities for running the PostgREST test suite - -{ buildEnv +{ buildToolbox , cabal-install , checkedShellScript , devCabalOptions @@ -156,6 +154,10 @@ let sed -i 's|^module \(.*\):|module \1/|g' test/coverage.overlay ''; +in +buildToolbox +{ + name = "postgrest-tests"; tools = [ testSpec @@ -165,16 +167,4 @@ let coverage coverageDraftOverlay ]; - - bashCompletion = builtins.map (tool: tool.bashCompletion) tools; - -in -# Create an environment that contains all the utility scripts for running tests - # that we defined above. -buildEnv - { - name = - "postgrest-tests"; - - paths = builtins.map (tool: tool.bin) tools; - } // { inherit bashCompletion; } +} diff --git a/nix/withtools.nix b/nix/withtools.nix index bfcbb232c..8851cd3f8 100644 --- a/nix/withtools.nix +++ b/nix/withtools.nix @@ -1,5 +1,5 @@ { bashCompletion -, buildEnv +, buildToolbox , checkedShellScript , lib , postgresqlVersions @@ -77,20 +77,13 @@ let # Create a `postgrest-with-postgresql-` for each PostgreSQL version withVersions = builtins.map withTmpDb postgresqlVersions; - tools = [ withAll ] ++ withVersions; - - bashCompletion = builtins.map (tool: tool.bashCompletion) tools; - in -buildEnv - { - name = - "postgrest-withtools"; - - paths = builtins.map (tool: tool.bin) tools; - } // { - inherit bashCompletion; - - # make withTools.latest available for other nix files - latest = withTmpDb (builtins.head postgresqlVersions); +buildToolbox +{ + name = "postgrest-withtools"; + tools = [ withAll ] ++ withVersions; + extra = { + # make withTools.latest available for other nix files + latest = withTmpDb (builtins.head postgresqlVersions); + }; } diff --git a/shell.nix b/shell.nix index 7c7dfe31a..13c4c8139 100644 --- a/shell.nix +++ b/shell.nix @@ -9,7 +9,10 @@ # # We highly recommend that use the PostgREST binary cache by installing cachix # (https://app.cachix.org/) and running `cachix use postgrest`. -{ memory ? false, docker ? false, release ? false }: +{ docker ? false +, memory ? false +, release ? false +}: let postgrest = import ./default.nix; @@ -20,13 +23,16 @@ let lib = pkgs.lib; - modules = + toolboxes = [ postgrest.devtools + postgrest.nixpkgsTools postgrest.style postgrest.tests postgrest.withTools ] + ++ lib.optional docker postgrest.docker + ++ lib.optional memory postgrest.memory ++ lib.optional release postgrest.release; in @@ -38,24 +44,18 @@ lib.overrideDerivation postgrest.env ( pkgs.cabal2nix pkgs.postgresql postgrest.hsie.bin - postgrest.nixpkgsUpgrade.bin ] - ++ modules - ++ lib.optional memory postgrest.memory - ++ lib.optional docker postgrest.docker; + ++ toolboxes; shellHook = '' source ${pkgs.bashCompletion}/etc/profile.d/bash_completion.sh + source ${postgrest.hsie.bashCompletion} '' + builtins.concatStringsSep "\n" ( builtins.map (bashCompletion: "source ${bashCompletion}") ( - builtins.concatLists (builtins.map (module: module.bashCompletion) modules) - ++ [ postgrest.hsie.bashCompletion postgrest.nixpkgsUpgrade.bashCompletion ] - ++ lib.optional memory postgrest.memory.bashCompletion - ++ lib.optional docker postgrest.docker.bashCompletion - + builtins.concatLists (builtins.map (toolbox: toolbox.bashCompletion) toolboxes) ) ); }