Skip to content

Instantly share code, notes, and snippets.

@trevorbernard
Created June 12, 2025 16:56
Show Gist options
  • Save trevorbernard/7ee5a62b2dcba7f6cfe2eff43ac63493 to your computer and use it in GitHub Desktop.
Save trevorbernard/7ee5a62b2dcba7f6cfe2eff43ac63493 to your computer and use it in GitHub Desktop.
{
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2411.716632";
outputs =
{
self,
nixpkgs,
}:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forEachSupportedSystem =
f:
nixpkgs.lib.genAttrs supportedSystems (
system:
f {
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
}
);
in
{
overlays.default =
final: prev:
let
# Use an older glibc version compatible with AWS Lambda
olderGlibc = prev.glibc.overrideAttrs (oldAttrs: {
version = "2.34";
src = prev.fetchurl {
url = "mirror://gnu/glibc/glibc-2.34.tar.xz";
sha256 = "sha256-HZAaKCU1LPvmBWgqQMdJkzw33r3lnYgzHqL3VHfI3VY=";
};
});
# Override stdenv to use the older glibc
lambdaStdenv = final.overrideCC final.stdenv (
final.gcc.override {
libc = olderGlibc;
}
);
python = final.python312.override {
stdenv = lambdaStdenv;
};
pythonPackages = python.pkgs;
developmentPackages = with pythonPackages; [
ruff
];
packages = with pythonPackages; [
boto3
pg8000
openai
];
in
{
pythonEnv = final.python312.withPackages (ps: developmentPackages ++ packages);
pythonLambdaEnv = python.withPackages (ps: packages);
};
checks = forEachSupportedSystem (
{ pkgs }:
{
lint = pkgs.runCommand "lint" { } ''
export RUFF_CACHE_DIR=$(mktemp -d)
cd ${self}
${pkgs.pythonEnv}/bin/ruff check .
touch $out
'';
}
);
packages = forEachSupportedSystem (
{ pkgs }:
{
default = pkgs.stdenvNoCC.mkDerivation {
name = "callsim-reports-lambda";
src = ./.;
buildInputs = with pkgs; [
rsync
zip
];
buildPhase = ''
mkdir -p lambda
rsync -av \
--include='*/' \
--include='*.py' \
--exclude='*/tests/' \
--exclude='*' \
${self}/ lambda/
rsync -av ${pkgs.pythonLambdaEnv}/lib/python3.12/site-packages/ lambda/
mkdir -p $out/dist
(cd lambda && zip -r $out/dist/lambda.zip . \
-x '**/__pycache__/*' '**/*.pyc')
'';
};
}
);
devShells = forEachSupportedSystem (
{ pkgs }:
{
default = pkgs.mkShell {
buildInputs = with pkgs; [
aws-sam-cli
awscli2
direnv
git
nix-direnv
pythonEnv
python312Packages.python-lsp-server
zip
unzip
rsync
];
shellHook = ''
echo "python --version"
echo "pip --version"
'';
};
}
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment