nix fmt
Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
This commit is contained in:
parent
a3187e163d
commit
900f95169f
83 changed files with 1134 additions and 705 deletions
|
@ -4,62 +4,96 @@ rec {
|
|||
## Renames an alsa device from a given `name` using the new `description`.
|
||||
##
|
||||
#@ { name: String, description: String } -> { matches: List, apply_properties: Attrs }
|
||||
mkAlsaRename = { name, description }: {
|
||||
matches = [
|
||||
[
|
||||
[ "device.name" "matches" name ]
|
||||
]
|
||||
];
|
||||
# actions = { "update-props" = { "node.description" = description; }; };
|
||||
apply_properties = {
|
||||
"device.description" = description;
|
||||
mkAlsaRename =
|
||||
{ name, description }:
|
||||
{
|
||||
matches = [
|
||||
[
|
||||
[
|
||||
"device.name"
|
||||
"matches"
|
||||
name
|
||||
]
|
||||
]
|
||||
];
|
||||
# actions = { "update-props" = { "node.description" = description; }; };
|
||||
apply_properties = {
|
||||
"device.description" = description;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
## Create a pipewire audio node.
|
||||
##
|
||||
#@ { name: String, factory: String ? "adapter", ... } -> { factory: String, args: Attrs }
|
||||
mkAudioNode = args@{ name, factory ? "adapter", ... }: {
|
||||
inherit factory;
|
||||
args = (builtins.removeAttrs args [ "name" "description" ]) // {
|
||||
"node.name" = name;
|
||||
"node.description" = args.description or args."node.description";
|
||||
"factory.name" = args."factory.name" or "support.null-audio-sink";
|
||||
mkAudioNode =
|
||||
args@{
|
||||
name,
|
||||
factory ? "adapter",
|
||||
...
|
||||
}:
|
||||
{
|
||||
inherit factory;
|
||||
args =
|
||||
(builtins.removeAttrs args [
|
||||
"name"
|
||||
"description"
|
||||
])
|
||||
// {
|
||||
"node.name" = name;
|
||||
"node.description" = args.description or args."node.description";
|
||||
"factory.name" = args."factory.name" or "support.null-audio-sink";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
## Create a virtual pipewire audio node.
|
||||
##
|
||||
#@ { name: String, ... } -> { factory: "adapter", args: Attrs }
|
||||
mkVirtualAudioNode = args@{ name, ... }:
|
||||
mkAudioNode (args // {
|
||||
name = "virtual-${lib.toLower name}-audio";
|
||||
description = "${name} (Virtual)";
|
||||
"media.class" = args.class or args."media.class" or "Audio/Duplex";
|
||||
"object.linger" = args."object.linger" or true;
|
||||
"audio.position" = args."audio.position" or [ "FL" "FR" ];
|
||||
"monitor.channel-volumes" = args."monitor.channel-volumes" or true;
|
||||
});
|
||||
mkVirtualAudioNode =
|
||||
args@{ name, ... }:
|
||||
mkAudioNode (
|
||||
args
|
||||
// {
|
||||
name = "virtual-${lib.toLower name}-audio";
|
||||
description = "${name} (Virtual)";
|
||||
"media.class" = args.class or args."media.class" or "Audio/Duplex";
|
||||
"object.linger" = args."object.linger" or true;
|
||||
"audio.position" =
|
||||
args."audio.position" or [
|
||||
"FL"
|
||||
"FR"
|
||||
];
|
||||
"monitor.channel-volumes" = args."monitor.channel-volumes" or true;
|
||||
}
|
||||
);
|
||||
|
||||
## Connect two pipewire audio nodes
|
||||
##
|
||||
#@ { name: String?, from: String, to: String, ... } -> { name: "libpipewire-module-loopback", args: Attrs }
|
||||
mkBridgeAudioModule = args@{ from, to, ... }: {
|
||||
name = "libpipewire-module-loopback";
|
||||
args = (builtins.removeAttrs args [ "from" "to" "name" ]) // {
|
||||
"node.name" =
|
||||
if args ? name then
|
||||
"${args.name}-bridge"
|
||||
else
|
||||
"${lib.toLower from}-to-${lib.toLower to}-bridge";
|
||||
"audio.position" = args."audio.position" or [ "FL" "FR" ];
|
||||
"capture.props" = {
|
||||
"node.target" = from;
|
||||
} // (args."capture.props" or { });
|
||||
"playback.props" = {
|
||||
"node.target" = to;
|
||||
"monitor.channel-volumes" = true;
|
||||
} // (args."playback.props" or { });
|
||||
mkBridgeAudioModule =
|
||||
args@{ from, to, ... }:
|
||||
{
|
||||
name = "libpipewire-module-loopback";
|
||||
args =
|
||||
(builtins.removeAttrs args [
|
||||
"from"
|
||||
"to"
|
||||
"name"
|
||||
])
|
||||
// {
|
||||
"node.name" =
|
||||
if args ? name then "${args.name}-bridge" else "${lib.toLower from}-to-${lib.toLower to}-bridge";
|
||||
"audio.position" =
|
||||
args."audio.position" or [
|
||||
"FL"
|
||||
"FR"
|
||||
];
|
||||
"capture.props" = {
|
||||
"node.target" = from;
|
||||
} // (args."capture.props" or { });
|
||||
"playback.props" = {
|
||||
"node.target" = to;
|
||||
"monitor.channel-volumes" = true;
|
||||
} // (args."playback.props" or { });
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
{ lib, inputs, snowfall-inputs }:
|
||||
{
|
||||
lib,
|
||||
inputs,
|
||||
snowfall-inputs,
|
||||
}:
|
||||
|
||||
rec {
|
||||
## Override a package's metadata
|
||||
|
@ -13,7 +17,8 @@ rec {
|
|||
## ```
|
||||
##
|
||||
#@ Attrs -> Package -> Package
|
||||
override-meta = meta: package:
|
||||
override-meta =
|
||||
meta: package:
|
||||
package.overrideAttrs (attrs: {
|
||||
meta = (attrs.meta or { }) // meta;
|
||||
});
|
||||
|
|
|
@ -16,36 +16,42 @@ rec {
|
|||
## ```
|
||||
##
|
||||
#@ { self: Flake, overrides: Attrs ? {} } -> Attrs
|
||||
mkDeploy = { self, overrides ? { } }:
|
||||
mkDeploy =
|
||||
{
|
||||
self,
|
||||
overrides ? { },
|
||||
}:
|
||||
let
|
||||
hosts = self.nixosConfigurations or { };
|
||||
names = builtins.attrNames hosts;
|
||||
nodes = lib.foldl
|
||||
(result: name:
|
||||
let
|
||||
host = hosts.${name};
|
||||
user = host.config.metacfg.user.name or null;
|
||||
inherit (host.pkgs) system;
|
||||
in
|
||||
result // {
|
||||
${name} = (overrides.${name} or { }) // {
|
||||
hostname = overrides.${name}.hostname or "${name}";
|
||||
profiles = (overrides.${name}.profiles or { }) // {
|
||||
system = (overrides.${name}.profiles.system or { }) // {
|
||||
nodes = lib.foldl (
|
||||
result: name:
|
||||
let
|
||||
host = hosts.${name};
|
||||
user = host.config.metacfg.user.name or null;
|
||||
inherit (host.pkgs) system;
|
||||
in
|
||||
result
|
||||
// {
|
||||
${name} = (overrides.${name} or { }) // {
|
||||
hostname = overrides.${name}.hostname or "${name}";
|
||||
profiles = (overrides.${name}.profiles or { }) // {
|
||||
system =
|
||||
(overrides.${name}.profiles.system or { })
|
||||
// {
|
||||
path = deploy-rs.lib.${system}.activate.nixos host;
|
||||
} // lib.optionalAttrs (user != null) {
|
||||
}
|
||||
// lib.optionalAttrs (user != null) {
|
||||
user = "root";
|
||||
sshUser = user;
|
||||
} // lib.optionalAttrs
|
||||
(host.config.metacfg.security.doas.enable or false)
|
||||
{
|
||||
sudo = "doas -u";
|
||||
};
|
||||
};
|
||||
}
|
||||
// lib.optionalAttrs (host.config.metacfg.security.doas.enable or false) { sudo = "doas -u"; };
|
||||
};
|
||||
})
|
||||
{ }
|
||||
names;
|
||||
};
|
||||
}
|
||||
) { } names;
|
||||
in
|
||||
{ inherit nodes; };
|
||||
{
|
||||
inherit nodes;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{ lib, ... }:
|
||||
|
||||
with lib; rec {
|
||||
with lib;
|
||||
rec {
|
||||
## Create a NixOS module option.
|
||||
##
|
||||
## ```nix
|
||||
|
@ -8,7 +9,8 @@ with lib; rec {
|
|||
## ```
|
||||
##
|
||||
#@ Type -> Any -> String
|
||||
mkOpt = type: default: description:
|
||||
mkOpt =
|
||||
type: default: description:
|
||||
mkOption { inherit type default description; };
|
||||
|
||||
## Create a NixOS module option without a description.
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
{ lib, inputs, snowfall-inputs }:
|
||||
{
|
||||
lib,
|
||||
inputs,
|
||||
snowfall-inputs,
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (inputs.nixpkgs.lib) assertMsg last;
|
||||
|
@ -9,14 +13,17 @@ in
|
|||
# Type: String -> Attrs
|
||||
# Usage: get-address-parts "bismuth:3000"
|
||||
# result: { host = "bismuth"; port = "3000"; }
|
||||
get-address-parts = address:
|
||||
get-address-parts =
|
||||
address:
|
||||
let
|
||||
address-parts = builtins.split ":" address;
|
||||
ip = builtins.head address-parts;
|
||||
host = if ip == "" then "127.0.0.1" else ip;
|
||||
port = if builtins.length address-parts != 3 then "" else last address-parts;
|
||||
in
|
||||
{ inherit host port; };
|
||||
{
|
||||
inherit host port;
|
||||
};
|
||||
|
||||
## Create proxy configuration for NGINX virtual hosts.
|
||||
##
|
||||
|
@ -33,22 +40,23 @@ in
|
|||
##
|
||||
#@ { port: Int ? null, host: String ? "127.0.0.1", proxy-web-sockets: Bool ? false, extra-config: Attrs ? { } } -> Attrs
|
||||
create-proxy =
|
||||
{ port ? null
|
||||
, host ? "127.0.0.1"
|
||||
, proxy-web-sockets ? false
|
||||
, extra-config ? { }
|
||||
{
|
||||
port ? null,
|
||||
host ? "127.0.0.1",
|
||||
proxy-web-sockets ? false,
|
||||
extra-config ? { },
|
||||
}:
|
||||
assert assertMsg (port != "" && port != null) "port cannot be empty";
|
||||
assert assertMsg (host != "") "host cannot be empty";
|
||||
extra-config // {
|
||||
locations = (extra-config.locations or { }) // {
|
||||
"/" = (extra-config.locations."/" or { }) // {
|
||||
proxyPass =
|
||||
"http://${host}${if port != null then ":${builtins.toString port}" else ""}";
|
||||
assert assertMsg (port != "" && port != null) "port cannot be empty";
|
||||
assert assertMsg (host != "") "host cannot be empty";
|
||||
extra-config
|
||||
// {
|
||||
locations = (extra-config.locations or { }) // {
|
||||
"/" = (extra-config.locations."/" or { }) // {
|
||||
proxyPass = "http://${host}${if port != null then ":${builtins.toString port}" else ""}";
|
||||
|
||||
proxyWebsockets = proxy-web-sockets;
|
||||
};
|
||||
proxyWebsockets = proxy-web-sockets;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue