From 1be7e48709d241edf4656475ac7bbdb2ee6f125a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Av=C3=A9?= Date: Fri, 1 Nov 2024 16:10:33 +0100 Subject: [PATCH] Add simple Rust flake --- Rust/.envrc | 14 ++++++++++++++ Rust/Cargo.lock | 7 +++++++ Rust/Cargo.toml | 6 ++++++ Rust/flake.lock | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ Rust/flake.nix | 33 +++++++++++++++++++++++++++++++++ Rust/src/main.rs | 3 +++ 6 files changed, 111 insertions(+) create mode 100644 Rust/.envrc create mode 100644 Rust/Cargo.lock create mode 100644 Rust/Cargo.toml create mode 100644 Rust/flake.lock create mode 100644 Rust/flake.nix create mode 100644 Rust/src/main.rs diff --git a/Rust/.envrc b/Rust/.envrc new file mode 100644 index 0000000..3a707b2 --- /dev/null +++ b/Rust/.envrc @@ -0,0 +1,14 @@ +[ -e ".devenv" ] || rm -rf .devenv +[ -L ".devenv" ] || (mkdir -p "$HOME/.cache/devenv$PWD" && ln -s "$HOME/.cache/devenv$PWD" .devenv) + +if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" +fi + +watch_file flake.nix +watch_file flake.lock + +if ! use flake . --impure +then + echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 +fi diff --git a/Rust/Cargo.lock b/Rust/Cargo.lock new file mode 100644 index 0000000..0cdb822 --- /dev/null +++ b/Rust/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "app" +version = "0.1.0" diff --git a/Rust/Cargo.toml b/Rust/Cargo.toml new file mode 100644 index 0000000..211d3b2 --- /dev/null +++ b/Rust/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "app" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/Rust/flake.lock b/Rust/flake.lock new file mode 100644 index 0000000..4dac7c3 --- /dev/null +++ b/Rust/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1730200266, + "narHash": "sha256-l253w0XMT8nWHGXuXqyiIC/bMvh1VRszGXgdpQlfhvU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "807e9154dcb16384b1b765ebe9cd2bba2ac287fd", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/Rust/flake.nix b/Rust/flake.nix new file mode 100644 index 0000000..264db42 --- /dev/null +++ b/Rust/flake.nix @@ -0,0 +1,33 @@ +{ + description = "Generic Rust Flake"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + }; + + outputs = inputs @ {flake-parts, ...}: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux" "aarch64-linux"]; + perSystem = { + pkgs, + ... + }: let + app = pkgs.rustPlatform.buildRustPackage { + pname = "app"; + version = "0.1.0"; + cargoLock = { + lockFile = ./Cargo.lock; + }; + src = ./.; + }; + in { + packages = { + default = app; + inherit app; + }; + }; + }; +} diff --git a/Rust/src/main.rs b/Rust/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/Rust/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}