From 3608dd845d224ce96d3a801f6c8a403326998ddf Mon Sep 17 00:00:00 2001 From: Matthias Schild Date: Fri, 4 Sep 2026 01:21:05 +0200 Subject: [PATCH] feat: initial commit. --- .gitignore | 1 + Cargo.lock | 7 +++++++ Cargo.toml | 6 ++++++ README.md | 12 ++++++++++++ flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 32 ++++++++++++++++++++++++++++++++ src/main.rs | 4 ++++ 7 files changed, 89 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..97c482a --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "nix-rust" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..53a2603 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "nix-rust" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/README.md b/README.md new file mode 100644 index 0000000..b2d3655 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Use Nix with Rust + +This is a simple example for a flake.nix file to develop with Rust. +Open a nix shell with + + nix develop + + # or with zsh + nix develop -c zsh + + # or with VS Code (Need to be installed on system) + nix develop -c code . diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4e641bd --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1788316716, + "narHash": "sha256-bc7rSpXIdn9QWGNqfWcPZWOhEVF8NoeAZkWq0XWnf/k=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3ed67ec0a4d3c7ab4ae1f04f8ee8df07bfa506a2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d41cbc2 --- /dev/null +++ b/flake.nix @@ -0,0 +1,32 @@ +{ + description = "My Rust development environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + + pkgs = import nixpkgs { + inherit system; + }; + in + { + devShells.${system}.default = pkgs.mkShell { + packages = [ + pkgs.rustc + pkgs.cargo + pkgs.rust-analyzer + pkgs.rustfmt + pkgs.clippy + pkgs.rustPlatform.rustLibSrc + pkgs.bash + pkgs.zsh + ]; + + RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; + }; + }; +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..ad4b0bf --- /dev/null +++ b/src/main.rs @@ -0,0 +1,4 @@ +fn main() { + let x = 5; + println!("Hello, world!"); +}