From dae0c7244d90b44ea82fbf01c3b40abca6abdec0 Mon Sep 17 00:00:00 2001 From: Conrad Parker Date: Sat, 21 Mar 2026 02:21:09 -0600 Subject: [PATCH] add rust hello world with nix flake --- rust/.envrc | 1 + rust/flake.nix | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ rust/hello.rs | 8 ++++++++ 3 files changed, 60 insertions(+) create mode 100644 rust/.envrc create mode 100644 rust/flake.nix create mode 100644 rust/hello.rs diff --git a/rust/.envrc b/rust/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/rust/.envrc @@ -0,0 +1 @@ +use flake diff --git a/rust/flake.nix b/rust/flake.nix new file mode 100644 index 0000000..87e360f --- /dev/null +++ b/rust/flake.nix @@ -0,0 +1,51 @@ +{ + description = "Rust dev environment"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + outputs = { self, nixpkgs }: + let + systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f { + pkgs = import nixpkgs { inherit system; }; + }); + in + { + packages = forAllSystems ({ pkgs }: { + default = pkgs.stdenv.mkDerivation { + pname = "hello-rust"; + version = "0.1.0"; + src = ./.; + nativeBuildInputs = [ pkgs.rustc ]; + buildPhase = '' + rustc -O -o hello hello.rs + ''; + installPhase = '' + mkdir -p $out/bin + cp hello $out/bin/ + ''; + }; + }); + + devShells = forAllSystems ({ pkgs }: { + default = pkgs.mkShell { + packages = with pkgs; [ + rustc + cargo + rust-analyzer + clippy + rustfmt + ]; + + RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + }; + }); + + apps = forAllSystems ({ pkgs }: { + default = { + type = "app"; + program = "${self.packages.${pkgs.system}.default}/bin/hello"; + }; + }); + }; +} diff --git a/rust/hello.rs b/rust/hello.rs new file mode 100644 index 0000000..a9d2090 --- /dev/null +++ b/rust/hello.rs @@ -0,0 +1,8 @@ +fn greet(name: &str) -> String { + format!("Hello, {}!", name) +} + +fn main() { + let message = greet("World"); + println!("{}", message); +} -- knotmirror 0.0.1