1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00

feat: independence from stockholm

This commit is contained in:
2023-03-26 19:24:38 +02:00
parent f805550ff8
commit 13e674389d
18 changed files with 651 additions and 171 deletions

View File

@@ -0,0 +1,23 @@
{pkgs}:
pkgs.symlinkJoin {
name = "cyberlocker-tools";
paths = [
(pkgs.writers.writeDashBin "cput" ''
set -efu
path=''${1:-$(hostname)}
path=$(echo "/$path" | sed -E 's:/+:/:')
url=http://c.r$path
${pkgs.curl}/bin/curl -fSs --data-binary @- "$url"
echo "$url"
'')
(pkgs.writers.writeDashBin "cdel" ''
set -efu
path=$1
path=$(echo "/$path" | sed -E 's:/+:/:')
url=http://c.r$path
${pkgs.curl}/bin/curl -f -X DELETE "$url"
'')
];
}

43
packages/dic.nix Normal file
View File

@@ -0,0 +1,43 @@
{
fetchgit,
lib,
stdenv,
coreutils,
curl,
gnugrep,
gnused,
util-linux,
}:
stdenv.mkDerivation {
name = "dic";
src = fetchgit {
url = https://cgit.ni.krebsco.de/dic;
rev = "refs/tags/v1.1.1";
sha256 = "1gbj967a5hj53fdkkxijqgwnl9hb8kskz0cmpjq7v65ffz3v6vag";
};
phases = [
"unpackPhase"
"installPhase"
];
installPhase = let
path = lib.makeBinPath [
coreutils
curl
gnused
gnugrep
util-linux
];
in ''
mkdir -p $out/bin
sed \
's,^main() {$,&\n PATH=${path}; export PATH,' \
< ./dic \
> $out/bin/dic
chmod +x $out/bin/dic
'';
}

49
packages/hc.nix Normal file
View File

@@ -0,0 +1,49 @@
{
fetchgit,
lib,
makeWrapper,
stdenv,
coreutils,
findutils,
gawk,
gnugrep,
qrencode,
texlive,
utillinux,
zbar,
}:
stdenv.mkDerivation rec {
name = "hc-${meta.version}";
src = fetchgit {
url = "https://cgit.krebsco.de/hc";
rev = "refs/tags/v${meta.version}";
sha256 = "09349gja22p0j3xs082kp0fnaaada14bafszn4r3q7rg1id2slfb";
};
nativeBuildInputs = [makeWrapper];
buildPhase = null;
installPhase = ''
mkdir -p $out/bin
cp $src/bin/hc $out/bin/hc
wrapProgram $out/bin/hc \
--prefix PATH : ${lib.makeBinPath [
coreutils
findutils
gawk
gnugrep
qrencode
texlive.combined.scheme-full
utillinux
zbar
]}
'';
meta = {
version = "1.0.0";
};
}

31
packages/htgen.nix Normal file
View File

@@ -0,0 +1,31 @@
{
fetchgit,
lib,
pkgs,
stdenv,
}:
stdenv.mkDerivation rec {
pname = "htgen";
version = "1.3.1";
src = fetchgit {
url = "http://cgit.krebsco.de/htgen";
rev = "refs/tags/${version}";
sha256 = "0ml8kp89bwkrwy6iqclzyhxgv2qn9dcpwaafbmsr4mgcl70zx22r";
};
installPhase = ''
mkdir -p $out/bin
{
echo '#! ${pkgs.dash}/bin/dash'
echo 'export PATH=${lib.makeBinPath [
pkgs.coreutils
pkgs.jq
pkgs.ucspi-tcp
]}''${PATH+":$PATH"}'
sed 's:^Server=htgen$:&/${version}:' htgen
} > $out/bin/htgen
chmod +x $out/bin/htgen
cp -r examples $out
'';
}

9
packages/kpaste.nix Normal file
View File

@@ -0,0 +1,9 @@
{
curl,
gnused,
writers,
}:
writers.writeDashBin "kpaste" ''
${curl}/bin/curl -sS http://p.r --data-binary @"''${1:--}" |
${gnused}/bin/sed '$ {p;s|http://p.r|https://p.krebsco.de|}'
''

View File

@@ -9,6 +9,9 @@ writers.writeDashBin "timer" ''
echo "Usage: $0 TIME MESSAGE" 1>&2
exit 1
}
time=$(echo "$1" | ${bc}/bin/bc)
echo "sleeping $time seconds, then saying: $2"
${coreutils}/bin/sleep "$time" && ${espeak}/bin/espeak -v german-mbrola-6 "$2"
${coreutils}/bin/sleep "$time" && {
echo "$2" | ${espeak}/bin/espeak -v german-mbrola-6
}
''

17
packages/untilport.nix Normal file
View File

@@ -0,0 +1,17 @@
{pkgs, ...}:
pkgs.writers.writeDashBin "untilport" ''
set -euf
usage() {
echo 'untiport $target $port'
echo 'Sleeps until the destinated port is reachable.'
echo 'ex: untilport google.de 80 && echo "google is now reachable"'
}
if [ $# -ne 2 ]; then
usage
else
until ${pkgs.libressl.nc}/bin/nc -z "$@"; do sleep 1; done
fi
''

View File

@@ -0,0 +1,177 @@
{
pkgs,
lib,
...
} @ args: let
# config cannot be declared in the input attribute set because that would
# cause callPackage to inject the wrong config. Instead, get it from ...
# via args.
config = args.config or {};
lib =
args.lib
// rec {
attrPaths = let
recurse = path: value:
if builtins.isAttrs value
then lib.mapAttrsToList (name: recurse (path ++ [name])) value
else [(lib.nameValuePair path value)];
in
attrs: lib.flatten (recurse [] attrs);
attrPathsSep = sep: attrs: lib.listToAttrs (map (x: x // {name = lib.concatStringsSep sep x.name;}) (attrPaths attrs));
toWeechatValue = x:
{
bool = builtins.toJSON x;
string = x;
list = lib.concatMapStringsSep "," toWeechatValue x;
int = toString x;
}
.${builtins.typeOf x};
setCommand = name: value: "/set ${name} \"${toWeechatValue value}\"";
filterAddreplace = name: filter: "/filter addreplace ${name} ${filter.buffer} ${toWeechatValue filter.tags} ${filter.regex}";
};
cfg = eval.config;
eval = lib.evalModules {
modules = lib.singleton {
_file = toString ./default.nix;
imports = lib.singleton config;
options = {
scripts = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [];
description = ''
some stuff from pkgs.weechatScripts
'';
};
settings = lib.mkOption {
type = (pkgs.formats.json {}).type;
description = ''
your weechat config in nix-style syntax.
secrets can be defined with \''${my.secret.value}
'';
default = {};
example = {
irc.server_default.nicks = "rick_\\\${sec.data.foo}";
irc.server_default.msg_part = "ciao kakao";
irc.server_default.msg_quit = "tschö mit \\\${sec.data.foo}";
irc.look.color_nicks_in_nicklist = true;
matrix.server.nibbana = {
address = "nibbana.jp";
};
irc.server.hackint = {
address = "irc.hackint.org/6697";
ssl = true;
autoconnect = true;
autojoin = ["#krebs"];
};
weechat.bar.buflist.hidden = true;
irc.server.hackint.command = lib.concatStringsSep "\\;" [
"/msg nickserv IDENTIFY \\\${sec.data.hackint_password}"
"/msg nickserv SET CLOAK ON"
];
filters.playlist_topic = {
buffer = "irc.*.#the_playlist";
tags = ["irc_topic"];
regex = "*";
};
relay = {
port.weechat = 9000;
network.password = "hunter2";
};
alias.cmd.mod = "quote omode $channel +o $nick";
secure.test.passphrase_command = "echo lol1234123124";
};
};
extraCommands = lib.mkOption {
type = lib.types.lines;
default = "";
};
files = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
default = {};
example = lib.literalExpression ''
{
"sec.conf" = toString (pkgs.writeText "sec.conf" '''
[crypt]
cipher = aes256
hash_algo = sha256
passphrase_command = ""
salt = on
[data]
__passphrase__ = off
foo = "bar"
''');
}
'';
};
};
};
};
setFile = pkgs.writeText "weechat.set" (
lib.optionalString (cfg.settings != {})
(lib.concatStringsSep "\n" (
lib.optionals
(cfg.settings.irc or {} != {})
(lib.mapAttrsToList
(name: server: "/server add ${name} ${lib.toWeechatValue server.addresses}")
cfg.settings.irc.server)
++ lib.optionals
(cfg.settings.matrix or {} != {})
(lib.mapAttrsToList
(name: server: "/matrix server add ${name} ${server.address}")
cfg.settings.matrix.server)
++ lib.mapAttrsToList lib.setCommand (lib.attrPathsSep "." cfg.settings)
++ lib.optionals
(cfg.settings.filters or {} != {})
(lib.mapAttrsToList lib.filterAddreplace cfg.settings.filters)
++ lib.singleton cfg.extraCommands
))
);
weechat = pkgs.weechat.override {
configure = _: {
init = "/exec -oc cat ${setFile}";
scripts = cfg.scripts;
};
};
wrapper = pkgs.writers.writeDashBin "weechat" ''
CONFDIR=''${XDG_CONFIG_HOME:-$HOME/.config}/weechat
${pkgs.coreutils}/bin/mkdir -p "$CONFDIR"
${
lib.concatStringsSep "\n"
(
lib.mapAttrsToList
(name: target:
/*
sh
*/
''
${pkgs.coreutils}/bin/cp ${lib.escapeShellArg target} "$CONFDIR"/${lib.escapeShellArg name}
${pkgs.coreutils}/bin/chmod +w "$CONFDIR"/${lib.escapeShellArg name}
'')
cfg.files
)
}
exec ${weechat}/bin/weechat "$@"
'';
in
pkgs.symlinkJoin {
name = "weechat-configured";
paths = [
wrapper
pkgs.weechat
];
postBuild = ''
ln -s ${setFile} $out/weechat.set
'';
}