smallest change
This commit is contained in:
parent
4cca1dc327
commit
9c83ba6849
77 changed files with 36828 additions and 1516 deletions
209
modules/nixos/hardware/audio/auto-connect-tt.lua
Normal file
209
modules/nixos/hardware/audio/auto-connect-tt.lua
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
-- As explained on (and stolen from): https://bennett.dev/auto-link-pipewire-ports-wireplumber/
|
||||
--
|
||||
-- This script keeps my stereo-null-sink connected to whatever output I'm currently using.
|
||||
-- I do this so Pulseaudio (and Wine) always sees a stereo output plus I can swap the output
|
||||
-- without needing to reconnect everything.
|
||||
|
||||
-- Link two ports together
|
||||
function link_port(output_port, input_port)
|
||||
if not input_port or not output_port then
|
||||
return nil
|
||||
end
|
||||
|
||||
print("out", dump(output_port.properties))
|
||||
print("in", dump(input_port.properties))
|
||||
|
||||
local link_args = {
|
||||
["link.input.node"] = input_port.properties["node.id"],
|
||||
["link.input.port"] = input_port.properties["object.id"],
|
||||
|
||||
["link.output.node"] = output_port.properties["node.id"],
|
||||
["link.output.port"] = output_port.properties["object.id"],
|
||||
|
||||
-- -- The node never got created if it didn't have this field set to something
|
||||
-- ["object.id"] = nil,
|
||||
--
|
||||
-- -- I was running into issues when I didn't have this set
|
||||
-- ["object.linger"] = 1,
|
||||
--
|
||||
-- ["node.description"] = "Link created by auto_connect_ports",
|
||||
}
|
||||
|
||||
print(dump(link_args))
|
||||
|
||||
local link = Link("link-factory", link_args)
|
||||
link:activate(1)
|
||||
|
||||
print("link created", dump(link.properties))
|
||||
|
||||
return link
|
||||
end
|
||||
|
||||
-- Automatically link ports together by their specific audio channels.
|
||||
--
|
||||
-- ┌──────────────────┐ ┌───────────────────┐
|
||||
-- │ │ │ │
|
||||
-- │ FL ├────────►│ AUX0 │
|
||||
-- │ OUTPUT │ │ │
|
||||
-- │ FR ├────────►│ AUX1 INPUT │
|
||||
-- │ │ │ │
|
||||
-- └──────────────────┘ │ AUX2 │
|
||||
-- │ │
|
||||
-- └───────────────────┘
|
||||
--
|
||||
-- -- Call this method inside a script in global scope
|
||||
--
|
||||
-- auto_connect_ports {
|
||||
--
|
||||
-- -- A constraint for all the required ports of the output device
|
||||
-- output = Constraint { "node.name"}
|
||||
--
|
||||
-- -- A constraint for all the required ports of the input device
|
||||
-- input = Constraint { .. }
|
||||
--
|
||||
-- -- A mapping of output audio channels to input audio channels
|
||||
--
|
||||
-- connections = {
|
||||
-- ["FL"] = "AUX0"
|
||||
-- ["FR"] = "AUX1"
|
||||
-- }
|
||||
--
|
||||
-- }
|
||||
|
||||
function dump(o)
|
||||
if type(o) == "table" then
|
||||
local s = "{ "
|
||||
for k, v in pairs(o) do
|
||||
if type(k) ~= "number" then
|
||||
k = '"' .. k .. '"'
|
||||
end
|
||||
s = s .. "[" .. k .. "] = " .. dump(v) .. ","
|
||||
end
|
||||
return s .. "} "
|
||||
else
|
||||
return tostring(o)
|
||||
end
|
||||
end
|
||||
|
||||
function auto_connect_ports(args)
|
||||
local output_om = ObjectManager({
|
||||
Interest({
|
||||
type = "port",
|
||||
args["output"],
|
||||
Constraint({ "port.direction", "equals", "out" }),
|
||||
}),
|
||||
})
|
||||
|
||||
print("output_om", dump(output_om))
|
||||
|
||||
local links = {}
|
||||
|
||||
local input_om = ObjectManager({
|
||||
Interest({
|
||||
type = "port",
|
||||
args["input"],
|
||||
Constraint({ "port.direction", "equals", "in" }),
|
||||
}),
|
||||
})
|
||||
|
||||
print("input_om", dump(input_om))
|
||||
|
||||
local all_links = ObjectManager({
|
||||
Interest({
|
||||
type = "link",
|
||||
}),
|
||||
})
|
||||
|
||||
print("all_links", dump(all_links))
|
||||
|
||||
local unless = nil
|
||||
|
||||
if args["unless"] then
|
||||
unless = ObjectManager({
|
||||
Interest({
|
||||
type = "port",
|
||||
args["unless"],
|
||||
Constraint({ "port.direction", "equals", "in" }),
|
||||
}),
|
||||
})
|
||||
end
|
||||
|
||||
function _connect()
|
||||
print("connecting...")
|
||||
local delete_links = unless and unless:get_n_objects() > 0
|
||||
|
||||
if delete_links then
|
||||
for _i, link in pairs(links) do
|
||||
link:request_destroy()
|
||||
end
|
||||
|
||||
links = {}
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
for output_name, input_names in pairs(args.connect) do
|
||||
local input_names = input_names[1] == nil and { input_names } or input_names
|
||||
|
||||
-- for output in output_om:iterate() do
|
||||
-- print(dump(output.properties))
|
||||
-- end
|
||||
|
||||
if delete_links then
|
||||
else
|
||||
-- Iterate through all the output ports with the correct channel name
|
||||
for output in output_om:iterate({ Constraint({ "audio.channel", "equals", output_name }) }) do
|
||||
for _i, input_name in pairs(input_names) do
|
||||
-- Iterate through all the input ports with the correct channel name
|
||||
-- print("inp name", input_name)
|
||||
-- print("output", dump(output.properties))
|
||||
-- for input in input_om:iterate() do
|
||||
-- print("hi")
|
||||
-- -- print(dump(input.properties))
|
||||
-- end
|
||||
for input in input_om:iterate({ Constraint({ "audio.channel", "equals", input_name }) }) do
|
||||
-- print("here2")
|
||||
-- Link all the nodes
|
||||
local link = link_port(output, input)
|
||||
-- print("linked")
|
||||
|
||||
if link then
|
||||
table.insert(links, link)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
output_om:connect("object-added", _connect)
|
||||
input_om:connect("object-added", _connect)
|
||||
all_links:connect("object-added", _connect)
|
||||
|
||||
output_om:activate()
|
||||
input_om:activate()
|
||||
all_links:activate()
|
||||
|
||||
if unless then
|
||||
unless:connect("object-added", _connect)
|
||||
unless:connect("object-removed", _connect)
|
||||
unless:activate()
|
||||
end
|
||||
|
||||
print("dun")
|
||||
end
|
||||
|
||||
-- Auto connect the stereo null sink to bluetooth headphones
|
||||
auto_connect_ports({
|
||||
input = Constraint({
|
||||
"port.alias",
|
||||
"matches",
|
||||
"Scarlett Solo USB:playback_*",
|
||||
}),
|
||||
output = Constraint({ "port.alias", "matches", "ALC1220 Analog:capture_*" }),
|
||||
connect = {
|
||||
["FL"] = { "FL" },
|
||||
["FR"] = { "FR" },
|
||||
},
|
||||
})
|
||||
|
|
@ -13,7 +13,6 @@ in {
|
|||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
# Enable sound with pipewire.
|
||||
hardware.pulseaudio.enable = false;
|
||||
security.rtkit.enable = true;
|
||||
services.pipewire = {
|
||||
|
|
@ -21,19 +20,102 @@ in {
|
|||
alsa.enable = true;
|
||||
alsa.support32Bit = true;
|
||||
pulse.enable = true;
|
||||
# If you want to use JACK applications, uncomment this
|
||||
wireplumber.enable = true;
|
||||
jack.enable = true;
|
||||
|
||||
extraConfig.pipewire.adjust-sample-rate = {
|
||||
"context.properties" = {
|
||||
"default.clock.rate" = 44100;
|
||||
"default.allowed-rates" = [44100];
|
||||
};
|
||||
};
|
||||
# extraConfig.pipewire.adjust-sample-rate = {
|
||||
# "context.properties" = {
|
||||
# "default.clock.rate" = 41000;
|
||||
# "default.clock.allowed-rates" = [44100];
|
||||
# };
|
||||
# };
|
||||
|
||||
# use the example session manager (no others are packaged yet so this is enabled by default,
|
||||
# no need to redefine it in your config for now)
|
||||
wireplumber.enable = true;
|
||||
# wireplumber.extraConfig = {
|
||||
# "custom" = {
|
||||
# "monitor.alsa.rules" = [
|
||||
# {
|
||||
# matches = [
|
||||
# {
|
||||
# "node.name" = "alsa_output.usb-Focusrite_Scarlett_Solo_USB_Y76P5M4160A866-00.HiFi__Line1__sink";
|
||||
# }
|
||||
# ];
|
||||
# actions = {
|
||||
# update-props = {
|
||||
# "audio.format" = "S32LE";
|
||||
# "audio.rate" = 192000;
|
||||
# "api.alsa.period-size" = 1024;
|
||||
# };
|
||||
# };
|
||||
# }
|
||||
# {
|
||||
# matches = [
|
||||
# {
|
||||
# "node.name" = "alsa_input.pci-0000_0d_00.4.analog-stereo";
|
||||
# }
|
||||
# ];
|
||||
# actions = {
|
||||
# update-props = {
|
||||
# "audio.format" = "S32LE";
|
||||
# "audio.rate" = 192000;
|
||||
# "api.alsa.period-size" = 1024;
|
||||
# };
|
||||
# };
|
||||
# }
|
||||
# {
|
||||
# matches = [
|
||||
# {
|
||||
# "node.name" = "~alsa_output.*";
|
||||
# }
|
||||
# ];
|
||||
# actions = {
|
||||
# update-props = {
|
||||
# "api.alsa.period-size" = 1024;
|
||||
# "api.alsa.headroom" = 8192;
|
||||
# };
|
||||
# };
|
||||
# }
|
||||
# ];
|
||||
# };
|
||||
#
|
||||
# "99-connect-tt" = {
|
||||
# "wireplumber.components" = [
|
||||
# {
|
||||
# name = "auto-connect-tt.lua";
|
||||
# type = "script/lua";
|
||||
# provides = "custom.connect-tt";
|
||||
# }
|
||||
# ];
|
||||
#
|
||||
# "wireplumber.profiles" = {
|
||||
# main = {
|
||||
# "custom.connect-tt" = "required";
|
||||
# };
|
||||
# };
|
||||
# };
|
||||
# };
|
||||
|
||||
# wireplumber.extraScripts = {
|
||||
# "auto-connect-tt.lua" = builtins.readFile ./auto-connect-tt.lua;
|
||||
# };
|
||||
# };
|
||||
#
|
||||
# # PulseAudio compatibility layer configuration for 44.1kHz
|
||||
# services.pipewire.extraConfig.pipewire-pulse."92-steam-config" = {
|
||||
# context.modules = [
|
||||
# {
|
||||
# name = "libpipewire-module-protocol-pulse";
|
||||
# args = {
|
||||
# pulse.min.req = "32/44100";
|
||||
# pulse.default.req = "32/44100";
|
||||
# pulse.min.quantum = "32/44100";
|
||||
# pulse.max.quantum = "8192/44100";
|
||||
# };
|
||||
# }
|
||||
# ];
|
||||
# };
|
||||
#
|
||||
# environment.sessionVariables = {
|
||||
# PIPEWIRE_LATENCY = "1024/44100";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
28
modules/nixos/hardware/audio/dump-links.lua
Normal file
28
modules/nixos/hardware/audio/dump-links.lua
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
-- Dump all Wireplumber links
|
||||
|
||||
function dump(o)
|
||||
if type(o) == "table" then
|
||||
local s = "{ "
|
||||
for k, v in pairs(o) do
|
||||
if type(k) ~= "number" then
|
||||
k = '"' .. k .. '"'
|
||||
end
|
||||
s = s .. "[" .. k .. "] = " .. dump(v) .. ",\n"
|
||||
end
|
||||
return s .. "} "
|
||||
else
|
||||
return tostring(o)
|
||||
end
|
||||
end
|
||||
|
||||
local link_om = ObjectManager({
|
||||
Interest({
|
||||
type = "link",
|
||||
}),
|
||||
})
|
||||
|
||||
link_om:connect("object-added", function(om, link)
|
||||
print(dump(link.properties) .. "\n\n")
|
||||
end)
|
||||
|
||||
link_om:activate()
|
||||
28
modules/nixos/hardware/audio/dump-ports.lua
Normal file
28
modules/nixos/hardware/audio/dump-ports.lua
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
-- Dump all Wireplumber ports
|
||||
|
||||
function dump(o)
|
||||
if type(o) == "table" then
|
||||
local s = "{ "
|
||||
for k, v in pairs(o) do
|
||||
if type(k) ~= "number" then
|
||||
k = '"' .. k .. '"'
|
||||
end
|
||||
s = s .. "[" .. k .. "] = " .. dump(v) .. ",\n"
|
||||
end
|
||||
return s .. "} "
|
||||
else
|
||||
return tostring(o)
|
||||
end
|
||||
end
|
||||
|
||||
local port_om = ObjectManager({
|
||||
Interest({
|
||||
type = "port",
|
||||
}),
|
||||
})
|
||||
|
||||
port_om:connect("object-added", function(om, port)
|
||||
print(dump(port.properties) .. "\n\n")
|
||||
end)
|
||||
|
||||
port_om:activate()
|
||||
104
modules/nixos/hardware/custom-opts/default.nix
Normal file
104
modules/nixos/hardware/custom-opts/default.nix
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
# yoinked from https://gitlab.com/funaali/dotfiles/-/blob/3c74966cc4501c548aac0ee83cf5982510dd615c/modules/nixos/custom-opts.nix#L50, thanks!
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
with lib.custom; let
|
||||
cfg = config.hardware.march;
|
||||
in {
|
||||
options.hardware.march = with types; {
|
||||
arch = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = "GCC -march=";
|
||||
};
|
||||
|
||||
system = mkOption {
|
||||
type = types.str;
|
||||
default = "x86_64-linux";
|
||||
};
|
||||
|
||||
enableNativeOptimizations = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable -march=<arch> optimizations for all packages";
|
||||
};
|
||||
|
||||
enableNativeOptimizationsByDefault = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
description = ''
|
||||
Architectures for which native optimizations are enabled by default.
|
||||
'';
|
||||
};
|
||||
|
||||
TCPBBRCongestionControl = mkEnableOption "TCP BBR congestion control";
|
||||
|
||||
cpu.vcores = mkOption {
|
||||
type = types.int;
|
||||
default = 0;
|
||||
description = "Teh number of virtual CPU cores. Used to calculate heuristics.";
|
||||
};
|
||||
|
||||
memory.total = mkOption {
|
||||
type = types.int;
|
||||
default = 0;
|
||||
description = "Total amount of RAM in the system (gigabytes). Used to calculate heuristics.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkMerge [
|
||||
# Enable nix to build for the system arch and its inferiors.
|
||||
(mkIf (cfg.arch != null) {
|
||||
# taken from https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/config/nix.nix
|
||||
nix.settings.system-features = map (x: "gccarch-${x}") ((systems.architectures.inferiors.${cfg.arch} or []) ++ [cfg.arch]) ++ ["big-parallel"];
|
||||
})
|
||||
|
||||
# Set nix cores and max jobs based on cores and installed memory.
|
||||
(mkIf (cfg.cpu.vcores + cfg.memory.total > 0) (
|
||||
let
|
||||
minMemoryPerCore = 2;
|
||||
jobsOvercommitFactor = 4;
|
||||
cores = min 16 (min (cfg.cpu.vcores / 2) (cfg.memory.total / minMemoryPerCore));
|
||||
max-jobs = jobsOvercommitFactor * cfg.memory.total / (cores * minMemoryPerCore);
|
||||
in {
|
||||
nix.settings = {
|
||||
inherit cores max-jobs;
|
||||
};
|
||||
}
|
||||
))
|
||||
|
||||
# Native arch optimizations
|
||||
(mkIf (cfg.enableNativeOptimizations || elem cfg.arch cfg.enableNativeOptimizationsByDefault) {
|
||||
assertions = [
|
||||
{
|
||||
message = "custom.arch can't be null when custom.enableNativeOptimizations is true!";
|
||||
assertion = cfg.enableNativeOptimizations -> cfg.arch != null;
|
||||
}
|
||||
];
|
||||
|
||||
nixpkgs.hostPlatform = mkOverride 1 {
|
||||
system = cfg.system;
|
||||
gcc.arch = cfg.arch;
|
||||
gcc.tune = cfg.arch;
|
||||
};
|
||||
})
|
||||
|
||||
# Enable TCP BBR congestion control
|
||||
(mkIf cfg.TCPBBRCongestionControl {
|
||||
boot.kernelModules = ["tcp_bbr"];
|
||||
boot.kernel.sysctl = {
|
||||
"net.core.default_qdisc" = "cake";
|
||||
"net.ipv4.tcp_congestion_control" = "bbr";
|
||||
};
|
||||
})
|
||||
|
||||
# Settings if total memory is defined
|
||||
(mkIf (cfg.memory.total > 0) {
|
||||
services.earlyoom.freeMemThreshold = min 1 (max 5 (200 / cfg.memory.total));
|
||||
})
|
||||
];
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ in {
|
|||
kmod
|
||||
systemd
|
||||
ripgrep
|
||||
mullvad
|
||||
nixos-stable.mullvad
|
||||
killall
|
||||
sd
|
||||
];
|
||||
|
|
|
|||
|
|
@ -37,11 +37,11 @@ in {
|
|||
# https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus
|
||||
# Only available from driver 515.43.04+
|
||||
# Currently alpha-quality/buggy, so false is currently the recommended setting.
|
||||
open = false;
|
||||
open = true;
|
||||
|
||||
# Enable the Nvidia settings menu,
|
||||
# accessible via `nvidia-settings`.
|
||||
nvidiaSettings = true;
|
||||
nvidiaSettings = false;
|
||||
|
||||
# Optionally, you may need to select the appropriate driver version for your specific GPU.
|
||||
package = config.boot.kernelPackages.nvidiaPackages.beta;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue