move musicutil to flake :3

This commit is contained in:
ChaotiCryptidz 2022-02-08 11:30:06 +00:00
parent e40a1e553f
commit 435d7311d2
12 changed files with 595 additions and 41 deletions

View file

@ -0,0 +1,232 @@
diff --git a/src/control/control.c b/src/control/control.c
index d66ed75..42cecad 100644
--- a/src/control/control.c
+++ b/src/control/control.c
@@ -838,6 +838,10 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
#ifndef PIC
extern void *snd_control_open_symbols(void);
#endif
+
+ snd_config_t *libs = NULL;
+ const char *libs_lib = NULL;
+
if (snd_config_get_type(ctl_conf) != SND_CONFIG_TYPE_COMPOUND) {
if (name)
SNDERR("Invalid type for CTL %s definition", name);
@@ -879,6 +883,19 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
SNDERR("Invalid type for %s", id);
goto _err;
}
+
+ continue;
+ }
+ // Handle an array of extra libs.
+ if (strcmp(id, "libs") == 0) {
+ if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
+ SNDERR("Invalid type for libs definition in CTL %s definition",
+ str);
+ goto _err;
+ }
+
+ libs = n;
+
continue;
}
if (strcmp(id, "open") == 0) {
@@ -903,7 +920,62 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
open_name = buf;
sprintf(buf, "_snd_ctl_%s_open", str);
}
- if (!lib) {
+
+#ifndef PIC
+ snd_control_open_symbols();
+#endif
+
+ // Normal alsa behaviour when there is no libs array.
+ if (!libs) {
+ if (lib) {
+ open_func = snd_dlobj_cache_get(lib, open_name,
+ SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 1);
+ }
+ }
+ // Handle libs array.
+ // Suppresses error messages if any function is loaded successfully.
+ else {
+ if (lib) {
+ open_func = snd_dlobj_cache_get(lib, open_name,
+ SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 0);
+ }
+
+ if (!open_func) {
+ snd_config_for_each(i, next, libs) {
+ snd_config_t *n = snd_config_iterator_entry(i);
+
+ err = snd_config_get_string(n, &libs_lib);
+ if (err < 0) {
+ SNDERR("Invalid entry in CTL %s libs definition", str);
+ goto _err;
+ }
+
+ if (!open_func) {
+ open_func = snd_dlobj_cache_get(libs_lib, open_name,
+ SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 0);
+ }
+ }
+ }
+
+ // Print error messages.
+ if (!open_func) {
+ if (lib) {
+ SNDERR("Either %s cannot be opened or %s was not defined inside",
+ lib, open_name);
+ }
+
+ snd_config_for_each(i, next, libs) {
+ snd_config_t *n = snd_config_iterator_entry(i);
+
+ snd_config_get_string(n, &libs_lib);
+ SNDERR("Either %s cannot be opened or %s was not defined inside",
+ libs_lib, open_name);
+ }
+ }
+ }
+
+ // Look in ALSA_PLUGIN_DIR iff we found nowhere else to look.
+ if (!lib && (!libs || !libs_lib)) {
const char *const *build_in = build_in_ctls;
while (*build_in) {
if (!strcmp(*build_in, str))
@@ -919,12 +991,11 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
lib = buf1;
sprintf(buf1, "%s/libasound_module_ctl_%s.so", ALSA_PLUGIN_DIR, str);
}
- }
-#ifndef PIC
- snd_control_open_symbols();
-#endif
- open_func = snd_dlobj_cache_get(lib, open_name,
+
+ open_func = snd_dlobj_cache_get(lib, open_name,
SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 1);
+ }
+
if (open_func) {
err = open_func(ctlp, name, ctl_root, ctl_conf, mode);
if (err >= 0) {
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
index 2e24338..7f489f4 100644
--- a/src/pcm/pcm.c
+++ b/src/pcm/pcm.c
@@ -2116,6 +2116,10 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
#ifndef PIC
extern void *snd_pcm_open_symbols(void);
#endif
+
+ snd_config_t *libs = NULL;
+ const char *libs_lib = NULL;
+
if (snd_config_get_type(pcm_conf) != SND_CONFIG_TYPE_COMPOUND) {
char *val;
id = NULL;
@@ -2160,6 +2164,19 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
SNDERR("Invalid type for %s", id);
goto _err;
}
+
+ continue;
+ }
+ // Handle an array of extra libs.
+ if (strcmp(id, "libs") == 0) {
+ if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
+ SNDERR("Invalid type for libs definition in PCM %s definition",
+ str);
+ goto _err;
+ }
+
+ libs = n;
+
continue;
}
if (strcmp(id, "open") == 0) {
@@ -2184,7 +2201,62 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
open_name = buf;
sprintf(buf, "_snd_pcm_%s_open", str);
}
- if (!lib) {
+
+#ifndef PIC
+ snd_pcm_open_symbols(); /* this call is for static linking only */
+#endif
+
+ // Normal alsa behaviour when there is no libs array.
+ if (!libs) {
+ if (lib) {
+ open_func = snd_dlobj_cache_get(lib, open_name,
+ SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 1);
+ }
+ }
+ // Handle libs array.
+ // Suppresses error messages if any function is loaded successfully.
+ else {
+ if (lib) {
+ open_func = snd_dlobj_cache_get(lib, open_name,
+ SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 0);
+ }
+
+ if (!open_func) {
+ snd_config_for_each(i, next, libs) {
+ snd_config_t *n = snd_config_iterator_entry(i);
+
+ err = snd_config_get_string(n, &libs_lib);
+ if (err < 0) {
+ SNDERR("Invalid entry in PCM %s libs definition", str);
+ goto _err;
+ }
+
+ if (!open_func) {
+ open_func = snd_dlobj_cache_get(libs_lib, open_name,
+ SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 0);
+ }
+ }
+ }
+
+ // Print error messages.
+ if (!open_func) {
+ if (lib) {
+ SNDERR("Either %s cannot be opened or %s was not defined inside",
+ lib, open_name);
+ }
+
+ snd_config_for_each(i, next, libs) {
+ snd_config_t *n = snd_config_iterator_entry(i);
+
+ snd_config_get_string(n, &libs_lib);
+ SNDERR("Either %s cannot be opened or %s was not defined inside",
+ libs_lib, open_name);
+ }
+ }
+ }
+
+ // Look in ALSA_PLUGIN_DIR iff we found nowhere else to look.
+ if (!lib && (!libs || !libs_lib)) {
const char *const *build_in = build_in_pcms;
while (*build_in) {
if (!strcmp(*build_in, str))
@@ -2200,12 +2272,11 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
lib = buf1;
sprintf(buf1, "%s/libasound_module_pcm_%s.so", ALSA_PLUGIN_DIR, str);
}
- }
-#ifndef PIC
- snd_pcm_open_symbols(); /* this call is for static linking only */
-#endif
- open_func = snd_dlobj_cache_get(lib, open_name,
+
+ open_func = snd_dlobj_cache_get(lib, open_name,
SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 1);
+ }
+
if (open_func) {
err = open_func(pcmp, name, pcm_root, pcm_conf, stream, mode);
if (err >= 0) {

View file

@ -38,6 +38,22 @@
"type": "github"
}
},
"flake-compat_2": {
"flake": false,
"locked": {
"lastModified": 1641205782,
"narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
@ -58,6 +74,28 @@
"type": "github"
}
},
"musicutil": {
"inputs": {
"flake-compat": "flake-compat_2",
"nixpkgs": [
"nixpkgs"
],
"utils": "utils_2"
},
"locked": {
"lastModified": 1644319517,
"narHash": "sha256-qH9+WBMb9zfeJcx2sf7juW28V5ggyv9jX9VKvRApyXg=",
"owner": "ChaotiCryptidz",
"repo": "musicutil",
"rev": "7b34eaeb8d05e8e8365127bc1e3389fc2d39663f",
"type": "gitlab"
},
"original": {
"owner": "ChaotiCryptidz",
"repo": "musicutil",
"type": "gitlab"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1643805626,
@ -78,6 +116,7 @@
"inputs": {
"deploy-rs": "deploy-rs",
"home-manager": "home-manager",
"musicutil": "musicutil",
"nixpkgs": "nixpkgs"
}
},
@ -95,6 +134,21 @@
"repo": "flake-utils",
"type": "github"
}
},
"utils_2": {
"locked": {
"lastModified": 1644229661,
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",

View file

@ -7,6 +7,8 @@
home-manager.inputs.nixpkgs.follows = "nixpkgs";
deploy-rs.url = "github:serokell/deploy-rs";
deploy-rs.inputs.nixpkgs.follows = "nixpkgs";
musicutil.url = "gitlab:ChaotiCryptidz/musicutil";
musicutil.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { ... }@inputs: import ./outputs.nix inputs;

View file

@ -6,4 +6,5 @@
"script-opts" = "ytdl_hook-ytdl_path=${pkgs.yt-dlp}/bin/yt-dlp";
};
};
programs.zsh.shellAliases.listen = "${pkgs.mpv}/bin/mpv \"https://music:$(cat /secrets/music-stream-password)@stream.owo.monster/flac\" --cache=yes --cache-pause-initial=yes --cache-pause-wait=5";
}

View file

@ -1 +1 @@
{ config, pkgs, ... }: { home.packages = with pkgs; [ musicutil ]; }
{ inputs, pkgs, ... }: { home.packages = [ inputs.musicutil.defaultPackage.${pkgs.system} ]; }

View file

@ -24,7 +24,7 @@
audio_output_format "44100:16:2"
audio_output {
type "httpd"
name "HTTP Music Out"
name "HTTP Opus"
encoder "opus"
port "8012"
bitrate "96000"
@ -32,6 +32,17 @@
always_on "yes"
tags "yes"
}
audio_output {
type "httpd"
name "HTTP FLAC"
encoder "flac"
port "8013"
format "44100:16:2"
#oggflac "yes"
#oggchaining "yes"
always_on "yes"
tags "yes"
}
'';
};
@ -49,6 +60,13 @@
auth_basic_user_file /secrets/music-stream-passwd;
'';
};
"/flac" = {
proxyPass = "http://127.0.0.1:8013";
extraConfig = ''
auth_basic "Music Password";
auth_basic_user_file /secrets/music-stream-passwd;
'';
};
};
};

View file

@ -30,7 +30,11 @@ in {
initrd.postDeviceCommands = pkgs.lib.mkBefore ''
mkdir -m 0755 -p /key
sleep 3
while !(findfs LABEL=${usb_label})
do
echo "Please Plug In USB"
sleep 1
done
mount -n -t vfat -o ro `findfs LABEL=${usb_label}` /key
'';

View file

@ -0,0 +1,232 @@
diff --git a/src/control/control.c b/src/control/control.c
index d66ed75..42cecad 100644
--- a/src/control/control.c
+++ b/src/control/control.c
@@ -838,6 +838,10 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
#ifndef PIC
extern void *snd_control_open_symbols(void);
#endif
+
+ snd_config_t *libs = NULL;
+ const char *libs_lib = NULL;
+
if (snd_config_get_type(ctl_conf) != SND_CONFIG_TYPE_COMPOUND) {
if (name)
SNDERR("Invalid type for CTL %s definition", name);
@@ -879,6 +883,19 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
SNDERR("Invalid type for %s", id);
goto _err;
}
+
+ continue;
+ }
+ // Handle an array of extra libs.
+ if (strcmp(id, "libs") == 0) {
+ if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
+ SNDERR("Invalid type for libs definition in CTL %s definition",
+ str);
+ goto _err;
+ }
+
+ libs = n;
+
continue;
}
if (strcmp(id, "open") == 0) {
@@ -903,7 +920,62 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
open_name = buf;
sprintf(buf, "_snd_ctl_%s_open", str);
}
- if (!lib) {
+
+#ifndef PIC
+ snd_control_open_symbols();
+#endif
+
+ // Normal alsa behaviour when there is no libs array.
+ if (!libs) {
+ if (lib) {
+ open_func = snd_dlobj_cache_get(lib, open_name,
+ SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 1);
+ }
+ }
+ // Handle libs array.
+ // Suppresses error messages if any function is loaded successfully.
+ else {
+ if (lib) {
+ open_func = snd_dlobj_cache_get(lib, open_name,
+ SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 0);
+ }
+
+ if (!open_func) {
+ snd_config_for_each(i, next, libs) {
+ snd_config_t *n = snd_config_iterator_entry(i);
+
+ err = snd_config_get_string(n, &libs_lib);
+ if (err < 0) {
+ SNDERR("Invalid entry in CTL %s libs definition", str);
+ goto _err;
+ }
+
+ if (!open_func) {
+ open_func = snd_dlobj_cache_get(libs_lib, open_name,
+ SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 0);
+ }
+ }
+ }
+
+ // Print error messages.
+ if (!open_func) {
+ if (lib) {
+ SNDERR("Either %s cannot be opened or %s was not defined inside",
+ lib, open_name);
+ }
+
+ snd_config_for_each(i, next, libs) {
+ snd_config_t *n = snd_config_iterator_entry(i);
+
+ snd_config_get_string(n, &libs_lib);
+ SNDERR("Either %s cannot be opened or %s was not defined inside",
+ libs_lib, open_name);
+ }
+ }
+ }
+
+ // Look in ALSA_PLUGIN_DIR iff we found nowhere else to look.
+ if (!lib && (!libs || !libs_lib)) {
const char *const *build_in = build_in_ctls;
while (*build_in) {
if (!strcmp(*build_in, str))
@@ -919,12 +991,11 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
lib = buf1;
sprintf(buf1, "%s/libasound_module_ctl_%s.so", ALSA_PLUGIN_DIR, str);
}
- }
-#ifndef PIC
- snd_control_open_symbols();
-#endif
- open_func = snd_dlobj_cache_get(lib, open_name,
+
+ open_func = snd_dlobj_cache_get(lib, open_name,
SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 1);
+ }
+
if (open_func) {
err = open_func(ctlp, name, ctl_root, ctl_conf, mode);
if (err >= 0) {
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
index 2e24338..7f489f4 100644
--- a/src/pcm/pcm.c
+++ b/src/pcm/pcm.c
@@ -2116,6 +2116,10 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
#ifndef PIC
extern void *snd_pcm_open_symbols(void);
#endif
+
+ snd_config_t *libs = NULL;
+ const char *libs_lib = NULL;
+
if (snd_config_get_type(pcm_conf) != SND_CONFIG_TYPE_COMPOUND) {
char *val;
id = NULL;
@@ -2160,6 +2164,19 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
SNDERR("Invalid type for %s", id);
goto _err;
}
+
+ continue;
+ }
+ // Handle an array of extra libs.
+ if (strcmp(id, "libs") == 0) {
+ if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
+ SNDERR("Invalid type for libs definition in PCM %s definition",
+ str);
+ goto _err;
+ }
+
+ libs = n;
+
continue;
}
if (strcmp(id, "open") == 0) {
@@ -2184,7 +2201,62 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
open_name = buf;
sprintf(buf, "_snd_pcm_%s_open", str);
}
- if (!lib) {
+
+#ifndef PIC
+ snd_pcm_open_symbols(); /* this call is for static linking only */
+#endif
+
+ // Normal alsa behaviour when there is no libs array.
+ if (!libs) {
+ if (lib) {
+ open_func = snd_dlobj_cache_get(lib, open_name,
+ SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 1);
+ }
+ }
+ // Handle libs array.
+ // Suppresses error messages if any function is loaded successfully.
+ else {
+ if (lib) {
+ open_func = snd_dlobj_cache_get(lib, open_name,
+ SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 0);
+ }
+
+ if (!open_func) {
+ snd_config_for_each(i, next, libs) {
+ snd_config_t *n = snd_config_iterator_entry(i);
+
+ err = snd_config_get_string(n, &libs_lib);
+ if (err < 0) {
+ SNDERR("Invalid entry in PCM %s libs definition", str);
+ goto _err;
+ }
+
+ if (!open_func) {
+ open_func = snd_dlobj_cache_get(libs_lib, open_name,
+ SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 0);
+ }
+ }
+ }
+
+ // Print error messages.
+ if (!open_func) {
+ if (lib) {
+ SNDERR("Either %s cannot be opened or %s was not defined inside",
+ lib, open_name);
+ }
+
+ snd_config_for_each(i, next, libs) {
+ snd_config_t *n = snd_config_iterator_entry(i);
+
+ snd_config_get_string(n, &libs_lib);
+ SNDERR("Either %s cannot be opened or %s was not defined inside",
+ libs_lib, open_name);
+ }
+ }
+ }
+
+ // Look in ALSA_PLUGIN_DIR iff we found nowhere else to look.
+ if (!lib && (!libs || !libs_lib)) {
const char *const *build_in = build_in_pcms;
while (*build_in) {
if (!strcmp(*build_in, str))
@@ -2200,12 +2272,11 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
lib = buf1;
sprintf(buf1, "%s/libasound_module_pcm_%s.so", ALSA_PLUGIN_DIR, str);
}
- }
-#ifndef PIC
- snd_pcm_open_symbols(); /* this call is for static linking only */
-#endif
- open_func = snd_dlobj_cache_get(lib, open_name,
+
+ open_func = snd_dlobj_cache_get(lib, open_name,
SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 1);
+ }
+
if (open_func) {
err = open_func(pcmp, name, pcm_root, pcm_conf, stream, mode);
if (err >= 0) {

View file

@ -0,0 +1,47 @@
{ lib
, stdenv
, fetchurl
, alsa-topology-conf
, alsa-ucm-conf
}:
stdenv.mkDerivation rec {
pname = "alsa-lib";
version = "1.2.6.1";
src = fetchurl {
url = "mirror://alsa/lib/${pname}-${version}.tar.bz2";
hash = "sha256-rVgpk9Us21+xWaC+q2CmrFfqsMwb34XcTbbWGX8CMz8=";
};
patches = [
# Add a "libs" field to the syntax recognized in the /etc/asound.conf file.
# The nixos modules for pulseaudio, jack, and pipewire are leveraging this
# "libs" field to declare locations for both native and 32bit plugins, in
# order to support apps with 32bit sound running on x86_64 architecture.
./alsa-plugin-conf-multilib.patch
];
enableParallelBuilding = true;
postInstall = ''
ln -s ${alsa-ucm-conf}/share/alsa/{ucm,ucm2} $out/share/alsa
ln -s ${alsa-topology-conf}/share/alsa/topology $out/share/alsa
'';
outputs = [ "out" "dev" ];
meta = with lib; {
homepage = "http://www.alsa-project.org/";
description = "ALSA, the Advanced Linux Sound Architecture libraries";
longDescription = ''
The Advanced Linux Sound Architecture (ALSA) provides audio and
MIDI functionality to the Linux-based operating system.
'';
license = licenses.lgpl21Plus;
platforms = platforms.linux;
maintainers = with maintainers; [ l-as ];
};
}

View file

@ -12,7 +12,7 @@ final: prev: {
};
roc-toolkit-patched = final.callPackage ./roc-toolkit-patched { };
roc-send-pcm = final.callPackage ./roc-send-pcm { };
musicutil = final.python3Packages.callPackage ./musicutil {
fold-to-ascii = final.python3Packages.callPackage ./fold-to-ascii {};
vivaldi = prev.vivaldi.override {
alsa-lib = final.callPackage ./alsa-lib {};
};
}

View file

@ -1,12 +0,0 @@
{ lib, buildPythonPackage, fetchPypi }:
buildPythonPackage rec {
pname = "fold-to-ascii";
version = "1.0.2.post1";
src = fetchPypi {
pname = "fold_to_ascii";
inherit version;
sha256 = "sha256-cWegf9wjC9XfU4HpIh/iRtDv86hutn45NfkfWuyjUzo=";
};
}

View file

@ -1,24 +0,0 @@
{ stdenv, fetchFromGitLab, lib, python3Packages, mutagen, fold-to-ascii, pyyaml, ffmpeg, r128gain }:
python3Packages.buildPythonApplication rec {
pname = "musicutil";
version = "latest";
rev = "9880c175a679bf4450745dc91fb18fb88e0a4fd6";
src = fetchFromGitLab {
owner = "ChaotiCryptidz";
repo = "musicutil";
inherit rev;
sha256 = "sha256-pvDxVeCNZy3TKfbFds4QSQPR2lYZR+RZrwBHI+Pfj+w=";
#sha256 = lib.fakeSha256;
};
postPatch = ''
substituteInPlace musicutil/meta.py --replace 'ffmpeg_path = "ffmpeg"' 'ffmpeg_path = "${ffmpeg}/bin/ffmpeg"'
substituteInPlace musicutil/meta.py --replace 'ffprobe_path = "ffprobe"' 'ffprobe_path = "${ffmpeg}/bin/ffprobe"'
substituteInPlace musicutil/meta.py --replace 'r128gain_path = "r128gain"' 'r128gain_path = "${r128gain}/bin/r128gain"'
'';
doCheck = false;
propagatedBuildInputs = [ mutagen fold-to-ascii pyyaml ];
}