From 13e674389ddbc9f3925002aeb3fbfefff6ebf1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Sun, 26 Mar 2023 19:24:38 +0200 Subject: [PATCH] feat: independence from stockholm --- configs/default.nix | 5 +- configs/packages.nix | 10 +- configs/power-action.nix | 4 +- flake.lock | 171 ++++++++--------------------- flake.nix | 13 ++- modules/htgen.nix | 47 ++++++++ modules/power-action.nix | 94 ++++++++++++++++ modules/retiolum.nix | 72 +++++++++++++ packages/cyberlocker-tools.nix | 23 ++++ packages/dic.nix | 43 ++++++++ packages/hc.nix | 49 +++++++++ packages/htgen.nix | 31 ++++++ packages/kpaste.nix | 9 ++ packages/timer.nix | 5 +- packages/untilport.nix | 17 +++ packages/weechat-declarative.nix | 177 +++++++++++++++++++++++++++++++ systems/makanek/tarot.nix | 48 ++++----- systems/makanek/weechat.nix | 4 +- 18 files changed, 651 insertions(+), 171 deletions(-) create mode 100644 modules/htgen.nix create mode 100644 modules/power-action.nix create mode 100644 modules/retiolum.nix create mode 100644 packages/cyberlocker-tools.nix create mode 100644 packages/dic.nix create mode 100644 packages/hc.nix create mode 100644 packages/htgen.nix create mode 100644 packages/kpaste.nix create mode 100644 packages/untilport.nix create mode 100644 packages/weechat-declarative.nix diff --git a/configs/default.nix b/configs/default.nix index 4a1b5fd..86dd3ff 100644 --- a/configs/default.nix +++ b/configs/default.nix @@ -13,10 +13,7 @@ in { imports = [ inputs.self.nixosModules.system-dependent inputs.self.nixosModules.traadfri - inputs.stockholm.nixosModules.power-action - { - nixpkgs.config.overlays = [inputs.nix-writers]; - } + inputs.self.nixosModules.power-action { boot.supportedFilesystems = ["ntfs"]; } diff --git a/configs/packages.nix b/configs/packages.nix index de949e1..53a0efd 100644 --- a/configs/packages.nix +++ b/configs/packages.nix @@ -134,7 +134,7 @@ in { okular # the word is nucular xournalpp # for annotating pdfs pdfpc # presenter console for pdf slides - inputs.stockholm.packages.x86_64-linux.hc # print files as qr codes + niveumPackages.hc # print files as qr codes yt-dlp espeak bc # calculator @@ -214,10 +214,10 @@ in { niveumPackages.nix-index-update #krebs - inputs.stockholm.packages.x86_64-linux.dic - inputs.stockholm.packages.x86_64-linux.cyberlocker-tools - inputs.stockholm.packages.x86_64-linux.untilport - inputs.stockholm.packages.x86_64-linux.kpaste + niveumPackages.dic + niveumPackages.cyberlocker-tools + niveumPackages.untilport + niveumPackages.kpaste config.nur.repos.mic92.ircsink (python3.withPackages (py: [ diff --git a/configs/power-action.nix b/configs/power-action.nix index 794bee0..b466908 100644 --- a/configs/power-action.nix +++ b/configs/power-action.nix @@ -5,7 +5,7 @@ }: let suspend = pkgs.writers.writeDash "suspend" "${pkgs.systemd}/bin/systemctl suspend"; in { - krebs.power-action = { + services.power-action = { enable = true; plans.suspend = { upperLimit = 7; @@ -19,6 +19,6 @@ in { }; security.sudo.extraConfig = '' - ${config.krebs.power-action.user} ALL= (root) NOPASSWD: ${suspend} + ${config.services.power-action.user} ALL= (root) NOPASSWD: ${suspend} ''; } diff --git a/flake.lock b/flake.lock index 36175f8..8520be2 100644 --- a/flake.lock +++ b/flake.lock @@ -74,36 +74,6 @@ "type": "github" } }, - "flake-utils_10": { - "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_11": { - "locked": { - "lastModified": 1676283394, - "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "flake-utils_2": { "locked": { "lastModified": 1659877975, @@ -196,11 +166,11 @@ }, "flake-utils_8": { "locked": { - "lastModified": 1676283394, - "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", "owner": "numtide", "repo": "flake-utils", - "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", "type": "github" }, "original": { @@ -232,11 +202,11 @@ "utils": "utils" }, "locked": { - "lastModified": 1679067101, - "narHash": "sha256-tMI1inGT9u4KWQml0w30dhWqQPlth1e9K/68sfDkEQA=", + "lastModified": 1679738842, + "narHash": "sha256-CvqRbsyDW756EskojZptDU590rez29RcHDV3ezoze08=", "owner": "nix-community", "repo": "home-manager", - "rev": "9154cd519a8942728038819682d6b3ff33f321bb", + "rev": "83110c259889230b324bb2d35bef78bf5f214a1f", "type": "github" }, "original": { @@ -320,25 +290,6 @@ "type": "github" } }, - "nix-writers": { - "inputs": { - "flake-utils": "flake-utils_8", - "nixpkgs": "nixpkgs_7" - }, - "locked": { - "lastModified": 1677612737, - "narHash": "sha256-UaCKZ4PbMZU6UZH7XNFcjRtd5jheswl66rjZDBfQgp8=", - "ref": "refs/heads/master", - "rev": "66a1f6833464bbb121b6d94247ad769f277351f8", - "revCount": 39, - "type": "git", - "url": "https://cgit.krebsco.de/nix-writers" - }, - "original": { - "type": "git", - "url": "https://cgit.krebsco.de/nix-writers" - } - }, "nixinate": { "inputs": { "nixpkgs": [ @@ -375,22 +326,6 @@ "type": "github" } }, - "nixpkgs_10": { - "locked": { - "lastModified": 1669418739, - "narHash": "sha256-T86oFvcUIRwHWBWUt7WjaP4BP/3lDGbv5AppQSI1FkI=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "695b3515251873e0a7e2021add4bba643c56cde3", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "695b3515251873e0a7e2021add4bba643c56cde3", - "type": "github" - } - }, "nixpkgs_2": { "locked": { "lastModified": 1665296151, @@ -425,11 +360,11 @@ }, "nixpkgs_4": { "locked": { - "lastModified": 1679318992, - "narHash": "sha256-uoj5Oy6hruIHuxzfQZtcalObe5kPrX9v+ClUMFEOzmE=", + "lastModified": 1679748960, + "narHash": "sha256-BP8XcYHyj1NxQi04RpyNW8e7KiXSoI+Fy1tXIK2GfdA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e2c97799da5f5cd87adfa5017fba971771e123ef", + "rev": "da26ae9f6ce2c9ab380c0f394488892616fc5a6a", "type": "github" }, "original": { @@ -471,21 +406,6 @@ } }, "nixpkgs_7": { - "locked": { - "lastModified": 1677608380, - "narHash": "sha256-k82O23qBAK+43X0KSBjsMYXG2x4kWWXeAmpPTc2KRGY=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "4aba90e89f6d4ac6138939961f62842bd94ec929", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_8": { "locked": { "lastModified": 1659446231, "narHash": "sha256-hekabNdTdgR/iLsgce5TGWmfIDZ86qjPhxDg/8TlzhE=", @@ -501,7 +421,7 @@ "type": "github" } }, - "nixpkgs_9": { + "nixpkgs_8": { "locked": { "lastModified": 1665296151, "narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=", @@ -517,13 +437,29 @@ "type": "github" } }, + "nixpkgs_9": { + "locked": { + "lastModified": 1669418739, + "narHash": "sha256-T86oFvcUIRwHWBWUt7WjaP4BP/3lDGbv5AppQSI1FkI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "695b3515251873e0a7e2021add4bba643c56cde3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "695b3515251873e0a7e2021add4bba643c56cde3", + "type": "github" + } + }, "nur": { "locked": { - "lastModified": 1679463968, - "narHash": "sha256-SBNgZb/Gc/9RbEvxz+jQ2o6nWNt1gzTwAw16lShT/ho=", + "lastModified": 1679849267, + "narHash": "sha256-AVcqq8qHp7WOYBJY5loLog0O4icNayrd0D9hwtpAnQQ=", "owner": "nix-community", "repo": "NUR", - "rev": "52e6a7748992cde538e52f3fa4737f64b5bec03d", + "rev": "637e2988a940a4ae8a094970fddb60a7a9e6732a", "type": "github" }, "original": { @@ -554,11 +490,11 @@ }, "retiolum": { "locked": { - "lastModified": 1678773616, - "narHash": "sha256-POr8rTMNmcnwe2tnWxhXG7T3W4wQp8cjN+TFpwsiLrs=", + "lastModified": 1679769542, + "narHash": "sha256-j8yR03AKjkgA5kAptjB5felipXT7wTPwemq66M+iB10=", "ref": "refs/heads/master", - "rev": "5492459f4516b89686e1d8086c9b46db39b6902b", - "revCount": 289, + "rev": "11b764aa2d2e1f6f6392d00806dad7e5cc3ef370", + "revCount": 291, "type": "git", "url": "https://git.thalheim.io/Mic92/retiolum" }, @@ -580,7 +516,6 @@ "recht": "recht", "retiolum": "retiolum", "scripts": "scripts", - "stockholm": "stockholm", "telebots": "telebots", "tinc-graph": "tinc-graph", "traadfri": "traadfri", @@ -646,8 +581,8 @@ }, "rust-overlay_4": { "inputs": { - "flake-utils": "flake-utils_10", - "nixpkgs": "nixpkgs_9" + "flake-utils": "flake-utils_8", + "nixpkgs": "nixpkgs_8" }, "locked": { "lastModified": 1677119371, @@ -691,32 +626,10 @@ "type": "github" } }, - "stockholm": { - "inputs": { - "flake-utils": "flake-utils_7", - "nix-writers": "nix-writers", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1677747908, - "narHash": "sha256-PNXb97q62yK61alFlOeohpro8WLxt2ay1jYUTrFMgPA=", - "owner": "kmein", - "repo": "stockholm", - "rev": "f8575e3af5b6d1fbd60d89c4df2e120b77b923c5", - "type": "github" - }, - "original": { - "owner": "kmein", - "repo": "stockholm", - "type": "github" - } - }, "telebots": { "inputs": { - "flake-utils": "flake-utils_9", - "nixpkgs": "nixpkgs_8" + "flake-utils": "flake-utils_7", + "nixpkgs": "nixpkgs_7" }, "locked": { "lastModified": 1677156381, @@ -758,8 +671,8 @@ }, "traadfri": { "inputs": { - "flake-utils": "flake-utils_11", - "nixpkgs": "nixpkgs_10" + "flake-utils": "flake-utils_9", + "nixpkgs": "nixpkgs_9" }, "locked": { "lastModified": 1677165914, @@ -793,11 +706,11 @@ "voidrice": { "flake": false, "locked": { - "lastModified": 1679320229, - "narHash": "sha256-M4D8bR9PJnvBfx4EN06bj4Fr0yXSi9po09aT9v3D7QQ=", + "lastModified": 1679694583, + "narHash": "sha256-W0TVLjfMWHjy8OFjkBp4jGZnIczTOYBnRMM/upn6BeE=", "owner": "Lukesmithxyz", "repo": "voidrice", - "rev": "0e2cd987dc2659c5c08a834a7cb4c2478b49cf31", + "rev": "749f74f84ef1ec1b15c9003c23120dc5c4baaa35", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 7bb160d..72a5591 100644 --- a/flake.nix +++ b/flake.nix @@ -17,14 +17,12 @@ tinc-graph.url = "github:kmein/tinc-graph"; traadfri.url = "github:kmein/traadfri"; voidrice.url = "github:Lukesmithxyz/voidrice"; - stockholm.url = "github:kmein/stockholm"; agenix.inputs.nixpkgs.follows = "nixpkgs"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; menstruation-backend.inputs.flake-utils.follows = "flake-utils"; menstruation-backend.inputs.nixpkgs.follows = "nixpkgs"; nixinate.inputs.nixpkgs.follows = "nixpkgs"; - stockholm.inputs.nixpkgs.follows = "nixpkgs"; tinc-graph.inputs.flake-utils.follows = "flake-utils"; tinc-graph.inputs.nixpkgs.follows = "nixpkgs"; voidrice.flake = false; @@ -39,17 +37,18 @@ agenix, retiolum, flake-utils, - stockholm, ... }: { apps = nixinate.nixinate.x86_64-linux self; nixosModules = { + htgen = import modules/htgen.nix; moodle-dl = import modules/moodle-dl.nix; networkmanager-declarative = import modules/networkmanager-declarative.nix; passport = import modules/passport.nix; panoptikon = import modules/panoptikon.nix; + power-action = import modules/power-action.nix; system-dependent = import modules/system-dependent.nix; telegram-bot = import modules/telegram-bot.nix; traadfri = import modules/traadfri.nix; @@ -121,7 +120,7 @@ } systems/makanek/configuration.nix inputs.self.nixosModules.telegram-bot - inputs.stockholm.nixosModules.htgen + inputs.self.nixosModules.htgen inputs.self.nixosModules.passport agenix.nixosModules.default retiolum.nixosModules.retiolum @@ -209,6 +208,7 @@ betacode = pkgs.callPackage packages/betacode.nix {}; cheat-sh = pkgs.callPackage packages/cheat-sh.nix {}; closest = pkgs.callPackage packages/closest {}; + cyberlocker-tools = pkgs.callPackage packages/cyberlocker-tools.nix {}; default-gateway = pkgs.callPackage packages/default-gateway.nix {}; depp = pkgs.callPackage packages/depp.nix {}; devanagari = pkgs.callPackage packages/devanagari {}; @@ -223,7 +223,9 @@ genius = pkgs.callPackage packages/genius.nix {}; gfs-fonts = pkgs.callPackage packages/gfs-fonts.nix {}; git-preview = pkgs.callPackage packages/git-preview.nix {}; + hc = pkgs.callPackage packages/hc.nix {}; heuretes = pkgs.callPackage packages/heuretes.nix {}; + htgen = pkgs.callPackage packages/htgen.nix {}; image-convert-favicon = pkgs.callPackage packages/image-convert-favicon.nix {}; image-convert-tolino = pkgs.callPackage packages/image-convert-tolino.nix {}; infschmv = pkgs.callPackage packages/infschmv.nix {}; @@ -234,6 +236,7 @@ k-lock = pkgs.callPackage packages/k-lock.nix {}; kirciuoklis = pkgs.callPackage packages/kirciuoklis.nix {}; klem = pkgs.callPackage packages/klem.nix {}; + kpaste = pkgs.callPackage packages/kpaste.nix {}; literature-quote = pkgs.callPackage packages/literature-quote.nix {}; mahlzeit = pkgs.haskellPackages.callPackage packages/mahlzeit.nix {}; man-pandoc = pkgs.callPackage packages/man/pandoc.nix {}; @@ -260,6 +263,7 @@ trans = pkgs.callPackage packages/trans.nix {}; ttspaste = pkgs.callPackage packages/ttspaste.nix {}; unicodmenu = pkgs.callPackage packages/unicodmenu.nix {}; + untilport = pkgs.callPackage packages/untilport.nix {}; vg = pkgs.callPackage packages/vg.nix {}; vimPlugins-cheat-sh-vim = pkgs.callPackage packages/vimPlugins/cheat-sh.nix {}; vimPlugins-icalendar-vim = pkgs.callPackage packages/vimPlugins/icalendar-vim.nix {}; @@ -271,6 +275,7 @@ vimPlugins-vim-mail = pkgs.callPackage packages/vimPlugins/vim-mail.nix {}; vimPlugins-vim-reason-plus = pkgs.callPackage packages/vimPlugins/vim-reason-plus.nix {}; vimv = pkgs.callPackage packages/vimv.nix {}; + weechat-declarative = pkgs.callPackage packages/weechat-declarative.nix {}; weechatScripts-hotlist2extern = pkgs.callPackage packages/weechatScripts/hotlist2extern.nix {}; wttr = pkgs.callPackage packages/wttr.nix {}; diff --git a/modules/htgen.nix b/modules/htgen.nix new file mode 100644 index 0000000..6f1e043 --- /dev/null +++ b/modules/htgen.nix @@ -0,0 +1,47 @@ +{ + config, + lib, + pkgs, + ... +}: let + htgen = pkgs.callPackage ../packages/htgen.nix {}; +in { + options.services.htgen = lib.mkOption { + default = {}; + type = lib.types.attrsOf (lib.types.submodule ({config, ...}: { + options = { + enable = lib.mkEnableOption "htgen-${config._module.args.name}"; + port = lib.mkOption { + type = lib.types.int; + }; + script = lib.mkOption { + type = lib.types.str; + }; + }; + })); + }; + config = { + systemd.services = + lib.mapAttrs' ( + name: cfg: + lib.nameValuePair "htgen-${name}" { + wantedBy = ["multi-user.target"]; + after = ["network.target"]; + environment = { + HOME = "/var/lib/htgen-${name}"; + HTGEN_PORT = toString cfg.port; + HTGEN_SCRIPT = cfg.script; + }; + serviceConfig = { + SyslogIdentifier = "htgen-${name}"; + DynamicUser = true; + StateDirectory = "htgen-${name}"; + PrivateTmp = true; + Restart = "always"; + ExecStart = "${htgen}/bin/htgen --serve"; + }; + } + ) + config.services.htgen; + }; +} diff --git a/modules/power-action.nix b/modules/power-action.nix new file mode 100644 index 0000000..71fd8f1 --- /dev/null +++ b/modules/power-action.nix @@ -0,0 +1,94 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; let + cfg = config.services.power-action; + + out = { + options.services.power-action = api; + config = lib.mkIf cfg.enable imp; + }; + + api = { + enable = mkEnableOption "power-action"; + battery = mkOption { + type = types.str; + default = "BAT0"; + }; + user = mkOption { + type = types.str; + default = "power-action"; + }; + startAt = mkOption { + type = types.str; + default = "*:0/1"; + }; + plans = mkOption { + type = with types; + attrsOf (submodule { + options = { + charging = mkOption { + type = nullOr bool; + default = null; + description = '' + check for charging status. + null = don't care + true = only if system is charging or unknown + false = only if system is discharging + ''; + }; + upperLimit = mkOption { + type = int; + }; + lowerLimit = mkOption { + type = int; + }; + action = mkOption { + type = path; + }; + }; + }); + }; + }; + + imp = { + systemd.services.power-action = { + serviceConfig = rec { + ExecStart = startScript; + User = cfg.user; + }; + startAt = cfg.startAt; + }; + }; + + startScript = pkgs.writers.writeDash "power-action" '' + set -euf + + power="$(${powerlvl})" + state="$(${state})" + ${concatStringsSep "\n" (mapAttrsToList writeRule cfg.plans)} + ''; + charging_check = plan: + if (plan.charging == null) + then "" + else if plan.charging + then ''&& [ "$state" = "true" ]'' + else ''&& ! [ "$state" = "true" ]''; + + writeRule = _: plan: "if [ $power -ge ${toString plan.lowerLimit} ] && [ $power -le ${toString plan.upperLimit} ] ${charging_check plan}; then ${plan.action}; fi"; + + powerlvl = pkgs.writers.writeDash "powerlvl" '' + cat /sys/class/power_supply/${cfg.battery}/capacity + ''; + + state = pkgs.writers.writeDash "state" '' + if [ "$(cat /sys/class/power_supply/${cfg.battery}/status)" = "Discharging" ] + then echo "false" + else echo "true" + fi + ''; +in + out diff --git a/modules/retiolum.nix b/modules/retiolum.nix new file mode 100644 index 0000000..908a356 --- /dev/null +++ b/modules/retiolum.nix @@ -0,0 +1,72 @@ +{ + config, + pkgs, + lib, + ... +}: +with lib; let + netname = "retiolum"; + cfg = config.networking.retiolum; +in { + options = { + networking.retiolum.ipv4 = mkOption { + type = types.str; + description = '' + own ipv4 address + ''; + }; + networking.retiolum.ipv6 = mkOption { + type = types.str; + description = '' + own ipv6 address + ''; + }; + networking.retiolum.nodename = mkOption { + type = types.str; + default = config.networking.hostName; + description = '' + tinc network name + ''; + }; + }; + + config = { + services.tinc.networks.${netname} = { + name = cfg.nodename; + hosts = + builtins.mapAttrs + (name: _: builtins.readFile "${}/${name}") + (builtins.readDir ); + rsaPrivateKeyFile = toString ; + ed25519PrivateKeyFile = toString ; + extraConfig = '' + LocalDiscovery = yes + AutoConnect = yes + ''; + }; + + networking.extraHosts = builtins.readFile (toString ); + + environment.systemPackages = [config.services.tinc.networks.${netname}.package]; + + networking.firewall = { + allowedTCPPorts = [655]; + allowedUDPPorts = [655]; + }; + #services.netdata.portcheck.checks.tinc.port = 655; + + systemd.network = { + enable = true; + networks = { + "${netname}".extraConfig = '' + [Match] + Name = tinc.${netname} + + [Network] + Address=${cfg.ipv4}/12 + Address=${cfg.ipv6}/16 + ''; + }; + }; + }; +} diff --git a/packages/cyberlocker-tools.nix b/packages/cyberlocker-tools.nix new file mode 100644 index 0000000..0c997ea --- /dev/null +++ b/packages/cyberlocker-tools.nix @@ -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" + '') + ]; +} diff --git a/packages/dic.nix b/packages/dic.nix new file mode 100644 index 0000000..334a5fc --- /dev/null +++ b/packages/dic.nix @@ -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 + ''; +} diff --git a/packages/hc.nix b/packages/hc.nix new file mode 100644 index 0000000..b481de8 --- /dev/null +++ b/packages/hc.nix @@ -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"; + }; +} diff --git a/packages/htgen.nix b/packages/htgen.nix new file mode 100644 index 0000000..7d129b0 --- /dev/null +++ b/packages/htgen.nix @@ -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 + ''; +} diff --git a/packages/kpaste.nix b/packages/kpaste.nix new file mode 100644 index 0000000..54d7f28 --- /dev/null +++ b/packages/kpaste.nix @@ -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|}' +'' diff --git a/packages/timer.nix b/packages/timer.nix index 5422b09..d743e56 100644 --- a/packages/timer.nix +++ b/packages/timer.nix @@ -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 + } '' diff --git a/packages/untilport.nix b/packages/untilport.nix new file mode 100644 index 0000000..0db755f --- /dev/null +++ b/packages/untilport.nix @@ -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 +'' diff --git a/packages/weechat-declarative.nix b/packages/weechat-declarative.nix new file mode 100644 index 0000000..b12eb9f --- /dev/null +++ b/packages/weechat-declarative.nix @@ -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 + ''; + } diff --git a/systems/makanek/tarot.nix b/systems/makanek/tarot.nix index aa344a7..d633310 100644 --- a/systems/makanek/tarot.nix +++ b/systems/makanek/tarot.nix @@ -15,32 +15,32 @@ sha256 = "1n2m53kjg2vj9dbr70b9jrsbqwdfrcb48l4wswn21549fi24g6dx"; }; in { - krebs.htgen.tarot = { + services.htgen.tarot = { port = tarotPort; - scriptFile = pkgs.writers.writeDash "tarot" '' - case "$Method $Request_URI" in - "GET /") - if item=$(${pkgs.findutils}/bin/find ${toString tarotFiles} -type f | ${pkgs.coreutils}/bin/shuf -n1); then - card=$(mktemp --tmpdir tarot.XXX) - trap 'rm $card' EXIT - reverse=$(${pkgs.coreutils}/bin/shuf -i0-1 -n1) - if [ "$reverse" -eq 1 ]; then - ${pkgs.imagemagick}/bin/convert -rotate 180 "$item" "$card" - else - ${pkgs.coreutils}/bin/cp "$item" "$card" + script = ''. ${pkgs.writers.writeDash "tarot" '' + case "$Method $Request_URI" in + "GET /") + if item=$(${pkgs.findutils}/bin/find ${toString tarotFiles} -type f | ${pkgs.coreutils}/bin/shuf -n1); then + card=$(mktemp --tmpdir tarot.XXX) + trap 'rm $card' EXIT + reverse=$(${pkgs.coreutils}/bin/shuf -i0-1 -n1) + if [ "$reverse" -eq 1 ]; then + ${pkgs.imagemagick}/bin/convert -rotate 180 "$item" "$card" + else + ${pkgs.coreutils}/bin/cp "$item" "$card" + fi + printf 'HTTP/1.1 200 OK\r\n' + printf 'Content-Type: %s\r\n' "$(${pkgs.file}/bin/file -ib "$card")" + printf 'Server: %s\r\n' "$Server" + printf 'Connection: close\r\n' + printf 'Content-Length: %d\r\n' $(${pkgs.coreutils}/bin/wc -c < "$card") + printf '\r\n' + cat "$card" + exit fi - printf 'HTTP/1.1 200 OK\r\n' - printf 'Content-Type: %s\r\n' "$(${pkgs.file}/bin/file -ib "$card")" - printf 'Server: %s\r\n' "$Server" - printf 'Connection: close\r\n' - printf 'Content-Length: %d\r\n' $(${pkgs.coreutils}/bin/wc -c < "$card") - printf '\r\n' - cat "$card" - exit - fi - ;; - esac - ''; + ;; + esac + ''}''; }; niveum.passport.services = [ diff --git a/systems/makanek/weechat.nix b/systems/makanek/weechat.nix index a911384..32d3024 100644 --- a/systems/makanek/weechat.nix +++ b/systems/makanek/weechat.nix @@ -1,11 +1,11 @@ { lib, pkgs, - inputs, ... }: let inherit (import ../../lib) kieran; weechatHome = "/var/lib/weechat"; + weechat-declarative = pkgs.callPackage ../../packages/weechat-declarative.nix {}; in { systemd.services.weechat = let tmux = pkgs.writers.writeDash "tmux" '' @@ -26,7 +26,7 @@ in { '' } "$@" ''; - weechat = inputs.stockholm.packages.x86_64-linux.weechat-declarative.override { + weechat = weechat-declarative.override { config = { scripts = [ pkgs.weechatScripts.weechat-autosort