nix(refactor): Add buildToolbox to streamline module interface towards shell.nix

This commit is contained in:
Wolfgang Walther
2021-04-18 13:51:39 +02:00
committed by Wolfgang Walther
parent de73ced34a
commit fe497fc438
13 changed files with 94 additions and 91 deletions
+3 -2
View File
@@ -31,6 +31,7 @@ let
overlays = overlays =
[ [
allOverlays.build-toolbox
allOverlays.checked-shell-script allOverlays.checked-shell-script
allOverlays.ghr allOverlays.ghr
allOverlays.gitignore allOverlays.gitignore
@@ -109,8 +110,8 @@ rec {
postgrest.env; postgrest.env;
# Utility for updating the pinned version of Nixpkgs. # Utility for updating the pinned version of Nixpkgs.
nixpkgsUpgrade = nixpkgsTools =
pkgs.callPackage nix/nixpkgs-upgrade.nix { }; pkgs.callPackage nix/nixpkgstools.nix { };
withTools = withTools =
pkgs.callPackage nix/withtools.nix { inherit postgresqlVersions; }; pkgs.callPackage nix/withtools.nix { inherit postgresqlVersions; };
+6 -10
View File
@@ -1,4 +1,4 @@
{ buildEnv { buildToolbox
, cabal-install , cabal-install
, checkedShellScript , checkedShellScript
, devCabalOptions , devCabalOptions
@@ -171,6 +171,10 @@ let
${hsieMinimalImports} graph-symbols | ${graphviz}/bin/dot -Tpng -o "$_arg_outfile" ${hsieMinimalImports} graph-symbols | ${graphviz}/bin/dot -Tpng -o "$_arg_outfile"
''; '';
in
buildToolbox
{
name = "postgrest-devtools";
tools = [ tools = [
watch watch
pushCachix pushCachix
@@ -183,12 +187,4 @@ let
hsieGraphModules hsieGraphModules
hsieGraphSymbols hsieGraphSymbols
]; ];
}
bashCompletion = builtins.map (tool: tool.bashCompletion) tools;
in
buildEnv
{
name = "postgrest-devtools";
paths = builtins.map (tool: tool.bin) tools;
} // { inherit bashCompletion; }
+10 -6
View File
@@ -1,4 +1,4 @@
{ buildEnv { buildToolbox
, postgrest , postgrest
, dockerTools , dockerTools
, checkedShellScript , checkedShellScript
@@ -37,9 +37,13 @@ let
'' ''
docker load -i ${image} docker load -i ${image}
''; '';
in in
buildEnv buildToolbox
{ {
name = "postgrest-docker"; name = "postgrest-docker";
paths = [ load.bin ]; tools = [ load ];
} // { inherit image; bashCompletion = load.bashCompletion; } extra = {
inherit image;
};
}
+6 -7
View File
@@ -1,7 +1,7 @@
# The memory tests have large dependencies (a profiled build of PostgREST) # 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 # 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. # the default test environment. We make them available through a separate module.
{ buildEnv { buildToolbox
, checkedShellScript , checkedShellScript
, curl , curl
, postgrestProfiled , postgrestProfiled
@@ -22,9 +22,8 @@ let
''; '';
in in
buildEnv buildToolbox
{ {
name = "postgrest-memory"; name = "postgrest-memory";
tools = [ test ];
paths = [ test.bin ]; }
} // { bashCompletion = test.bashCompletion; }
@@ -1,4 +1,5 @@
{ checkedShellScript { buildToolbox
, checkedShellScript
, curl , curl
, jq , jq
, nix , nix
@@ -21,7 +22,7 @@ let
tarballUrlBase = tarballUrlBase =
https://github.com/nixos/nixpkgs/archive/; https://github.com/nixos/nixpkgs/archive/;
script = upgrade =
checkedShellScript checkedShellScript
{ {
inherit name; inherit name;
@@ -43,5 +44,10 @@ let
} }
EOF EOF
''; '';
in in
script buildToolbox
{
name = "postgrest-nixpkgstools";
tools = [ upgrade ];
}
@@ -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
+5
View File
@@ -0,0 +1,5 @@
self: super:
# Overlay that adds `buildToolbox`, an enhanced version of `buildEnv`
{
buildToolbox = super.callPackage ./build-toolbox.nix { };
}
+1
View File
@@ -1,4 +1,5 @@
{ {
build-toolbox = import ./build-toolbox;
checked-shell-script = import ./checked-shell-script; checked-shell-script = import ./checked-shell-script;
ghr = import ./ghr; ghr = import ./ghr;
gitignore = import ./gitignore.nix; gitignore = import ./gitignore.nix;
+6 -10
View File
@@ -1,4 +1,4 @@
{ buildEnv { buildToolbox
, checkedShellScript , checkedShellScript
, curl , curl
, docker , docker
@@ -166,13 +166,9 @@ let
[ "$responseCode" -eq 200 ] [ "$responseCode" -eq 200 ]
''; '';
tools = [ github dockerLogin dockerHub dockerHubDescription ];
bashCompletion = builtins.map (tool: tool.bashCompletion) tools;
in in
buildEnv buildToolbox
{ {
name = "postgrest-release"; name = "postgrest-release";
paths = builtins.map (tool: tool.bin) tools; tools = [ github dockerLogin dockerHub dockerHubDescription ];
} // { inherit bashCompletion; } }
+6 -10
View File
@@ -1,5 +1,5 @@
{ black { black
, buildEnv , buildToolbox
, checkedShellScript , checkedShellScript
, git , git
, hlint , hlint
@@ -60,13 +60,9 @@ let
${shellcheck}/bin/shellcheck test/create_test_db test/memory-tests.sh test/with_tmp_db ${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 in
buildEnv buildToolbox
{ {
name = "postgrest-style"; name = "postgrest-style";
paths = builtins.map (tool: tool.bin) tools; tools = [ style styleCheck lint ];
} // { inherit bashCompletion; } }
+6 -16
View File
@@ -1,6 +1,4 @@
# Utilities for running the PostgREST test suite { buildToolbox
{ buildEnv
, cabal-install , cabal-install
, checkedShellScript , checkedShellScript
, devCabalOptions , devCabalOptions
@@ -156,6 +154,10 @@ let
sed -i 's|^module \(.*\):|module \1/|g' test/coverage.overlay sed -i 's|^module \(.*\):|module \1/|g' test/coverage.overlay
''; '';
in
buildToolbox
{
name = "postgrest-tests";
tools = tools =
[ [
testSpec testSpec
@@ -165,16 +167,4 @@ let
coverage coverage
coverageDraftOverlay 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; }
+9 -16
View File
@@ -1,5 +1,5 @@
{ bashCompletion { bashCompletion
, buildEnv , buildToolbox
, checkedShellScript , checkedShellScript
, lib , lib
, postgresqlVersions , postgresqlVersions
@@ -77,20 +77,13 @@ let
# Create a `postgrest-with-postgresql-` for each PostgreSQL version # Create a `postgrest-with-postgresql-` for each PostgreSQL version
withVersions = builtins.map withTmpDb postgresqlVersions; withVersions = builtins.map withTmpDb postgresqlVersions;
tools = [ withAll ] ++ withVersions;
bashCompletion = builtins.map (tool: tool.bashCompletion) tools;
in in
buildEnv buildToolbox
{ {
name = name = "postgrest-withtools";
"postgrest-withtools"; tools = [ withAll ] ++ withVersions;
extra = {
paths = builtins.map (tool: tool.bin) tools; # make withTools.latest available for other nix files
} // { latest = withTmpDb (builtins.head postgresqlVersions);
inherit bashCompletion; };
# make withTools.latest available for other nix files
latest = withTmpDb (builtins.head postgresqlVersions);
} }
+11 -11
View File
@@ -9,7 +9,10 @@
# #
# We highly recommend that use the PostgREST binary cache by installing cachix # We highly recommend that use the PostgREST binary cache by installing cachix
# (https://app.cachix.org/) and running `cachix use postgrest`. # (https://app.cachix.org/) and running `cachix use postgrest`.
{ memory ? false, docker ? false, release ? false }: { docker ? false
, memory ? false
, release ? false
}:
let let
postgrest = postgrest =
import ./default.nix; import ./default.nix;
@@ -20,13 +23,16 @@ let
lib = lib =
pkgs.lib; pkgs.lib;
modules = toolboxes =
[ [
postgrest.devtools postgrest.devtools
postgrest.nixpkgsTools
postgrest.style postgrest.style
postgrest.tests postgrest.tests
postgrest.withTools postgrest.withTools
] ]
++ lib.optional docker postgrest.docker
++ lib.optional memory postgrest.memory
++ lib.optional release postgrest.release; ++ lib.optional release postgrest.release;
in in
@@ -38,24 +44,18 @@ lib.overrideDerivation postgrest.env (
pkgs.cabal2nix pkgs.cabal2nix
pkgs.postgresql pkgs.postgresql
postgrest.hsie.bin postgrest.hsie.bin
postgrest.nixpkgsUpgrade.bin
] ]
++ modules ++ toolboxes;
++ lib.optional memory postgrest.memory
++ lib.optional docker postgrest.docker;
shellHook = shellHook =
'' ''
source ${pkgs.bashCompletion}/etc/profile.d/bash_completion.sh source ${pkgs.bashCompletion}/etc/profile.d/bash_completion.sh
source ${postgrest.hsie.bashCompletion}
'' ''
+ builtins.concatStringsSep "\n" ( + builtins.concatStringsSep "\n" (
builtins.map (bashCompletion: "source ${bashCompletion}") ( builtins.map (bashCompletion: "source ${bashCompletion}") (
builtins.concatLists (builtins.map (module: module.bashCompletion) modules) builtins.concatLists (builtins.map (toolbox: toolbox.bashCompletion) toolboxes)
++ [ postgrest.hsie.bashCompletion postgrest.nixpkgsUpgrade.bashCompletion ]
++ lib.optional memory postgrest.memory.bashCompletion
++ lib.optional docker postgrest.docker.bashCompletion
) )
); );
} }