Skip to content

Commit fb3999a

Browse files
committed
feat(release): additional q files and infra
1 parent 49b50f8 commit fb3999a

15 files changed

+894
-0
lines changed

.editorconfig

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# All files
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_size = 2
9+
indent_style = space
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
# Solidity
14+
# https://github.com/sambacha/prettier-config-solidity
15+
[*.sol]
16+
indent_size = 4
17+
indent_style = space
18+
19+
# q
20+
# kdb+
21+
[*.q]
22+
indent_style = space
23+
indent_size = 2
24+
end_of_line = lf
25+
charset = utf-8
26+
trim_trailing_whitespace = true
27+
insert_final_newline = true
28+
29+
# Markdown
30+
[*.{md,adoc,asciidoc}]
31+
charset = utf-8
32+
end_of_line = lf
33+
insert_final_newline = true
34+
trim_trailing_whitespace = false
35+
36+
# Match nix files, set indent to spaces with width of two
37+
[*.nix]
38+
indent_style = space
39+
indent_size = 2
40+
41+
# JavaScript, JSON, JSX, JavaScript Modules, TypeScript
42+
# https://github.com/feross/standard
43+
# https://prettier.io
44+
[*.{cjs,js,json,jsx,mjs,ts,tsx,mts,cts}]
45+
indent_size = 2
46+
indent_style = space
47+
48+
# TOML
49+
# https://github.com/toml-lang/toml/tree/master/examples
50+
[*.toml]
51+
indent_size = 2
52+
indent_style = space
53+
54+
# YAML
55+
# http://yaml.org/spec/1.2/2009-07-21/spec.html#id2576668
56+
[*.{yaml,yml}]
57+
indent_size = 2
58+
indent_style = space
59+
60+
# Shell
61+
# https://google.github.io/styleguide/shell.xml#Indentation
62+
[*.{bash,sh,zsh}]
63+
indent_size = 2
64+
indent_style = space
65+
66+
# confg + cfg
67+
[*.{conf,cfg}]
68+
charset = UTF-8
69+
end_of_line = LF
70+
indent_size = 4
71+
indent_style = tab
72+
insert_final_newline = true
73+
tab_width = 4
74+
trim_trailing_whitespace = true
75+
76+
# Match diffs, avoid to trim trailing whitespace
77+
[*.{diff,patch}]
78+
trim_trailing_whitespace = false
79+
80+
# Ignore fixtures and vendored files
81+
[{dist,artifacts,vendor,test/fixtures,tests_config,__snapshot__,}/**]
82+
charset = unset
83+
end_of_line = unset
84+
indent_size = unset
85+
indent_style = unset
86+
insert_final_newline = unset
87+
trim_trailing_spaces = unset

.github/update.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
echo "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" > "hash"
5+
6+
# try (and fail) building, to get SRI hash of cargo deps
7+
(set +e; nix build |& tee out)
8+
9+
# parse output, get hash, save
10+
awk '/got: / {print $2}' out > "hash"
11+
12+
function clean() { rm -rf out; }
13+
trap clean EXIT

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- mode: gitignore; -*-
2+
/out
3+
.DS_Store
4+
.secret
5+
.idea/*
6+
7+
logs
8+
*.log
9+
.\#*
10+
**/.terraform/*
11+
12+
# .tfstate files
13+
*.tfstate
14+
*.tfstate.*
15+
*.tfvars
16+
*.tfvars.json
17+
*.ssh
18+
*.key
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
From 1b9d3667a90358c5d008321818c3e219cc7e30a7 Mon Sep 17 00:00:00 2001
2+
From: Sam Bacha <[email protected]>
3+
Date: Sun, 6 Jun 2021 08:25:06 +0200
4+
Subject: [PATCH] Makefile: don't download k.h from github master branch during
5+
build
6+
7+
We provide this after cloning the repo
8+
---
9+
Makefile | 6 ++----
10+
1 file changed, 2 insertions(+), 4 deletions(-)
11+
12+
diff --git a/Makefile b/Makefile
13+
index 5af64c9..f6a652f 100644
14+
--- a/Makefile
15+
+++ b/Makefile
16+
@@ -28,12 +28,10 @@ endif
17+
QARCH = $(OSFLAG)$(MS)
18+
Q = $(QHOME)/$(QARCH)
19+
20+
-all: k.h
21+
+all:
22+
$(CC) kfk.c -m$(MS) $(OPTS) $(LDOPTS_DYNAMIC) $(LD_COMMON) -I$(KFK_INCLUDE) $(LNK) -o $(TGT) $(OSXOPTS)
23+
-static: k.h
24+
+static:
25+
$(CC) kfk.c -m$(MS) $(OPTS) $(LDOPTS_STATIC) $(LD_COMMON) -I$(KFK_INCLUDE) $(LNK) -o $(TGT) $(OSXOPTS)
26+
-k.h:
27+
- curl -s -O -L https://github.com/KxSystems/kdb/raw/master/c/c/k.h
28+
install:
29+
install $(TGT) $(Q)
30+
clean:
31+
--
32+
2.31.1
33+

kfk/default.nix

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{ stdenv, fetchFromGitHub, rdkafka, zlib, openssl, ... }:
2+
3+
let
4+
version = "1.5.0";
5+
kdbSrc = fetchFromGitHub {
6+
owner = "KxSystems";
7+
repo = "kdb";
8+
rev = "39b957030bf6a4608f2508ff29894d7fac32a0c2";
9+
sha256 = "0r0yfnfn2g89hc7gvk2y1d568lkda0463jw3ha1gg8h83v1vm63f";
10+
};
11+
in
12+
stdenv.mkDerivation {
13+
inherit version;
14+
name = "kfk-${version}";
15+
16+
src = fetchFromGitHub {
17+
owner = "KxSystems";
18+
repo = "kafka";
19+
rev = "v${version}";
20+
sha256 = "1yi9f8gy3nv5hncd0qh9q2lzk315pavf3bkc5wq48ki0yxllhaqf";
21+
};
22+
23+
# The Makefile downloaded k.h from kdb repo, master branch.
24+
# Patch this out, and copy it into $src after unpack.
25+
patches = [ ./0001-Makefile-don-t-download-k.h-from-github-master-branc.patch ];
26+
27+
preConfigure = ''
28+
cp ${kdbSrc}/c/c/k.h .
29+
'';
30+
31+
#NIX_CFLAGS_COMPILE = "-I.";
32+
NIX_CFLAGS_LINK = "-L${zlib.out}/lib -L${openssl.out}/lib";
33+
34+
makeFlags = [
35+
"KAFKA_ROOT=${rdkafka}"
36+
];
37+
38+
# override install phase, cause their `make install` is bonkers, and we only
39+
# really care about libkfk.so anyways.
40+
installPhase = ''
41+
install -Dm644 kfk.q $out/q/kfk.q
42+
install -Dm644 libkfk.so $out/q/l64/libkfk.so
43+
strip $out/q/l64/*.so
44+
'';
45+
46+
meta = {
47+
description = "A thin wrapper for kdb+ around librdkafka C API for Kafka";
48+
};
49+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
From fff009102056d071c98f839ed8954d0386bb83eb Mon Sep 17 00:00:00 2001
2+
From: Sam Bacha <[email protected]>
3+
Date: Thu, 20 Jan 2022 12:08:01 +0100
4+
Subject: [PATCH] log4q: use logfmt format
5+
6+
---
7+
log4q.q | 2 +-
8+
1 file changed, 1 insertion(+), 1 deletion(-)
9+
10+
diff --git a/log4q.q b/log4q.q
11+
index 87f601a..67be65c 100644
12+
--- a/log4q.q
13+
+++ b/log4q.q
14+
@@ -1,5 +1,5 @@
15+
\d .log4q
16+
-fm:"%c\t[%p]:H=%h:PID[%i]:%d:%t:%f: %m\r\n";
17+
+fm:"level=%c file=%f host=%h pid=%i %m\n";
18+
sev:snk:`SILENT`DEBUG`INFO`WARN`ERROR`FATAL!();a:{$[1<count x;[h[x 0]::x 1;snk[y],::x 0];[h[x]::{x@y};snk[y],::x;]];};r:{snk::@[snk;y;except;x];};
19+
h:m:()!();m["c"]:{[x;y]string x};m["f"]:{[x;y]string .z.f};m["p"]:{[x;y]string .z.p};m["P"]:{[x;y]string .z.P};m["m"]:{[x;y]y};m["h"]:{[x;y]string .z.h};m["i"]:{[x;y]string .z.i};m["d"]:{[x;y]string .z.d};m["D"]:{[x;y]string .z.D};m["t"]:{[x;y]string .z.t};m["T"]:{[x;y]string .z.T};
20+
l:{ssr/[fm;"%",/:lfm;m[lfm:raze -1_/:2_/:nl where fm like/: nl:"*%",/:(.Q.a,.Q.A),\:"*"].\:(x;y)]};
21+
--
22+
2.34.1
23+

log4q/default.nix

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ stdenv, fetchFromGitHub }:
2+
stdenv.mkDerivation {
3+
pname = "log4q";
4+
version = "0.0.0+unstable";
5+
6+
src = fetchFromGitHub {
7+
owner = "prodrive11";
8+
repo = "log4q";
9+
rev = "932f33bfeab3f1faa60aac187d23bacc9bf1bd9e";
10+
sha256 = "sha256-Zr/GSicHerr1KGMUBvFlZSkR/HTBgVOp0BjEMYR5seI=";
11+
};
12+
13+
patches = [ ./0001-log4q-use-logfmt-format.patch ];
14+
15+
installPhase = ''
16+
install -D log4q.q $out/q/log4q.q
17+
'';
18+
}

main.nix

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{ system ? builtins.currentSystem
2+
, nixpkgs ? import ./nixpkgs.nix { inherit system; }
3+
}:
4+
let
5+
sources = import ./sources.nix;
6+
devshell = import sources.devshell { pkgs = nixpkgs; };
7+
tf = nixpkgs.terraform.withPlugins (p: [
8+
p.aws
9+
p.cloudflare
10+
p.external
11+
p.grafana
12+
(nixpkgs.callPackage ./pkgs/terraform-provider-htpasswd { })
13+
p.helm
14+
p.http
15+
p.kafka
16+
p.kubernetes
17+
p.local
18+
p.null
19+
p.random
20+
p.secret
21+
p.template
22+
p.tls
23+
]);
24+
25+
26+
# Q third-party libs
27+
kfk = nixpkgs.callPackage ./pkgs/kfk { }; # "kafka-kdb"
28+
log4q = nixpkgs.callPackage ./pkgs/log4q { };
29+
protobufkdb = nixpkgs.callPackage ./pkgs/protobufkdb { };
30+
qAbiEncode = nixpkgs.callPackage ./pkgs/qAbiEncode { };
31+
qbigint = nixpkgs.callPackage ./pkgs/qbigint { };
32+
qquartic = nixpkgs.callPackage ./pkgs/qquartic { };
33+
qunit = nixpkgs.callPackage ./pkgs/qunit { };
34+
qwebapi = nixpkgs.callPackage ./pkgs/qwebapi { };
35+
# Bundle them all into one big package
36+
qVendorLibs = nixpkgs.symlinkJoin {
37+
name = "q-libs";
38+
paths = [
39+
kfk
40+
log4q
41+
protobufkdb
42+
qAbiEncode
43+
qbigint
44+
qquartic
45+
qunit
46+
qwebapi
47+
];
48+
};
49+
50+
q = nixpkgs.callPackage ./pkgs/q {
51+
# Make those part of the base binary
52+
qLibs = qVendorLibs;
53+
};
54+
55+
# kdb source
56+
kdbLibs = nixpkgs.symlinkJoin {
57+
name = "kdb-libs";
58+
paths = [
59+
# Get the protobufs
60+
(nixpkgs.runCommandNoCC "manifold-protos-q" { } ''
61+
mkdir -p $out/q/proto
62+
cp ${manifoldProtos}/*.proto $out/q/proto
63+
'')
64+
# Get the rest of the source
65+
(nixpkgs.runCommandNoCC "manifold-q"
66+
{
67+
src = builtins.path {
68+
path = ../modules/kdb/src/main/q;
69+
filter = name: type:
70+
with nixpkgs.lib;
71+
if type == "directory" then
72+
# Avoid adding the old DB folder in there
73+
! hasSuffix "/db" name
74+
else # regular files
75+
# Only add .q and .sh files
76+
hasSuffix ".q" name || hasSuffix ".sh" name;
77+
};
78+
} ''
79+
mkdir $out
80+
cp -r $src $out/q
81+
chmod +w $out/q
82+
patchShebangs $out/q
83+
'')
84+
];
85+
};
86+
87+
kdb-container = nixpkgs.dockerTools.buildLayeredImage {
88+
name = "<% NAME %>";
89+
tag = "dev";
90+
contents = [
91+
nixpkgs.bashInteractive # for debugging
92+
nixpkgs.coreutils
93+
nixpkgs.gnused
94+
nixpkgs.dockerTools.fakeNss # otherwise q just outputs pwuid
95+
q
96+
kdbLibs
97+
];
98+
maxLayers = 15;
99+
config = {
100+
Cmd = [ "/q/start.sh" ];
101+
Env = [
102+
"QHOME=/q"
103+
"QDB=/qdb"
104+
];
105+
Volumes = {
106+
"/qdb" = { };
107+
};
108+
WorkingDir = "/";
109+
};
110+
extraCommands = ''
111+
# make sure /tmp exists
112+
mkdir -m 1777 tmp
113+
'';
114+
};
115+
116+
117+
packages = [
118+
# Used to invoke q scripts
119+
nixpkgs.rlwrap
120+
q
121+
122+
123+
commands = [
124+
{ name = "gradle"; category = "dev"; help = "gradle build system"; command = ''$PRJ_ROOT/gradlew "$@"''; }
125+
{ name = "j"; category = "dev"; help = "just a command runner"; command = ''${nixpkgs.just}/bin/just "$@"''; }
126+
{ category = "dev"; package = nixpkgs.yarn; }
127+
{ name = "tf"; category = "ops"; help = "terraform alias"; command = ''${tf}/bin/terraform "$@"''; }
128+
];
129+
};
130+
131+
132+
nixos-configs = (nixpkgs.lib.recurseIntoAttrs (import ../ops/nixos/configs { inherit (nixpkgs) lib nixos; }));
133+
}

0 commit comments

Comments
 (0)