feat: add (incomplete) nix flake

dave.py isn't packaged yet. Will try to do this myself but dealing with
vcpkg is a bit annoying.
This commit is contained in:
2026-03-22 17:59:19 -04:00
parent 3232e797c8
commit 4185723b8d
40 changed files with 494 additions and 66 deletions

View File

@@ -7,4 +7,4 @@ COPY . .
RUN pip install -r requirements.txt
CMD ["python", "main.py"]
CMD ["python", "-m", "errornocord.main"]

View File

@@ -1,3 +1,3 @@
# ErrorNoCord
Discord music bot for testing purposes, with live reloading support
Hot-reloadable Discord music bot

59
default.nix Normal file
View File

@@ -0,0 +1,59 @@
{
lib,
python3Packages,
self,
...
}:
let
disnake = python3Packages.disnake.overrideAttrs (old: {
src = self.pins.disnake;
propagatedBuildInputs =
with python3Packages;
old.propagatedBuildInputs
++ [
typing-extensions
versioningit
];
nativeBuildInputs = old.nativeBuildInputs ++ [ python3Packages.hatchling ];
});
disnake_paginator = python3Packages.buildPythonPackage {
pname = "disnake-paginator";
version = "1.0.8";
src = self.pins.disnake-paginator;
pyproject = true;
build-system = [ python3Packages.setuptools ];
propagatedBuildInputs = [
disnake
];
doCheck = false;
};
in
python3Packages.buildPythonApplication {
pname = "errornocord";
version = "0.1.0";
src = lib.cleanSource ./.;
pyproject = true;
build-system = [ python3Packages.setuptools ];
propagatedBuildInputs = with python3Packages; [
aiohttp
audioop-lts
disnake
disnake_paginator
psutil
typing-extensions
youtube-transcript-api
yt-dlp
];
doCheck = false;
}

0
errornocord/__init__.py Normal file
View File

View File

@@ -2,7 +2,7 @@ import argparse
import contextlib
import io
import utils
from . import utils
class ArgumentParser:

View File

@@ -4,8 +4,7 @@ from typing import ClassVar, Optional
import disnake
from constants import BAR_LENGTH, EMBED_COLOR
from ..constants import BAR_LENGTH, EMBED_COLOR
from .utils import format_duration
from .youtubedl import YTDLSource

View File

@@ -4,8 +4,7 @@ from typing import Any, Optional
import disnake
import yt_dlp
from constants import YTDL_OPTIONS
from ..constants import YTDL_OPTIONS
from .discord import PCMVolumeTransformer, TrackedAudioSource
ytdl = yt_dlp.YoutubeDL(YTDL_OPTIONS)

View File

@@ -6,11 +6,10 @@ import disnake
import psutil
from yt_dlp import version
import arguments
import commands
from constants import EMBED_COLOR
from state import client, start_time
from utils import format_duration, reply, surround
from .. import arguments, commands
from ..constants import EMBED_COLOR
from ..state import client, start_time
from ..utils import format_duration, reply, surround
async def status(message):

View File

@@ -3,11 +3,9 @@ import re
import aiohttp
import disnake
import arguments
import commands
import utils
from constants import APPLICATION_FLAGS, BADGE_EMOJIS, EMBED_COLOR, PUBLIC_FLAGS
from state import client
from .. import arguments, commands, utils
from ..constants import APPLICATION_FLAGS, BADGE_EMOJIS, EMBED_COLOR, PUBLIC_FLAGS
from ..state import client
async def lookup(message):

View File

@@ -1,7 +1,7 @@
from enum import Enum
from functools import lru_cache
import constants
from .. import constants
class Command(Enum):

View File

@@ -1,5 +1,4 @@
import utils
from ... import utils
from .utils import command_allowed

View File

@@ -1,12 +1,8 @@
import disnake_paginator
import arguments
import commands
import sponsorblock
import utils
from constants import EMBED_COLOR
from state import players
from ... import arguments, commands, sponsorblock, utils
from ...constants import EMBED_COLOR
from ...state import players
from .utils import command_allowed

View File

@@ -3,13 +3,9 @@ import itertools
import disnake
import disnake_paginator
import arguments
import audio
import commands
import utils
from constants import EMBED_COLOR
from state import client, players, trusted_users
from ... import arguments, audio, commands, utils
from ...constants import EMBED_COLOR
from ...state import client, players, trusted_users
from .playback import resume
from .utils import command_allowed, ensure_joined, play_next

View File

@@ -1,11 +1,8 @@
import disnake
import audio
import sponsorblock
import utils
from constants import EMBED_COLOR, SPONSORBLOCK_CATEGORY_NAMES
from state import players
from ... import audio, sponsorblock, utils
from ...constants import EMBED_COLOR, SPONSORBLOCK_CATEGORY_NAMES
from ...state import players
from .utils import command_allowed

View File

@@ -2,8 +2,8 @@ from logging import error
import disnake
import utils
from state import client, players
from ... import utils
from ...state import client, players
def play_after_callback(e, message, once):

View File

@@ -12,11 +12,10 @@ from logging import debug
import disnake
import disnake_paginator
import commands
import utils
from commands import Command as C
from constants import EMBED_COLOR, OWNERS, PREFIX, RELOADABLE_MODULES
from state import client, command_cooldowns, command_locks, idle_tracker
from . import commands, utils
from .commands import Command as C
from .constants import EMBED_COLOR, OWNERS, PREFIX, RELOADABLE_MODULES
from .state import client, command_cooldowns, command_locks, idle_tracker
async def on_message(message, edited=False):

View File

@@ -2,11 +2,8 @@ import asyncio
import threading
from logging import debug, info, warning
import commands
import core
import fun
import tasks
from state import client
from . import commands, core, fun, tasks
from .state import client
def prepare():

View File

@@ -1,7 +1,7 @@
import random
import commands
from constants import REACTIONS
from . import commands
from .constants import REACTIONS
async def on_message(message):

View File

@@ -1,10 +1,10 @@
import logging
import constants
import events
from state import client
from . import constants, events
from .state import client
if __name__ == "__main__":
def main():
logging.basicConfig(
format=(
"%(asctime)s %(levelname)s %(name)s:%(module)s %(message)s"
@@ -18,3 +18,7 @@ if __name__ == "__main__":
events.prepare()
client.run(constants.SECRETS["TOKEN"])
if __name__ == "__main__":
main()

View File

@@ -3,7 +3,7 @@ import json
import aiohttp
from state import sponsorblock_cache
from .state import sponsorblock_cache
categories = json.dumps(
[

View File

@@ -2,7 +2,7 @@ import time
import disnake
from utils import LimitedSizeDict
from .utils import LimitedSizeDict
intents = disnake.Intents.default()
intents.message_content = True

View File

@@ -4,7 +4,7 @@ from logging import debug, error
import disnake
from state import client, idle_tracker, players
from .state import client, idle_tracker, players
async def cleanup():

View File

@@ -1,6 +1,6 @@
from collections import OrderedDict
from constants import SECRETS
from ..constants import SECRETS
def surround(inner: str, outer="```") -> str:

View File

@@ -1,13 +1,12 @@
import ctypes
import time
from logging import debug, error
from pathlib import Path
import disnake
import commands
from constants import OWNERS
from state import command_cooldowns, message_responses
from .. import commands
from ..constants import OWNERS
from ..state import command_cooldowns, message_responses
def cooldown(message, cooldown_time: int):

61
flake.lock generated Normal file
View File

@@ -0,0 +1,61 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1772408722,
"narHash": "sha256-rHuJtdcOjK7rAHpHphUb1iCvgkU3GpfvicLMwwnfMT0=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "f20dc5d9b8027381c474144ecabc9034d6a839a3",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1773821835,
"narHash": "sha256-TJ3lSQtW0E2JrznGVm8hOQGVpXjJyXY2guAxku2O9A4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b40629efe5d6ec48dd1efba650c797ddbd39ace0",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1772328832,
"narHash": "sha256-e+/T/pmEkLP6BHhYjx6GmwP5ivonQQn0bJdH9YrRB+Q=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "c185c7a5e5dd8f9add5b2f8ebeff00888b070742",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

41
flake.nix Normal file
View File

@@ -0,0 +1,41 @@
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs =
{
flake-parts,
self,
...
}@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-linux"
"x86_64-linux"
];
perSystem =
{ pkgs, self', ... }:
{
devShells.default = pkgs.mkShell {
name = "errornocord";
buildInputs = [
self'.packages.default
];
};
packages = rec {
errornocord = pkgs.callPackage ./. { inherit self; };
default = errornocord;
};
};
flake.pins = import ./npins;
};
description = "Hot-reloadable Discord music bot";
}

249
npins/default.nix Normal file
View File

@@ -0,0 +1,249 @@
/*
This file is provided under the MIT licence:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
# Generated by npins. Do not modify; will be overwritten regularly
let
# Backwards-compatibly make something that previously didn't take any arguments take some
# The function must return an attrset, and will unfortunately be eagerly evaluated
# Same thing, but it catches eval errors on the default argument so that one may still call it with other arguments
mkFunctor =
fn:
let
e = builtins.tryEval (fn { });
in
(if e.success then e.value else { error = fn { }; }) // { __functor = _self: fn; };
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
range =
first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
concatStrings = builtins.concatStringsSep "";
# If the environment variable NPINS_OVERRIDE_${name} is set, then use
# the path directly as opposed to the fetched source.
# (Taken from Niv for compatibility)
mayOverride =
name: path:
let
envVarName = "NPINS_OVERRIDE_${saneName}";
saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
ersatz = builtins.getEnv envVarName;
in
if ersatz == "" then
path
else
# this turns the string into an actual Nix path (for both absolute and
# relative paths)
builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" (
if builtins.substring 0 1 ersatz == "/" then
/. + ersatz
else
/. + builtins.getEnv "PWD" + "/${ersatz}"
);
mkSource =
name: spec:
{
pkgs ? null,
}:
assert spec ? type;
let
# Unify across builtin and pkgs fetchers.
# `fetchGit` requires a wrapper because of slight API differences.
fetchers =
if pkgs == null then
{
inherit (builtins) fetchTarball fetchurl;
# For some fucking reason, fetchGit has a different signature than the other builtin fetchers …
fetchGit = args: (builtins.fetchGit args).outPath;
}
else
{
fetchTarball =
{
url,
sha256,
}:
pkgs.fetchzip {
inherit url sha256;
extension = "tar";
};
inherit (pkgs) fetchurl;
fetchGit =
{
url,
submodules,
rev,
name,
narHash,
}:
pkgs.fetchgit {
inherit url rev name;
fetchSubmodules = submodules;
hash = narHash;
};
};
# Dispatch to the correct code path based on the type
path =
if spec.type == "Git" then
mkGitSource fetchers spec
else if spec.type == "GitRelease" then
mkGitSource fetchers spec
else if spec.type == "PyPi" then
mkPyPiSource fetchers spec
else if spec.type == "Channel" then
mkChannelSource fetchers spec
else if spec.type == "Tarball" then
mkTarballSource fetchers spec
else if spec.type == "Container" then
mkContainerSource pkgs spec
else
builtins.throw "Unknown source type ${spec.type}";
in
spec // { outPath = mayOverride name path; };
mkGitSource =
{
fetchTarball,
fetchGit,
...
}:
{
repository,
revision,
url ? null,
submodules,
hash,
...
}:
assert repository ? type;
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
# In the latter case, there we will always be an url to the tarball
if url != null && !submodules then
fetchTarball {
inherit url;
sha256 = hash;
}
else
let
url =
if repository.type == "Git" then
repository.url
else if repository.type == "GitHub" then
"https://github.com/${repository.owner}/${repository.repo}.git"
else if repository.type == "GitLab" then
"${repository.server}/${repository.repo_path}.git"
else if repository.type == "Forgejo" then
"${repository.server}/${repository.owner}/${repository.repo}.git"
else
throw "Unrecognized repository type ${repository.type}";
urlToName =
url: rev:
let
matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
short = builtins.substring 0 7 rev;
appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
in
"${if matched == null then "source" else builtins.head matched}${appendShort}";
name = urlToName url revision;
in
fetchGit {
rev = revision;
narHash = hash;
inherit name submodules url;
};
mkPyPiSource =
{ fetchurl, ... }:
{
url,
hash,
...
}:
fetchurl {
inherit url;
sha256 = hash;
};
mkChannelSource =
{ fetchTarball, ... }:
{
url,
hash,
...
}:
fetchTarball {
inherit url;
sha256 = hash;
};
mkTarballSource =
{ fetchTarball, ... }:
{
url,
locked_url ? url,
hash,
...
}:
fetchTarball {
url = locked_url;
sha256 = hash;
};
mkContainerSource =
pkgs:
{
image_name,
image_tag,
image_digest,
...
}:
if pkgs == null then
builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers"
else
pkgs.dockerTools.pullImage {
imageName = image_name;
imageDigest = image_digest;
finalImageTag = image_tag;
};
in
mkFunctor (
{
input ? ./sources.json,
}:
let
data =
if builtins.isPath input then
# while `readFile` will throw an error anyways if the path doesn't exist,
# we still need to check beforehand because *our* error can be caught but not the one from the builtin
# *piegames sighs*
if builtins.pathExists input then
builtins.fromJSON (builtins.readFile input)
else
throw "Input path ${toString input} does not exist"
else if builtins.isAttrs input then
input
else
throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset";
version = data.version;
in
if version == 7 then
builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins
else
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
)

26
npins/sources.json Normal file
View File

@@ -0,0 +1,26 @@
{
"pins": {
"disnake": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "DisnakeDev",
"repo": "disnake"
},
"branch": "master",
"submodules": false,
"revision": "79afc2d8673299f43636730d4a1518e7901f95fa",
"url": "https://github.com/DisnakeDev/disnake/archive/79afc2d8673299f43636730d4a1518e7901f95fa.tar.gz",
"hash": "sha256-7gsHFnqTyANdV+eosLI4MlzsMyebLdYZShEVObJPhl8="
},
"disnake-paginator": {
"type": "PyPi",
"name": "disnake-paginator",
"version_upper_bound": null,
"version": "1.0.8",
"url": "https://files.pythonhosted.org/packages/8c/db/3a86b247c7653a3f1676d16a316daf400edcf76295098ab60544f2a8f8b7/disnake_paginator-1.0.8.tar.gz",
"hash": "sha256-Sn0qbKNkJIdX8GCRRRPxwWutBtG9c1Zt7JnQAsl5I4s="
}
},
"version": 7
}

10
pyproject.toml Normal file
View File

@@ -0,0 +1,10 @@
[project]
name = "errornocord"
version = "0.1.0"
[project.scripts]
errornocord = "errornocord.main:main"
[tool.setuptools.packages.find]
where = ["."]
include = ["errornocord*"]