From e110fdbd2c600222e31065ae66203d0e873ae51f Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sat, 17 Feb 2024 20:19:17 +0100 Subject: [PATCH] nix: Refactor checkedShellScript's inRootDir to workingDir This allows more flexible control over the working directory. Values for workingDir must always start with a / and will then be relative to the repo root. --- .../checked-shell-script/checked-shell-script.nix | 7 +++++-- nix/tools/cabalTools.nix | 8 ++++---- nix/tools/devTools.nix | 10 +++++----- nix/tools/loadtest.nix | 8 ++++---- nix/tools/memory.nix | 2 +- nix/tools/nixpkgsTools.nix | 2 +- nix/tools/release/default.nix | 2 +- nix/tools/style.nix | 6 +++--- nix/tools/tests.nix | 14 +++++++------- nix/tools/withTools.nix | 12 ++++++------ 10 files changed, 37 insertions(+), 34 deletions(-) diff --git a/nix/overlays/checked-shell-script/checked-shell-script.nix b/nix/overlays/checked-shell-script/checked-shell-script.nix index 591f9f894..64297d19c 100644 --- a/nix/overlays/checked-shell-script/checked-shell-script.nix +++ b/nix/overlays/checked-shell-script/checked-shell-script.nix @@ -15,12 +15,13 @@ , docs , args ? [ ] , positionalCompletion ? "" -, inRootDir ? false , redirectTixFiles ? true , withEnv ? null , withPath ? [ ] , withTmpDir ? false +, workingDir ? null }: text: +assert workingDir == null || lib.hasPrefix "/" workingDir; let # square brackets are a pain to escape - if even possible. just don't use them... escape = builtins.replaceStrings [ "\n" ] [ " \\n" ]; @@ -89,7 +90,7 @@ let trap 'rm -rf $hpctixdir' EXIT '' - + lib.optionalString inRootDir '' + + lib.optionalString (workingDir != null) '' cd "$(${git}/bin/git rev-parse --show-toplevel)" if test ! -f postgrest.cabal; then @@ -97,6 +98,8 @@ let "run this command somewhere in the PostgREST repo." exit 1 fi + + cd "''${PWD}${workingDir}" '' + lib.optionalString withTmpDir '' diff --git a/nix/tools/cabalTools.nix b/nix/tools/cabalTools.nix index eb6198058..fef0d726b 100644 --- a/nix/tools/cabalTools.nix +++ b/nix/tools/cabalTools.nix @@ -11,7 +11,7 @@ let name = "postgrest-build"; docs = "Build PostgREST interactively using cabal-install."; args = [ "ARG_LEFTOVERS([Cabal arguments])" ]; - inRootDir = true; + workingDir = "/"; withEnv = postgrest.env; } '' @@ -23,7 +23,7 @@ let { name = "postgrest-clean"; docs = "Clean the PostgREST project, including all cabal-install artifacts."; - inRootDir = true; + workingDir = "/"; } '' # clean old coverage data, too @@ -45,7 +45,7 @@ let "ARG_USE_ENV([PGRST_DB_POOL_ACQUISITION_TIMEOUT], [1], [PostgREST pool size])" "ARG_LEFTOVERS([PostgREST arguments])" ]; - inRootDir = true; + workingDir = "/"; withEnv = postgrest.env; } '' @@ -63,7 +63,7 @@ let name = "postgrest-repl"; docs = "Interact with PostgREST modules using the cabal repl"; args = [ "ARG_LEFTOVERS([cabal v2-repl arguments])" ]; - inRootDir = true; + workingDir = "/"; withEnv = postgrest.env; } '' diff --git a/nix/tools/devTools.nix b/nix/tools/devTools.nix index 07393687e..d2b0a9ac4 100644 --- a/nix/tools/devTools.nix +++ b/nix/tools/devTools.nix @@ -34,7 +34,7 @@ let ]; positionalCompletion = "_command"; redirectTixFiles = false; # will be done by sub-command - inRootDir = true; + workingDir = "/"; } '' while true; do @@ -51,7 +51,7 @@ let Requires authentication with `cachix authtoken ...`. ''; - inRootDir = true; + workingDir = "/"; } '' ${nix}/bin/nix-instantiate \ @@ -71,7 +71,7 @@ let This currently excludes the memory and spec-idempotence tests, as those are particularly expensive. ''; - inRootDir = true; + workingDir = "/"; } '' ${tests}/bin/postgrest-test-spec @@ -126,7 +126,7 @@ let COMPREPLY=( $(compgen -W "basic full" -- "$cur") ) fi ''; - inRootDir = true; + workingDir = "/"; } '' if [ run != "$_arg_operation" ]; then @@ -237,7 +237,7 @@ let name = "postgrest-dump-minimal-imports"; docs = "Dump minimal imports into given directory."; args = [ "ARG_POSITIONAL_SINGLE([dumpdir], [Output directory])" ]; - inRootDir = true; + workingDir = "/"; withTmpDir = true; } '' diff --git a/nix/tools/loadtest.nix b/nix/tools/loadtest.nix index 6c2988b33..097375464 100644 --- a/nix/tools/loadtest.nix +++ b/nix/tools/loadtest.nix @@ -43,7 +43,7 @@ let "ARG_OPTIONAL_SINGLE([testdir], [t], [Directory to load tests and fixtures from], [./test/load])" "ARG_LEFTOVERS([additional vegeta arguments])" ]; - inRootDir = true; + workingDir = "/"; } '' # previously required settings to make this work with older branches @@ -90,7 +90,7 @@ let __gitcomp_nl "$(__git_refs)" fi ''; - inRootDir = true; + workingDir = "/"; } '' for tgt in "''${_arg_target[@]}"; do @@ -140,7 +140,7 @@ let "ARG_POSITIONAL_SINGLE([file], [Filename of result to create report for])" "ARG_LEFTOVERS([additional vegeta arguments])" ]; - inRootDir = true; + workingDir = "/"; } '' ${vegeta}/bin/vegeta report -type=json "$_arg_file" \ @@ -169,7 +169,7 @@ let { name = "postgrest-loadtest-report"; docs = "Create a report of all loadtest reports as markdown."; - inRootDir = true; + workingDir = "/"; } '' find loadtest -type f -iname '*.bin' -exec ${reporter} {} \; \ diff --git a/nix/tools/memory.nix b/nix/tools/memory.nix index a233e3397..1dee50e1a 100644 --- a/nix/tools/memory.nix +++ b/nix/tools/memory.nix @@ -13,7 +13,7 @@ let { name = "postgrest-test-memory"; docs = "Run the memory tests."; - inRootDir = true; + workingDir = "/"; withPath = [ postgrestProfiled curl ]; } '' diff --git a/nix/tools/nixpkgsTools.nix b/nix/tools/nixpkgsTools.nix index 6f4d04269..b53aaa04c 100644 --- a/nix/tools/nixpkgsTools.nix +++ b/nix/tools/nixpkgsTools.nix @@ -28,7 +28,7 @@ let { inherit name; docs = "Pin the newest stable version of Nixpkgs."; - inRootDir = true; + workingDir = "/"; } '' # The list of refs is sorted. The first result will be nixpkgs-unstable, the second the latest stable branch. diff --git a/nix/tools/release/default.nix b/nix/tools/release/default.nix index 67e44f114..519a50cfc 100644 --- a/nix/tools/release/default.nix +++ b/nix/tools/release/default.nix @@ -53,7 +53,7 @@ let name = "postgrest-release"; docs = "Patch postgrest.cabal, CHANGELOG.md, tag and push all in one go."; args = [ "ARG_POSITIONAL_SINGLE([version], [Version to release], [pre])" ]; - inRootDir = true; + workingDir = "/"; } '' trap "echo You need to be on the main branch or a release branch to proceed. Exiting ..." ERR diff --git a/nix/tools/style.nix b/nix/tools/style.nix index dc716185b..7c1f35239 100644 --- a/nix/tools/style.nix +++ b/nix/tools/style.nix @@ -17,7 +17,7 @@ let { name = "postgrest-style"; docs = "Automatically format Haskell, Nix and Python files."; - inRootDir = true; + workingDir = "/"; } '' # Format Nix files @@ -39,7 +39,7 @@ let { name = "postgrest-style-check"; docs = "Check whether postgrest-style results in any uncommited changes."; - inRootDir = true; + workingDir = "/"; } '' ${style} @@ -54,7 +54,7 @@ let { name = "postgrest-lint"; docs = "Lint all Haskell files, bash scripts and github workflows."; - inRootDir = true; + workingDir = "/"; } '' echo "Checking consistency of import aliases in Haskell code..." diff --git a/nix/tools/tests.nix b/nix/tools/tests.nix index 08521b50b..1e57c4e88 100644 --- a/nix/tools/tests.nix +++ b/nix/tools/tests.nix @@ -24,7 +24,7 @@ let name = "postgrest-test-spec"; docs = "Run the Haskell test suite. Use --match PATTERN for running individual specs"; args = [ "ARG_LEFTOVERS([hspec arguments])" ]; - inRootDir = true; + workingDir = "/"; withEnv = postgrest.env; } '' @@ -37,7 +37,7 @@ let { name = "postgrest-test-doctests"; docs = "Run the Haskell doctest test suite"; - inRootDir = true; + workingDir = "/"; withEnv = postgrest.env; } '' @@ -49,7 +49,7 @@ let { name = "postgrest-test-spec-idempotence"; docs = "Check that the Haskell tests can be run multiple times against the same db."; - inRootDir = true; + workingDir = "/"; withEnv = postgrest.env; } '' @@ -75,7 +75,7 @@ let name = "postgrest-test-io"; docs = "Run the pytest-based IO tests. Add -k to run tests that match a given expression."; args = [ "ARG_LEFTOVERS([pytest arguments])" ]; - inRootDir = true; + workingDir = "/"; withEnv = postgrest.env; } '' @@ -89,7 +89,7 @@ let { name = "postgrest-dump-schema"; docs = "Dump the loaded schema's SchemaCache as a yaml file."; - inRootDir = true; + workingDir = "/"; withEnv = postgrest.env; withPath = [ jq ]; } @@ -106,7 +106,7 @@ let name = "postgrest-coverage"; docs = "Run spec and io tests while collecting hpc coverage data. First runs weeder to detect dead code."; args = [ "ARG_LEFTOVERS([hpc report arguments])" ]; - inRootDir = true; + workingDir = "/"; redirectTixFiles = false; withEnv = postgrest.env; withTmpDir = true; @@ -181,7 +181,7 @@ let { name = "postgrest-coverage-draft-overlay"; docs = "Create a draft overlay from current coverage report."; - inRootDir = true; + workingDir = "/"; } '' ${ghc}/bin/hpc draft --output=test/coverage.overlay coverage/postgrest.tix diff --git a/nix/tools/withTools.nix b/nix/tools/withTools.nix index 51764a064..7efc5fff3 100644 --- a/nix/tools/withTools.nix +++ b/nix/tools/withTools.nix @@ -34,7 +34,7 @@ let "ARG_USE_ENV([PGOPTIONS], [-c search_path=public,test], [PG options to use])" ]; positionalCompletion = "_command"; - inRootDir = true; + workingDir = "/"; redirectTixFiles = false; withPath = [ postgresql ]; withTmpDir = true; @@ -139,7 +139,7 @@ let "ARG_LEFTOVERS([command arguments])" ]; positionalCompletion = "_command"; - inRootDir = true; + workingDir = "/"; } (lib.concatStringsSep "\n\n" runners); @@ -161,7 +161,7 @@ let "ARG_USE_ENV([PGDELAY], [0ms], [extra PG latency (duration)])" ]; positionalCompletion = "_command"; - inRootDir = true; + workingDir = "/"; redirectTixFiles = false; withTmpDir = true; } @@ -199,7 +199,7 @@ let "ARG_USE_ENV([PGRST_DELAY], [0ms], [extra PostgREST latency (duration)])" ]; positionalCompletion = "_command"; - inRootDir = true; + workingDir = "/"; redirectTixFiles = false; withTmpDir = true; } @@ -249,7 +249,7 @@ let _command_offset 2 fi ''; - inRootDir = true; + workingDir = "/"; } '' # not using withTmpDir here, because we don't want to keep the directory on error @@ -360,7 +360,7 @@ let "ARG_LEFTOVERS([command arguments])" ]; positionalCompletion = "_command"; - inRootDir = true; + workingDir = "/"; withEnv = postgrest.env; withTmpDir = true; }