b5e34360a7
- Initially tested on Raspberry Pi 4B & Raspberry Pi 3B - Create user + password, enable SSH, connect to local network - Implemented modules: audio-recorder, gps-recorder, real-time-clock, shutdown-button - Deployment option with deploy-rs Signed-off-by: Satu Koskinen <satu.a.koskinen@gmail.com>
71 lines
2.2 KiB
Nix
71 lines
2.2 KiB
Nix
{
|
|
config,
|
|
pkgs,
|
|
lib,
|
|
...
|
|
}: {
|
|
options = with lib; {
|
|
services.audio-recorder = {
|
|
enable = mkEnableOption "Whether to enable the audio recording service.";
|
|
|
|
output-folder = mkOption {
|
|
type = types.str;
|
|
default = "/output/audio";
|
|
description = "The folder to save recordings to.";
|
|
};
|
|
|
|
sample-rate = mkOption {
|
|
type = types.int;
|
|
default = 44100;
|
|
description = "The sample rate to use for recording.";
|
|
};
|
|
|
|
sample-format = mkOption {
|
|
type = types.str;
|
|
default = "S32_LE";
|
|
description = "The sample format to use for recording.";
|
|
};
|
|
|
|
channels = mkOption {
|
|
type = types.int;
|
|
default = 2;
|
|
description = "The amount of channels to use.";
|
|
};
|
|
|
|
max-file-time-secs = mkOption {
|
|
type = types.int;
|
|
default = 600;
|
|
description = "The maximum length of a recording in seconds.";
|
|
};
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf config.services.audio-recorder.enable {
|
|
systemd.services.audio-recorder = {
|
|
description = "Audio Recording Service";
|
|
wantedBy = ["multi-user.target"];
|
|
script = ''
|
|
#!/usr/bin/env bash
|
|
set -x
|
|
${pkgs.coreutils}/bin/mkdir -p ${config.services.audio-recorder.output-folder}
|
|
${pkgs.alsaUtils}/bin/arecord -l
|
|
CARD_ID=$(${pkgs.alsaUtils}/bin/arecord -l | grep "USB Audio" | grep -oP '(?<=card )\d')
|
|
DEVICE_ID=$(${pkgs.alsaUtils}/bin/arecord -l | grep "USB Audio" | grep -oP '(?<=device )\d')
|
|
${pkgs.alsaUtils}/bin/arecord \
|
|
--device hw:$CARD_ID,$DEVICE_ID \
|
|
--format ${config.services.audio-recorder.sample-format} \
|
|
--max-file-time ${toString config.services.audio-recorder.max-file-time-secs} \
|
|
--rate ${toString config.services.audio-recorder.sample-rate} \
|
|
--channels ${toString config.services.audio-recorder.channels} \
|
|
--use-strftime \
|
|
${config.services.audio-recorder.output-folder}/%Y-%m-%d_%H-%M-%S.wav
|
|
'';
|
|
serviceConfig = {
|
|
User = "root"; # Replace with appropriate user
|
|
Restart = "always";
|
|
};
|
|
startLimitIntervalSec = 0;
|
|
};
|
|
};
|
|
}
|