From 8fa5d38f8227c74a909a5162cff71b8958aacd2d Mon Sep 17 00:00:00 2001 From: osbm Date: Mon, 5 May 2025 15:15:21 +0300 Subject: [PATCH] add flake support --- flake.lock | 27 ++++++++++++++++++++ flake.nix | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..6ddbef9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1746332716, + "narHash": "sha256-VBmKSkmw9PYBCEGhBKzORjx+nwNZkPZyHcUHE21A/ws=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "6b1c028bce9c89e9824cde040d6986d428296055", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bcc54bb --- /dev/null +++ b/flake.nix @@ -0,0 +1,73 @@ +{ + description = "Backend development flake"; + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + outputs = {nixpkgs, ... }: let + forAllSystems = nixpkgs.lib.genAttrs [ + "aarch64-linux" + "i686-linux" + "x86_64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + in { + devShells = forAllSystems (system: let + pkgs = import nixpkgs { + inherit system; + config = { + android_sdk.accept_license = true; + allowUnfree = true; + }; + }; + in { + default = pkgs.mkShell { + packages = with pkgs; [ + (python312.withPackages ( + ppkgs: + with python312Packages; [ + pip # python package manager + fastapi # web framework + pandas # data manipulation + pydantic # data validation + uvicorn # ASGI server + sqlalchemy # ORM + python-multipart # fastapi multipart form data + ] + )) + fastapi-cli + sqlitestudio + ]; + }; + }); + # app for backing up the data + apps = forAllSystems (system: let + pkgs = import nixpkgs { + inherit system; + config = { + android_sdk.accept_license = true; + allowUnfree = true; + }; + }; + in { + default = pkgs.fastapi-cli; + backup-db = pkgs.writeShellApplication { + name = "backup-db"; + runtimeInputs = [ pkgs.zip ]; + text = '' + # date + DATE=$(date +%Y-%m-%d) + # backup directory + BACKUP_DIR=~/aifred-backup/ + # create backup directory if it doesn't exist + mkdir -p $BACKUP_DIR + + # backup file name + BACKUP_FILE=$BACKUP_DIR/backup-$DATE.zip + zip -r $BACKUP_FILE data/ + + # move backup file to backup directory + mv #BACKUP_FILE $BACKUP_DIR + ''; + }; + }); + }; +}