diff --git a/nix/localstack-up.nix b/nix/localstack-up.nix new file mode 100644 index 000000000..0863dec3d --- /dev/null +++ b/nix/localstack-up.nix @@ -0,0 +1,15 @@ +{ lib +, localstack +, writeShellApplication +}: + +# writeShellApplication is a "writer helper" which +# will create a shellchecked executable shell script located in $out/bin/ +# This shell script will be used to allow for impure+stateful actions +writeShellApplication { + name = "localstack-up"; + # Docker must be installed outside of the development shell, so only + # pass localstack to script + runtimeInputs = [ localstack ]; + text = builtins.readFile ../scripts/localstack_up.sh; +} diff --git a/nix/overlay.nix b/nix/overlay.nix index 27d6b7be4..11fbd3282 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -1,121 +1,122 @@ # An overlay allows for a package set to be extended with new or modified packages # `final` refers to the package set with all overlays applied. # This allows for added or modified packages to be referenced with # all relevant changes final: # `prev` refers to the previous package set before this current overlay is applied. # This is cheaper for nix to evaluate, thus should be prefered over final when possible. prev: { # Patch aws-sdk-cpp to automatically pick up header location # specific to nixpkgs, as nixpkgs separates build-time and runtime # depencenies (a saving of 400MB in header + generated files). # In the case of c and c++, this means the header files are # located in a separate directory from the libraries. # # From a developer perspective, this avoids having to manually specify # the header location with `-DAWS_CORE_HEADER_FILE` each time # one invokes `cmake` on the command line when using # `find_package(AWSSDK COMPONENTS [comps])` # # For more information, see: # - aws-sdk-cpp issue: https://github.com/aws/aws-sdk-cpp/issues/2009 # - Nixpkgs fix: https://github.com/NixOS/nixpkgs/pull/182918 aws-sdk-cpp = (prev.aws-sdk-cpp.overrideAttrs(oldAttrs:{ postPatch = oldAttrs.postPatch + '' substituteInPlace cmake/AWSSDKConfig.cmake \ --replace 'C:/AWSSDK/''${AWSSDK_INSTALL_INCLUDEDIR}/aws/core' \ 'C:/AWSSDK/''${AWSSDK_INSTALL_INCLUDEDIR}/aws/core" "${placeholder "dev"}/include/aws/core' ''; })).override { # avoid rebuildilng all 300+ apis apis = [ "core" "s3" "dynamodb" ]; }; # add packages meant for just this repository amqp-cpp = prev.callPackage ./amqp-cpp.nix { }; arcanist = prev.callPackage ./arcanist.nix { }; better-prompt = prev.callPackage ./better-prompt.nix { }; # c-ares is used to bootstrap curl, so cmake is not available in the default # build c-ares_cmake-config = prev.c-ares.overrideAttrs(o: { nativeBuildInputs = (o.nativeBuildInputs or []) ++ [ prev.cmake ]; }); protobuf_3_15_cmake = prev.callPackage ./protobuf_3_15.nix { }; devShells.default = final.callPackage ./dev-shell.nix { }; devShell = final.devShells.default; + localstack-up = prev.callPackage ./localstack-up.nix { }; # Make our version of mariadb the default everywhere mariadb = prev.mariadb_108; mariadb-up = prev.callPackage ./mariadb-up-mac.nix { }; mysql-down = prev.callPackage ./mysql-down-linux.nix { }; mysql-up = prev.callPackage ./mysql-up-linux.nix { }; redis-up = prev.callPackage ./redis-up-mac.nix { }; olm = prev.olm.overrideAttrs(oldAttrs: { # *.hh files aren't meant to be used externally # so we patch installation to add it postInstall = '' cp \ $NIX_BUILD_TOP/${oldAttrs.src.name}/include/olm/*.h* \ ''${!outputDev}/include/olm ''; }); corrosion = prev.corrosion.overrideAttrs(_: { patches = [ # Fix logic around finding cargo and rustc when not managed by rustup (prev.fetchpatch { url = "https://github.com/corrosion-rs/corrosion/commit/d5330b3f03c7abb4e4da71e35654fa03ecb778bb.patch"; sha256 = "sha256-jrA30bWNWprkqCiedf+xL7GlR9+9jgOyKAoTPVKkB9c="; }) ]; }); # 16.14 now requires experimental import assertions syntax, pin to 16.13 # https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V16.md nodejs-16_x = prev.nodejs-16_x.overrideAttrs (oldAttrs: rec { version = "16.13.0"; name = "nodejs-${version}"; src = prev.fetchurl { url = "https://nodejs.org/dist/v${version}/node-v${version}.tar.xz"; sha256 = "sha256-MhFLPcOUXtD5X4vDO0LGjg7xjECMtWEiVyoWPZB+y8w="; }; # Nixpkgs applies two patches for 16.15. One patch is for finding headers # needed for v8 on darwin using apple_sdk 11; the other patch fixes crashes # related cache dir defaulting to using `$HOME` without asserting that # it exists. # # However, 16.13 doesn't need the second patch, as the regression which # caused it was introduced after 16.13. This ends up being a no-op. But # nix will still try to apply the patch and fail with "this patch has # already been applied". # # For more context, see (https://github.com/npm/cli/pull/5197) # # lib.head will select the first element in an array patches = [ (prev.lib.head oldAttrs.patches) ]; }); # Ensure that yarn is using the pinned version yarn = prev.yarn.override (_: { nodejs = final.nodejs-16_x; }); } diff --git a/scripts/localstack_up.sh b/scripts/localstack_up.sh new file mode 100644 index 000000000..2b2da6079 --- /dev/null +++ b/scripts/localstack_up.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Avoid localstack attempt to write in the nix store +XDG_DATA_HOME=''${XDG_DATA_HOME:-$HOME/.local/share} +export FILESYSTEM_ROOT=''${XDG_DATA_HOME}/localstack/filesystem + +# Since docker is installed outside of nix, need to ensure that it was +# installed impurely +if ! command -v docker > /dev/null; then + echo "Please install docker in order to use localstack" >&2 + exit 1 +fi + +if ! command -v localstack > /dev/null; then + echo "Please install localstack cli in order to use localstack" >&2 + exit 1 +fi + +# The 'localstack status' command will poll forever if you have a newer +# docker cli, so instead use docker ps + grep to determine running container +if ! docker ps | grep localstack &> /dev/null; then + echo "Starting localstack..." >&2 + localstack start \ + --detached \ + --docker \ + --no-banner > /dev/null +else + echo "localstack is already running, skipping localstack initialization" +fi + +# Explicitly exit this script so the parent shell can determine +# when it's safe to return control of terminal to user +exit 0