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 =
[
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; };
+6 -10
View File
@@ -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; }
}
+10 -6
View File
@@ -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;
};
}
+6 -7
View File
@@ -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 ];
}
@@ -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 ];
}
@@ -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;
ghr = import ./ghr;
gitignore = import ./gitignore.nix;
+6 -10
View File
@@ -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 ];
}
+6 -10
View File
@@ -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 ];
}
+6 -16
View File
@@ -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; }
}
+9 -16
View File
@@ -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);
};
}
+11 -11
View File
@@ -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)
)
);
}