From 92c20821dc7e28072b1ea349e223965554a20458 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 1 Apr 2023 14:28:46 +0000 Subject: [PATCH] place scaffolding that enables cargo and nix builds --- Cargo.lock | 7 +++++++ Cargo.toml | 8 ++++++++ README.md | 34 +++++++++++++++++++++++++++++++++- flake.lock | 42 ++++++++++++++++++++++++++++++++++++++++++ flake.nix | 37 +++++++++++++++++++++++++++++++++++++ src/main.rs | 3 +++ 6 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 src/main.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..20a30ea --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "billbot" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..fbddfa5 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "billbot" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/README.md b/README.md index b017496..de32e64 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ _To :b:reserve and prötec_ -This will be a [Matrix](https://matrix.org) bot used to track +This will be a [Matrix][matrix] bot used to track informal debts between some (small) group of individuals. its goals are (in order of importance): @@ -42,3 +42,35 @@ below is an example of how this bot might work: > @user:host paid @other:host $NNN.MM - maybe state the remaining position? > @user:host now owes $other:host $X.YY + + +## Development/Hacking + +this project is built with [cargo][cargo], the [Rust][rust] package manager. simply run: + +```sh +$ cargo build +$ ./target/debug/billbot +``` + +it can also be built with [nix][nix]: +```sh +$ nix build +$ ./result/bin/billbot +``` + +a nix development environment (i.e. access to the correct toolchain) can be entered like so: +```sh +$ nix develop +``` + +after which ordinary cargo commands can be used: +```sh +nix-shell> cargo build +nix-shell> ./target/debug/billbot +``` + +[matrix]: https://matrix.org +[cargo]: https://doc.rust-lang.org/cargo +[rust]: https://rust-lang.org +[nix]: https://nixos.org diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..d55888a --- /dev/null +++ b/flake.lock @@ -0,0 +1,42 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1680122840, + "narHash": "sha256-zCQ/9iFHzCW5JMYkkHMwgK1/1/kTMgCMHq4THPINpAU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a575c243c23e2851b78c00e9fa245232926ec32f", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-22.11", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..067a0cc --- /dev/null +++ b/flake.nix @@ -0,0 +1,37 @@ +{ + description = "Billbot matrix billshare bot"; + inputs = { + nixpkgs.url = "nixpkgs/nixos-22.11"; + flake-utils.url = github:numtide/flake-utils; + }; + + outputs = { self, nixpkgs, flake-utils }: + with flake-utils.lib; eachSystem allSystems (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in rec { + packages = { + # docs: /doc/languages-frameworks/rust.section.md + mx-billbot = pkgs.rustPlatform.buildRustPackage { + name = "mx-billbot"; + src = self; + cargoLock.lockFile = ./Cargo.lock; + # enables debug builds, if we want: https://github.com/NixOS/nixpkgs/issues/60919. + hardeningDisable = [ "fortify" ]; + }; + }; + defaultPackage = packages.mx-billbot; + + devShells.default = with pkgs; mkShell { + # enables debug builds, if we want: https://github.com/NixOS/nixpkgs/issues/60919. + hardeningDisable = [ "fortify" ]; + + # Allow cargo to download crates. + SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt"; + + nativeBuildInputs = [ cargo ]; + }; + }); +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}