From 2950ff778e12bd63af93597b85cd6f64f362768a Mon Sep 17 00:00:00 2001 From: George Thomas Date: Tue, 2 Dec 2025 16:42:44 +0000 Subject: [PATCH] Add simple Rust Crane project The Nix code is taken from the Crane docs, and adapted for merging with the existing Haskell.Nix flake. The other files are from `cargo init`, with minor modifications, and `cargo generate-lockfile`. The default dev shell contains tools for both languages. We can now run `nix build .#rust` and `nix build .#haskell`, where the latter was previously `nix build .#aoc:exe:aoc`. --- .gitignore | 1 + Cargo.lock | 7 +++++++ Cargo.toml | 6 ++++++ flake.lock | 16 ++++++++++++++++ flake.nix | 17 +++++++++++++++-- src/main.rs | 3 +++ 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore index 5c7b746..ee9ca1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dist*/ result +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..eee204e --- /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 = "aoc" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c0838b1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "aoc" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/flake.lock b/flake.lock index 26a11aa..9a6a0b8 100644 --- a/flake.lock +++ b/flake.lock @@ -83,6 +83,21 @@ "type": "github" } }, + "crane": { + "locked": { + "lastModified": 1763938834, + "narHash": "sha256-j8iB0Yr4zAvQLueCZ5abxfk6fnG/SJ5JnGUziETjwfg=", + "owner": "ipetkov", + "repo": "crane", + "rev": "d9e753122e51cee64eb8d2dddfe11148f339f5a2", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -588,6 +603,7 @@ }, "root": { "inputs": { + "crane": "crane", "flake-utils": "flake-utils", "haskellNix": "haskellNix", "nixpkgs": [ diff --git a/flake.nix b/flake.nix index 18936ae..97d325c 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,8 @@ inputs.haskellNix.url = "github:input-output-hk/haskell.nix"; inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable"; inputs.flake-utils.url = "github:numtide/flake-utils"; - outputs = { self, nixpkgs, flake-utils, haskellNix }: + inputs.crane.url = "github:ipetkov/crane"; + outputs = { self, nixpkgs, flake-utils, haskellNix, crane }: flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: let overlays = [ @@ -17,7 +18,19 @@ ]; pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; }; haskell = pkgs.hixProject.flake { }; + rust = crane.mkLib pkgs; in - haskell + { + devShells.default = pkgs.mkShell { + inputsFrom = [ + haskell.devShells.default + (rust.devShell { }) + ]; + }; + packages = { + haskell = haskell.packages."aoc:exe:aoc"; + rust = rust.buildPackage { src = rust.cleanCargoSource ./.; }; + }; + } ); } 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!"); +}