use flake and direnv

This commit is contained in:
yen 2024-02-28 17:50:06 +01:00
parent 22d91491dc
commit 5147a56672
Signed by: yen
GPG Key ID: 120F272B9981E77F
5 changed files with 91 additions and 12 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake .

View File

@ -1,10 +0,0 @@
let
pkgs = import <nixpkgs> {};
in pkgs.mkShell {
packages = [
(pkgs.python3.withPackages (python-pkgs: [
python-pkgs.python-telegram-bot
]))
];
}

61
flake.lock generated Normal file
View File

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1709126324,
"narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "d465f4819400de7c8d874d50b982301f28a84605",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1709101946,
"narHash": "sha256-TsySgcWm/GlbYdL3AEva49ceeI2BdPQ7muwfYNr1fwo=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "d53c2037394da6fe98decca417fc8fda64bf2443",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

27
flake.nix Normal file
View File

@ -0,0 +1,27 @@
{
description = "Python3 telegram bot environment";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
python-telegram-bot
]);
in
{
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
pythonEnv
];
};
});
}

View File

@ -1,6 +1,6 @@
#!/usr/bin/python
from telegram.ext import Updater, CommandHandler, Filters
from telegram.ext import Updater, CommandHandler, filters
import os
from random import randrange
import sys
@ -93,7 +93,7 @@ def main():
updater.dispatcher.add_handler(CommandHandler("list", _list))
updater.dispatcher.add_handler(CommandHandler("get", get))
updater.dispatcher.add_handler(CommandHandler("random", random))
updater.dispatcher.add_handler(CommandHandler("save", save, Filters.reply))
updater.dispatcher.add_handler(CommandHandler("save", save, filters.REPLY))
updater.start_polling()
updater.idle()