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:
@@ -7,4 +7,4 @@ COPY . .
|
|||||||
|
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
CMD ["python", "main.py"]
|
CMD ["python", "-m", "errornocord.main"]
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
# ErrorNoCord
|
# ErrorNoCord
|
||||||
|
|
||||||
Discord music bot for testing purposes, with live reloading support
|
Hot-reloadable Discord music bot
|
||||||
|
|||||||
59
default.nix
Normal file
59
default.nix
Normal 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
0
errornocord/__init__.py
Normal file
@@ -2,7 +2,7 @@ import argparse
|
|||||||
import contextlib
|
import contextlib
|
||||||
import io
|
import io
|
||||||
|
|
||||||
import utils
|
from . import utils
|
||||||
|
|
||||||
|
|
||||||
class ArgumentParser:
|
class ArgumentParser:
|
||||||
@@ -4,8 +4,7 @@ from typing import ClassVar, Optional
|
|||||||
|
|
||||||
import disnake
|
import disnake
|
||||||
|
|
||||||
from constants import BAR_LENGTH, EMBED_COLOR
|
from ..constants import BAR_LENGTH, EMBED_COLOR
|
||||||
|
|
||||||
from .utils import format_duration
|
from .utils import format_duration
|
||||||
from .youtubedl import YTDLSource
|
from .youtubedl import YTDLSource
|
||||||
|
|
||||||
@@ -4,8 +4,7 @@ from typing import Any, Optional
|
|||||||
import disnake
|
import disnake
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
|
|
||||||
from constants import YTDL_OPTIONS
|
from ..constants import YTDL_OPTIONS
|
||||||
|
|
||||||
from .discord import PCMVolumeTransformer, TrackedAudioSource
|
from .discord import PCMVolumeTransformer, TrackedAudioSource
|
||||||
|
|
||||||
ytdl = yt_dlp.YoutubeDL(YTDL_OPTIONS)
|
ytdl = yt_dlp.YoutubeDL(YTDL_OPTIONS)
|
||||||
@@ -6,11 +6,10 @@ import disnake
|
|||||||
import psutil
|
import psutil
|
||||||
from yt_dlp import version
|
from yt_dlp import version
|
||||||
|
|
||||||
import arguments
|
from .. import arguments, commands
|
||||||
import commands
|
from ..constants import EMBED_COLOR
|
||||||
from constants import EMBED_COLOR
|
from ..state import client, start_time
|
||||||
from state import client, start_time
|
from ..utils import format_duration, reply, surround
|
||||||
from utils import format_duration, reply, surround
|
|
||||||
|
|
||||||
|
|
||||||
async def status(message):
|
async def status(message):
|
||||||
@@ -3,11 +3,9 @@ import re
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
import disnake
|
import disnake
|
||||||
|
|
||||||
import arguments
|
from .. import arguments, commands, utils
|
||||||
import commands
|
from ..constants import APPLICATION_FLAGS, BADGE_EMOJIS, EMBED_COLOR, PUBLIC_FLAGS
|
||||||
import utils
|
from ..state import client
|
||||||
from constants import APPLICATION_FLAGS, BADGE_EMOJIS, EMBED_COLOR, PUBLIC_FLAGS
|
|
||||||
from state import client
|
|
||||||
|
|
||||||
|
|
||||||
async def lookup(message):
|
async def lookup(message):
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
|
||||||
import constants
|
from .. import constants
|
||||||
|
|
||||||
|
|
||||||
class Command(Enum):
|
class Command(Enum):
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import utils
|
from ... import utils
|
||||||
|
|
||||||
from .utils import command_allowed
|
from .utils import command_allowed
|
||||||
|
|
||||||
|
|
||||||
@@ -1,12 +1,8 @@
|
|||||||
import disnake_paginator
|
import disnake_paginator
|
||||||
|
|
||||||
import arguments
|
from ... import arguments, commands, sponsorblock, utils
|
||||||
import commands
|
from ...constants import EMBED_COLOR
|
||||||
import sponsorblock
|
from ...state import players
|
||||||
import utils
|
|
||||||
from constants import EMBED_COLOR
|
|
||||||
from state import players
|
|
||||||
|
|
||||||
from .utils import command_allowed
|
from .utils import command_allowed
|
||||||
|
|
||||||
|
|
||||||
@@ -3,13 +3,9 @@ import itertools
|
|||||||
import disnake
|
import disnake
|
||||||
import disnake_paginator
|
import disnake_paginator
|
||||||
|
|
||||||
import arguments
|
from ... import arguments, audio, commands, utils
|
||||||
import audio
|
from ...constants import EMBED_COLOR
|
||||||
import commands
|
from ...state import client, players, trusted_users
|
||||||
import utils
|
|
||||||
from constants import EMBED_COLOR
|
|
||||||
from state import client, players, trusted_users
|
|
||||||
|
|
||||||
from .playback import resume
|
from .playback import resume
|
||||||
from .utils import command_allowed, ensure_joined, play_next
|
from .utils import command_allowed, ensure_joined, play_next
|
||||||
|
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
import disnake
|
import disnake
|
||||||
|
|
||||||
import audio
|
from ... import audio, sponsorblock, utils
|
||||||
import sponsorblock
|
from ...constants import EMBED_COLOR, SPONSORBLOCK_CATEGORY_NAMES
|
||||||
import utils
|
from ...state import players
|
||||||
from constants import EMBED_COLOR, SPONSORBLOCK_CATEGORY_NAMES
|
|
||||||
from state import players
|
|
||||||
|
|
||||||
from .utils import command_allowed
|
from .utils import command_allowed
|
||||||
|
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@ from logging import error
|
|||||||
|
|
||||||
import disnake
|
import disnake
|
||||||
|
|
||||||
import utils
|
from ... import utils
|
||||||
from state import client, players
|
from ...state import client, players
|
||||||
|
|
||||||
|
|
||||||
def play_after_callback(e, message, once):
|
def play_after_callback(e, message, once):
|
||||||
@@ -12,11 +12,10 @@ from logging import debug
|
|||||||
import disnake
|
import disnake
|
||||||
import disnake_paginator
|
import disnake_paginator
|
||||||
|
|
||||||
import commands
|
from . import commands, utils
|
||||||
import utils
|
from .commands import Command as C
|
||||||
from commands import Command as C
|
from .constants import EMBED_COLOR, OWNERS, PREFIX, RELOADABLE_MODULES
|
||||||
from constants import EMBED_COLOR, OWNERS, PREFIX, RELOADABLE_MODULES
|
from .state import client, command_cooldowns, command_locks, idle_tracker
|
||||||
from state import client, command_cooldowns, command_locks, idle_tracker
|
|
||||||
|
|
||||||
|
|
||||||
async def on_message(message, edited=False):
|
async def on_message(message, edited=False):
|
||||||
@@ -2,11 +2,8 @@ import asyncio
|
|||||||
import threading
|
import threading
|
||||||
from logging import debug, info, warning
|
from logging import debug, info, warning
|
||||||
|
|
||||||
import commands
|
from . import commands, core, fun, tasks
|
||||||
import core
|
from .state import client
|
||||||
import fun
|
|
||||||
import tasks
|
|
||||||
from state import client
|
|
||||||
|
|
||||||
|
|
||||||
def prepare():
|
def prepare():
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
import commands
|
from . import commands
|
||||||
from constants import REACTIONS
|
from .constants import REACTIONS
|
||||||
|
|
||||||
|
|
||||||
async def on_message(message):
|
async def on_message(message):
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import constants
|
from . import constants, events
|
||||||
import events
|
from .state import client
|
||||||
from state import client
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
|
def main():
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format=(
|
format=(
|
||||||
"%(asctime)s %(levelname)s %(name)s:%(module)s %(message)s"
|
"%(asctime)s %(levelname)s %(name)s:%(module)s %(message)s"
|
||||||
@@ -18,3 +18,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
events.prepare()
|
events.prepare()
|
||||||
client.run(constants.SECRETS["TOKEN"])
|
client.run(constants.SECRETS["TOKEN"])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -3,7 +3,7 @@ import json
|
|||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from state import sponsorblock_cache
|
from .state import sponsorblock_cache
|
||||||
|
|
||||||
categories = json.dumps(
|
categories = json.dumps(
|
||||||
[
|
[
|
||||||
@@ -2,7 +2,7 @@ import time
|
|||||||
|
|
||||||
import disnake
|
import disnake
|
||||||
|
|
||||||
from utils import LimitedSizeDict
|
from .utils import LimitedSizeDict
|
||||||
|
|
||||||
intents = disnake.Intents.default()
|
intents = disnake.Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
@@ -4,7 +4,7 @@ from logging import debug, error
|
|||||||
|
|
||||||
import disnake
|
import disnake
|
||||||
|
|
||||||
from state import client, idle_tracker, players
|
from .state import client, idle_tracker, players
|
||||||
|
|
||||||
|
|
||||||
async def cleanup():
|
async def cleanup():
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from constants import SECRETS
|
from ..constants import SECRETS
|
||||||
|
|
||||||
|
|
||||||
def surround(inner: str, outer="```") -> str:
|
def surround(inner: str, outer="```") -> str:
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
import ctypes
|
import ctypes
|
||||||
import time
|
import time
|
||||||
from logging import debug, error
|
from logging import debug, error
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import disnake
|
import disnake
|
||||||
|
|
||||||
import commands
|
from .. import commands
|
||||||
from constants import OWNERS
|
from ..constants import OWNERS
|
||||||
from state import command_cooldowns, message_responses
|
from ..state import command_cooldowns, message_responses
|
||||||
|
|
||||||
|
|
||||||
def cooldown(message, cooldown_time: int):
|
def cooldown(message, cooldown_time: int):
|
||||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal 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
41
flake.nix
Normal 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
249
npins/default.nix
Normal 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
26
npins/sources.json
Normal 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
10
pyproject.toml
Normal 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*"]
|
||||||
Reference in New Issue
Block a user