Skip to content

Commit

Permalink
chore(nix): added SQLC package.
Browse files Browse the repository at this point in the history
This commit introduces several changes to modernize the project:

- Adds `tools/nix/pks/sqlc.nix` for SQLC package.
- Updates `cmd/quantm/queues.go` with new core and hooks queue setups.
- Updates `flake.nix` and `flake.lock` with `gomod2nix` and renamed `breu` input.
  • Loading branch information
debuggerpk committed Jan 19, 2025
1 parent 49b6b5e commit ee753ef
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 20 deletions.
2 changes: 1 addition & 1 deletion GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cp .env.example .env
Start the necessary services using Docker Compose. This inlcudes

- temporal-db: Postgres 16.x for required for temporal
- temporal: 1.25.x, it derives the main logic of the application
- temporal: 1.25.x, it drives the main logic of the application
- db: Postgres 16.x for the main database

```bash
Expand Down
11 changes: 11 additions & 0 deletions cmd/quantm/queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"go.breu.io/quantm/internal/pulse"
)

// q_core sets up the core queue.
func q_core() {
q := durable.OnCore()

Expand All @@ -17,38 +18,48 @@ func q_core() {
)

if q != nil {
// Register core activities
q.RegisterActivity(pulse.PersistRepoEvent)
q.RegisterActivity(pulse.PersistChatEvent)

// Register repo workflows and activities
q.RegisterWorkflow(repos.RepoWorkflow)
q.RegisterActivity(repos.NewRepoActivities())

// Register branch workflows and activities
q.RegisterWorkflow(repos.BranchWorkflow)
q.RegisterActivity(repos.NewBranchActivities())
}
}

// q_hooks sets up the hooks queue.
func q_hooks() {
q := durable.OnHooks()

q.CreateWorker()

if q != nil {
// Register pulse activities
q.RegisterActivity(pulse.PersistRepoEvent)
q.RegisterActivity(pulse.PersistChatEvent)

// Register github install workflow and activity
q.RegisterWorkflow(github.InstallWorkflow)
q.RegisterActivity(&github.InstallActivity{})

// Register github sync repos workflow and activity
q.RegisterWorkflow(github.SyncReposWorkflow)
q.RegisterActivity(&github.InstallReposActivity{})

// Register github push workflow and activity
q.RegisterWorkflow(github.PushWorkflow)
q.RegisterActivity(&github.PushActivity{})

// Register github ref workflow and activity
q.RegisterWorkflow(github.RefWorkflow)
q.RegisterActivity(&github.RefActivity{})

// Register github pull request workflow and activity
q.RegisterWorkflow(github.PullRequestWorkflow)
q.RegisterActivity(&github.PullRequestActivity{})
}
Expand Down
34 changes: 29 additions & 5 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 25 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,61 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
flake-utils.url = "github:numtide/flake-utils";
gomod2nix.url = "github:nix-community/gomod2nix";
gomod2nix.inputs.nixpkgs.follows = "nixpkgs";
gomod2nix.inputs.flake-utils.follows = "flake-utils";

breu-go.url = "github:breuhq/flake-go";
breu.url = "github:breuhq/flake-go";
};

outputs = {
nixpkgs,
breu-go,
flake-utils,
breu,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {inherit system;};
buildGoModule = pkgs.buildGo123Module;

# Apply the breu-go overlay
pkgs' = pkgs.extend (final: prev: breu-go.overlay.${system} final prev);
setup = breu.setup.${system};

# Add required dependencies to the base environment
base = pkgs'.setup.base [
# Base packages required for building and running quantm
base = setup.base [
pkgs.openssl
pkgs.http-parser
pkgs.zlib
pkgs.python3 # requird for http-parser
pkgs.python3 # required for http-parser in libgit2
pkgs.libgit2
];

# Set up the development shell with our base packages
shell = pkgs'.setup.shell base [] {};
# Development packages for use in the dev shell
dev = [
pkgs.libpg_query # FIXME: probably not required anymore.
(pkgs.callPackage ./tools/nix/pkgs/sqlc.nix {inherit buildGoModule;})
];

# Set up the development shell with our base and dev packages
shell = setup.shell base dev {};

# Build the quantm binary
quantm = pkgs.stdenv.mkDerivation {
name = "quantm";
version = "0.1.0"; # Adjust as needed
src = ./.; # Use the directory containing your Go code
src = ./.;

nativeBuildInputs = base;

buildPhase = ''
export GOROOT="${pkgs.go_1_23}/share/go"
go build -x -tags static,system_libgit2 -o $out/bin/quantm ./cmd/quantm
export GOROOT=${pkgs.go_1_23}/share/go
export GOCACHE="$TEMPDIR/go-cache"
export GOMODCACHE="$TEMPDIR/go-mod-cache"
go build -x -tags static,system_libgit2 -o ./tmp/quantm ./cmd/quantm
'';

installPhase = ''
mkdir -p $out/bin
cp $out/bin/quantm $out/bin/quantm
cp ./tmp/quantm $out/bin/quantm
'';
};
in {
Expand Down
45 changes: 45 additions & 0 deletions tools/nix/pkgs/sqlc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
lib,
stdenv,
buildGoModule,
fetchFromGitHub,
installShellFiles,
}:
buildGoModule rec {
pname = "sqlc";
version = "1.27.0";

src = fetchFromGitHub {
owner = "sqlc-dev";
repo = "sqlc";
rev = "v${version}";
hash = "sha256-wxQ+YPsDX0Z6B8whlQ/IaT2dRqapPL8kOuFEc6As1rU=";
};

proxyVendor = true;
vendorHash = "sha256-ndOw3uShF5TngpxYNumoK3H3R9v4crfi5V3ZCoSqW90=";

subPackages = ["cmd/sqlc"];

nativeBuildInputs = [installShellFiles];

ldflags = [
"-s"
"-w"
];

postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installShellCompletion --cmd sqlc \
--bash <($out/bin/sqlc completion bash) \
--fish <($out/bin/sqlc completion fish) \
--zsh <($out/bin/sqlc completion zsh)
'';

meta = {
description = "Generate type-safe code from SQL";
homepage = "https://sqlc.dev/";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [aaronjheng];
mainProgram = "sqlc";
};
}

0 comments on commit ee753ef

Please sign in to comment.