diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7cedb98 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1722869614, + "narHash": "sha256-7ojM1KSk3mzutD7SkrdSflHXEujPvW1u7QuqWoTLXQU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "883180e6550c1723395a3a342f830bfc5c371f6b", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..330903b --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + description = "Assistant for Uzbek Rust community"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; + # nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { self + , nixpkgs + , flake-utils + , ... + } @ inputs: + let + lib = nixpkgs.lib; + systems = [ + "aarch64-linux" + "x86_64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + + forAllSystems = nixpkgs.lib.genAttrs systems; + forEachSystem = f: lib.genAttrs systems (system: f pkgsFor.${system}); + + pkgsFor = lib.genAttrs systems (system: + import nixpkgs { + inherit system; + config.allowUnfree = true; + }); + + devShellFor = system: + let + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + }; + script = import ./shell.nix { inherit pkgs; }; + in + script; + in + { + # Nix script formatter + formatter = + forAllSystems (system: nixpkgs.legacyPackages.${system}.nixpkgs-fmt); + + # Development environment + devShell = lib.mapAttrs (system: _: devShellFor system) (lib.genAttrs systems { }); + + # Output package + packages = forAllSystems (system: { + default = pkgsFor.${system}.callPackage ./. { }; + }); + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..6d26d30 --- /dev/null +++ b/shell.nix @@ -0,0 +1,72 @@ +{ pkgs ? import {} }: +let + getLibFolder = pkg: "${pkg}/lib"; + getFramwork = pkg: "${pkg}/Library/Frameworks"; + darwinOptions = if pkgs.stdenv.isDarwin then '' + -F${(getFramwork pkgs.darwin.apple_sdk.frameworks.Security)} + -F${(getFramwork pkgs.darwin.apple_sdk.frameworks.CoreFoundation)} + -F${(getFramwork pkgs.darwin.apple_sdk.frameworks.CoreServices)} + -F${(getFramwork pkgs.darwin.apple_sdk.frameworks.SystemConfiguration)} + '' else ""; +in +pkgs.stdenv.mkDerivation { + name = "telegram"; + + nativeBuildInputs = [ + pkgs.gcc + pkgs.rustc + pkgs.cargo + pkgs.cargo-watch + pkgs.pkg-config + pkgs.rust-analyzer + pkgs.llvmPackages.llvm + pkgs.llvmPackages.clang + ]; + + buildInputs = [ + pkgs.openssl + pkgs.darwin.apple_sdk.frameworks.Security + pkgs.darwin.apple_sdk.frameworks.CoreServices + pkgs.darwin.apple_sdk.frameworks.CoreFoundation + pkgs.darwin.apple_sdk.frameworks.SystemConfiguration + ]; + + # Set Environment Variables + RUST_BACKTRACE = 1; + NIX_LDFLAGS = "-L${(getLibFolder pkgs.libiconv)} ${darwinOptions}"; + RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ + (getLibFolder pkgs.gcc) + (getLibFolder pkgs.libiconv) + (getLibFolder pkgs.llvmPackages.llvm) + ]; + + shellHook = '' + # Load the environment variables from the .env file + if [ ! -f .env ]; then + echo "Please enter your telegram bot token: "; + read -r TELOXIDE_TOKEN; + echo "TELOXIDE_TOKEN=$TELOXIDE_TOKEN" > .env; + else + source .env; + fi + + # Set the environment variable + export TELOXIDE_TOKEN=$TELOXIDE_TOKEN; + + # Start watching for changes + # Start watching for changes in the background + # cargo watch -x "run" & + + # Store the PID of the background process + # CARGO_WATCH_PID=$! + + # Function to clean up the background process on exit + # cleanup() { + # kill $CARGO_WATCH_PID + # } + + # Trap EXIT signal to run cleanup function + # trap cleanup EXIT + ''; +}