Skip to content

Commit a3a286a

Browse files
committed
flaking
1 parent bb97017 commit a3a286a

File tree

3 files changed

+190
-0
lines changed

3 files changed

+190
-0
lines changed

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
description = "Assistant for Uzbek Rust community";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
6+
# nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
7+
flake-utils.url = "github:numtide/flake-utils";
8+
};
9+
10+
outputs =
11+
{ self
12+
, nixpkgs
13+
, flake-utils
14+
, ...
15+
} @ inputs:
16+
let
17+
lib = nixpkgs.lib;
18+
systems = [
19+
"aarch64-linux"
20+
"x86_64-linux"
21+
"aarch64-darwin"
22+
"x86_64-darwin"
23+
];
24+
25+
forAllSystems = nixpkgs.lib.genAttrs systems;
26+
forEachSystem = f: lib.genAttrs systems (system: f pkgsFor.${system});
27+
28+
pkgsFor = lib.genAttrs systems (system:
29+
import nixpkgs {
30+
inherit system;
31+
config.allowUnfree = true;
32+
});
33+
34+
devShellFor = system:
35+
let
36+
pkgs = import nixpkgs {
37+
inherit system;
38+
config.allowUnfree = true;
39+
};
40+
script = import ./shell.nix { inherit pkgs; };
41+
in
42+
script;
43+
in
44+
{
45+
# Nix script formatter
46+
formatter =
47+
forAllSystems (system: nixpkgs.legacyPackages.${system}.nixpkgs-fmt);
48+
49+
# Development environment
50+
devShell = lib.mapAttrs (system: _: devShellFor system) (lib.genAttrs systems { });
51+
52+
# Output package
53+
packages = forAllSystems (system: {
54+
default = pkgsFor.${system}.callPackage ./. { };
55+
});
56+
};
57+
}

shell.nix

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{ pkgs ? import <nixpkgs> {} }:
2+
let
3+
getLibFolder = pkg: "${pkg}/lib";
4+
getFramwork = pkg: "${pkg}/Library/Frameworks";
5+
darwinOptions = if pkgs.stdenv.isDarwin then ''
6+
-F${(getFramwork pkgs.darwin.apple_sdk.frameworks.Security)}
7+
-F${(getFramwork pkgs.darwin.apple_sdk.frameworks.CoreFoundation)}
8+
-F${(getFramwork pkgs.darwin.apple_sdk.frameworks.CoreServices)}
9+
-F${(getFramwork pkgs.darwin.apple_sdk.frameworks.SystemConfiguration)}
10+
'' else "";
11+
in
12+
pkgs.stdenv.mkDerivation {
13+
name = "telegram";
14+
15+
nativeBuildInputs = [
16+
pkgs.gcc
17+
pkgs.rustc
18+
pkgs.cargo
19+
pkgs.cargo-watch
20+
pkgs.pkg-config
21+
pkgs.rust-analyzer
22+
pkgs.llvmPackages.llvm
23+
pkgs.llvmPackages.clang
24+
];
25+
26+
buildInputs = [
27+
pkgs.openssl
28+
pkgs.darwin.apple_sdk.frameworks.Security
29+
pkgs.darwin.apple_sdk.frameworks.CoreServices
30+
pkgs.darwin.apple_sdk.frameworks.CoreFoundation
31+
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
32+
];
33+
34+
# Set Environment Variables
35+
RUST_BACKTRACE = 1;
36+
NIX_LDFLAGS = "-L${(getLibFolder pkgs.libiconv)} ${darwinOptions}";
37+
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
38+
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
39+
(getLibFolder pkgs.gcc)
40+
(getLibFolder pkgs.libiconv)
41+
(getLibFolder pkgs.llvmPackages.llvm)
42+
];
43+
44+
shellHook = ''
45+
# Load the environment variables from the .env file
46+
if [ ! -f .env ]; then
47+
echo "Please enter your telegram bot token: ";
48+
read -r TELOXIDE_TOKEN;
49+
echo "TELOXIDE_TOKEN=$TELOXIDE_TOKEN" > .env;
50+
else
51+
source .env;
52+
fi
53+
54+
# Set the environment variable
55+
export TELOXIDE_TOKEN=$TELOXIDE_TOKEN;
56+
57+
# Start watching for changes
58+
# Start watching for changes in the background
59+
# cargo watch -x "run" &
60+
61+
# Store the PID of the background process
62+
# CARGO_WATCH_PID=$!
63+
64+
# Function to clean up the background process on exit
65+
# cleanup() {
66+
# kill $CARGO_WATCH_PID
67+
# }
68+
69+
# Trap EXIT signal to run cleanup function
70+
# trap cleanup EXIT
71+
'';
72+
}

0 commit comments

Comments
 (0)