74 lines
1.7 KiB
Nix
74 lines
1.7 KiB
Nix
{
|
|
description = "minimal flake for go dev";
|
|
|
|
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1";
|
|
|
|
outputs =
|
|
inputs:
|
|
let
|
|
goVersion = 26;
|
|
|
|
supportedSystems = [
|
|
"x86_64-linux"
|
|
"aarch64-linux"
|
|
"x86_64-darwin"
|
|
"aarch64-darwin"
|
|
];
|
|
|
|
forEachSupportedSystem =
|
|
f:
|
|
inputs.nixpkgs.lib.genAttrs supportedSystems (
|
|
system:
|
|
f {
|
|
pkgs = import inputs.nixpkgs {
|
|
inherit system;
|
|
overlays = [ inputs.self.overlays.default ];
|
|
};
|
|
}
|
|
);
|
|
in
|
|
{
|
|
overlays.default = final: prev: {
|
|
go = final."go_1_${toString goVersion}";
|
|
};
|
|
|
|
devShells = forEachSupportedSystem (
|
|
{ pkgs }:
|
|
{
|
|
default = pkgs.mkShell {
|
|
packages = with pkgs; [
|
|
go
|
|
sqlc
|
|
goose
|
|
postgresql
|
|
|
|
(pkgs.writeShellScriptBin "pg-start" ''
|
|
export PGDATA=${"$PWD"}/.pgdata
|
|
export PGHOST=${"$PWD"}/.pgsocket
|
|
|
|
mkdir -p "$PGDATA"
|
|
mkdir -p "$PGHOST"
|
|
|
|
if [ ! -f "$PGDATA/PG_VERSION" ]; then
|
|
echo "Initializing database..."
|
|
initdb -D "$PGDATA"
|
|
fi
|
|
|
|
echo "Starting postgres..."
|
|
pg_ctl -D "$PGDATA" -l logfile -o "-k $PGHOST" start
|
|
'')
|
|
|
|
(pkgs.writeShellScriptBin "pg-stop" ''
|
|
export PGDATA=${"$PWD"}/.pgdata
|
|
pg_ctl -D "$PGDATA" stop
|
|
'')
|
|
];
|
|
|
|
shellHook = ''
|
|
export PGDATA=$PWD/.pgdata
|
|
'';
|
|
};
|
|
}
|
|
);
|
|
};
|
|
}
|