Skip to content

Commit ed31e6b

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 06cb51c + e913575 commit ed31e6b

File tree

9 files changed

+475
-11
lines changed

9 files changed

+475
-11
lines changed

2configs/consul.nix

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# interface.bind = "retiolum";
1313
extraConfig = {
1414
bind_addr = config.krebs.build.host.nets.retiolum.ip4.addr;
15-
bootstrap_expect = 1;
15+
bootstrap_expect = 3;
1616
server = true;
1717
# retry_join = config.services.consul.extraConfig.start_join;
1818
retry_join = lib.mapAttrsToList (_n: h: lib.head h.nets.retiolum.aliases) (
@@ -29,16 +29,20 @@
2929
cleanup_dead_servers = true;
3030
# How long a server must be stable before promoting
3131
server_stabilization_time = "10s";
32-
# Only requires 3 servers minimum instead of all configured servers
33-
min_quorum = 3;
32+
# Allow cluster to operate with 2 of 3 nodes (majority quorum)
33+
min_quorum = 2;
3434
};
3535

36-
# Performance tuning for faster leader elections
36+
# Performance tuning - slightly relaxed for network tolerance
3737
performance = {
38-
# Reduce raft timing for faster recovery
39-
raft_multiplier = 1;
38+
# 2 = default, gives more time for slow/unstable networks
39+
# 1 was too aggressive and caused leader flapping
40+
raft_multiplier = 2;
4041
};
4142

43+
# Reconnect timeout for failed nodes (default 72h, reduce for faster cleanup)
44+
reconnect_timeout = "24h";
45+
4246
# Leave on terminate for cleaner shutdowns
4347
leave_on_terminate = true;
4448
};
@@ -48,9 +52,6 @@
4852
systemd.services.consul = {
4953
# Add pre-start script to clean up potential issues
5054
preStart = ''
51-
# Remove any stale peers.json from failed recovery attempts
52-
rm -f /var/lib/consul/raft/peers.json
53-
5455
# Ensure proper permissions
5556
chown -R consul:consul /var/lib/consul
5657
'';

2configs/paste.nix

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
self.inputs.stockholm.nixosModules.htgen
1212
];
1313

14-
security.acme.certs."cyberlocker".server = config.krebs.ssl.acmeURL;
15-
security.acme.certs."paste".server = config.krebs.ssl.acmeURL;
1614
services.nginx.virtualHosts.cyberlocker = {
1715
enableACME = true;
1816
addSSL = true;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
lib,
3+
fetchFromGitHub,
4+
swift,
5+
swiftpm,
6+
swiftPackages,
7+
}:
8+
9+
swiftPackages.stdenv.mkDerivation {
10+
pname = "system-audio-dump";
11+
version = "0-unstable-2025-09-02";
12+
13+
src = fetchFromGitHub {
14+
owner = "sohzm";
15+
repo = "systemAudioDump";
16+
rev = "19caa4f6c0661c03a10d1f08c79a11f0b00f251a";
17+
hash = "sha256-H2TeB7/Meq7EvfW7zLZn5GGFrKwCyZuJvafv61ZWdrA=";
18+
};
19+
20+
nativeBuildInputs = [
21+
swift
22+
swiftpm
23+
];
24+
25+
postPatch = ''
26+
# Downgrade swift-tools-version from 6.0 to 5.10 and macOS from v15 to v14
27+
sed -i 's/swift-tools-version:6.0/swift-tools-version:5.10/' Package.swift
28+
sed -i 's/.macOS(.v15)/.macOS(.v14)/' Package.swift
29+
30+
# Patch Swift 6 / macOS 15 features in source
31+
# Remove @retroactive attribute (Swift 6 feature for silencing conformance warnings)
32+
sed -i 's/@retroactive //' Sources/SystemAudioDump/main.swift
33+
# Remove captureMicrophone (macOS 15+ only, defaults to false anyway)
34+
sed -i '/captureMicrophone/d' Sources/SystemAudioDump/main.swift
35+
'';
36+
37+
buildPhase = ''
38+
runHook preBuild
39+
swift build -c release
40+
runHook postBuild
41+
'';
42+
43+
installPhase = ''
44+
runHook preInstall
45+
mkdir -p $out/bin
46+
cp .build/release/SystemAudioDump $out/bin/system-audio-dump
47+
runHook postInstall
48+
'';
49+
50+
meta = {
51+
description = "macOS CLI that captures system audio and outputs raw PCM to stdout";
52+
homepage = "https://github.com/sohzm/systemAudioDump";
53+
license = lib.licenses.mit;
54+
platforms = lib.platforms.darwin;
55+
mainProgram = "system-audio-dump";
56+
};
57+
}

5pkgs/vosk/package.nix

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
lib,
3+
python3Packages,
4+
fetchurl,
5+
stdenv,
6+
}:
7+
let
8+
version = "0.3.44";
9+
10+
# Platform-specific wheels
11+
wheels = {
12+
"x86_64-linux" = {
13+
url = "https://files.pythonhosted.org/packages/py3/v/vosk/vosk-${version}-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl";
14+
hash = "sha256-JlLvITxMeAfcQK8eeqV43Mz8TcQZKCKia8RalZG8v3Y=";
15+
};
16+
"aarch64-linux" = {
17+
url = "https://files.pythonhosted.org/packages/py3/v/vosk/vosk-${version}-py3-none-manylinux2014_aarch64.whl";
18+
hash = "sha256-mZW3+lQ0sTS0vQmJfiSQ28VhFcKtKUPAMGIeEMcDezQ=";
19+
};
20+
"x86_64-darwin" = {
21+
url = "https://files.pythonhosted.org/packages/py3/v/vosk/vosk-${version}-py3-none-macosx_10_6_universal2.whl";
22+
hash = "sha256-Ap0LPWpc/4dMV1uKWBSkzM+zdgjP9S6EbAKoxnqIKAE=";
23+
};
24+
"aarch64-darwin" = {
25+
url = "https://files.pythonhosted.org/packages/py3/v/vosk/vosk-${version}-py3-none-macosx_10_6_universal2.whl";
26+
hash = "sha256-Ap0LPWpc/4dMV1uKWBSkzM+zdgjP9S6EbAKoxnqIKAE=";
27+
};
28+
};
29+
30+
wheel =
31+
wheels.${stdenv.hostPlatform.system}
32+
or (throw "Unsupported platform: ${stdenv.hostPlatform.system}");
33+
in
34+
python3Packages.buildPythonPackage {
35+
pname = "vosk";
36+
inherit version;
37+
format = "wheel";
38+
39+
src = fetchurl {
40+
inherit (wheel) url hash;
41+
};
42+
43+
dependencies = with python3Packages; [
44+
cffi
45+
requests
46+
tqdm
47+
srt
48+
websockets
49+
];
50+
51+
# Skip tests as they require audio files and models
52+
doCheck = false;
53+
54+
pythonImportsCheck = [ "vosk" ];
55+
56+
meta = {
57+
description = "Offline speech recognition API based on Kaldi and Vosk";
58+
homepage = "https://alphacephei.com/vosk/";
59+
license = lib.licenses.asl20;
60+
platforms = lib.attrNames wheels;
61+
};
62+
}

machines/shodan/physical.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
self.inputs.nixos-hardware.nixosModules.lenovo-thinkpad-x220
77
];
88

9+
# Disable hdapsd - not needed for SSD, and the package is broken with newer GCC
10+
services.hdapsd.enable = false;
11+
912
boot.loader.grub = {
1013
enable = true;
1114
device = "/dev/disk/by-id/ata-Samsung_SSD_850_EVO_500GB_S2RBNX0H662201F";

tools/record/flake-module.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{ ... }:
2+
{
3+
perSystem =
4+
{ pkgs, self', ... }:
5+
{
6+
packages.record = pkgs.writeShellApplication {
7+
name = "record";
8+
runtimeInputs = [
9+
pkgs.ffmpeg
10+
pkgs.gum
11+
]
12+
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.pulseaudio ]
13+
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [ self'.packages.system-audio-dump ];
14+
text = builtins.readFile ./rec.sh;
15+
};
16+
};
17+
}

tools/record/rec.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
list_sources() {
5+
if [[ "$OSTYPE" == "darwin"* ]]; then
6+
# macOS: list audio devices via ffmpeg avfoundation
7+
echo "system: System Audio (via ScreenCaptureKit)"
8+
ffmpeg -f avfoundation -list_devices true -i "" 2>&1 | \
9+
sed -n '/AVFoundation audio devices:/,/^[^[]/p' | \
10+
grep -E '^\[AVFoundation.*\[[0-9]+\]' | \
11+
sed 's/.*\[\([0-9]*\)\] \(.*\)/\1: \2/'
12+
else
13+
# Linux: list PulseAudio/PipeWire sources including monitors (for system audio)
14+
# Sources ending in .monitor capture the output of that sink (system audio)
15+
pactl list sources short | awk '{print $2}' | while read -r source; do
16+
if [[ "$source" == *.monitor ]]; then
17+
echo "$source (system audio)"
18+
else
19+
echo "$source"
20+
fi
21+
done
22+
fi
23+
}
24+
25+
get_source_name() {
26+
# Strip the description suffix for actual recording
27+
local name="$1"
28+
echo "${name% (system audio)}"
29+
}
30+
31+
record_source() {
32+
local source="$1"
33+
34+
if [[ "$OSTYPE" == "darwin"* ]]; then
35+
if [[ "$source" == "system" ]]; then
36+
# Use system-audio-dump for system audio (ScreenCaptureKit)
37+
# Output is raw PCM 24kHz 16-bit stereo, convert to WAV for compatibility
38+
system-audio-dump | ffmpeg -f s16le -ar 24000 -ac 2 -i - -f wav -acodec pcm_s16le - 2>/dev/null
39+
else
40+
# Use avfoundation for mic input, source is the device index
41+
ffmpeg -f avfoundation -i ":${source}" -f wav -acodec pcm_s16le - 2>/dev/null
42+
fi
43+
else
44+
# Linux: use pulse
45+
ffmpeg -f pulse -i "$source" -f wav -acodec pcm_s16le - 2>/dev/null
46+
fi
47+
}
48+
49+
# Show help
50+
if [[ "${1:-}" == "-h" ]] || [[ "${1:-}" == "--help" ]]; then
51+
echo "Usage: record [SOURCE]"
52+
echo ""
53+
echo "Record audio from a source and output WAV to stdout."
54+
echo "If no source is provided, prompts interactively with gum."
55+
echo ""
56+
echo "Options:"
57+
echo " -l, --list List available audio sources"
58+
echo " -h, --help Show this help"
59+
echo ""
60+
echo "System audio:"
61+
echo " Linux: Select a .monitor source (captures sink output)"
62+
echo " macOS: Use 'system' source (requires Screen Recording permission)"
63+
echo ""
64+
echo "Examples:"
65+
echo " record | mpv -"
66+
echo " record system | mpv - # macOS system audio"
67+
echo " record 0 | mpv - # macOS device index"
68+
echo " record alsa_output.pci-xxx.monitor | mpv - # Linux system audio"
69+
exit 0
70+
fi
71+
72+
# List sources
73+
if [[ "${1:-}" == "-l" ]] || [[ "${1:-}" == "--list" ]]; then
74+
list_sources
75+
exit 0
76+
fi
77+
78+
# Get source from argument or prompt
79+
if [[ -n "${1:-}" ]]; then
80+
SOURCE="$1"
81+
else
82+
# Use gum to select a source
83+
if [[ "$OSTYPE" == "darwin"* ]]; then
84+
SOURCE=$(list_sources | gum choose --header "Select audio source:" | cut -d: -f1)
85+
else
86+
SELECTION=$(list_sources | gum choose --header "Select audio source:")
87+
SOURCE=$(get_source_name "$SELECTION")
88+
fi
89+
fi
90+
91+
if [[ -z "$SOURCE" ]]; then
92+
echo "Error: No source selected" >&2
93+
exit 1
94+
fi
95+
96+
echo "Recording from: $SOURCE (Ctrl+C to stop)" >&2
97+
record_source "$SOURCE"

tools/stt/flake-module.nix

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{ ... }:
2+
{
3+
perSystem =
4+
{ pkgs, self', ... }:
5+
let
6+
python = pkgs.python3.withPackages (_ps: [
7+
self'.packages.vosk
8+
]);
9+
in
10+
{
11+
packages.stt = pkgs.stdenv.mkDerivation {
12+
pname = "stt";
13+
version = "0.4.0";
14+
src = ./.;
15+
nativeBuildInputs = [ pkgs.makeWrapper ];
16+
installPhase = ''
17+
runHook preInstall
18+
mkdir -p $out/bin
19+
cp stt.py $out/bin/stt
20+
chmod +x $out/bin/stt
21+
wrapProgram $out/bin/stt \
22+
--prefix PATH : ${python}/bin \
23+
--set PYTHONPATH ${python}/${python.sitePackages}
24+
runHook postInstall
25+
'';
26+
meta.mainProgram = "stt";
27+
};
28+
};
29+
}

0 commit comments

Comments
 (0)