Skip to content

Commit

Permalink
flaking
Browse files Browse the repository at this point in the history
  • Loading branch information
orzklv committed Aug 14, 2024
1 parent bb97017 commit a3a286a
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 0 deletions.
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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 ./. { };
});
};
}
72 changes: 72 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{ pkgs ? import <nixpkgs> {} }:
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
'';
}

0 comments on commit a3a286a

Please sign in to comment.