add flake support

This commit is contained in:
osbm 2025-05-05 15:15:21 +03:00
parent 472aa83b3e
commit 8fa5d38f82
2 changed files with 100 additions and 0 deletions

27
flake.lock generated Normal file
View File

@ -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
}

73
flake.nix Normal file
View File

@ -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
'';
};
});
};
}