From 7f97b1ed9f0a7de3d9765ab477f74191ddb5a16d Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Tue, 15 Oct 2024 16:52:24 -0500 Subject: [PATCH] Get a basic Flake setup --- .envrc | 1 + .gitignore | 2 + Cargo.lock | 7 +++ Cargo.toml | 6 +++ flake.lock | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 78 +++++++++++++++++++++++++++++ src/lib.rs | 63 ++++++++++++++++++++++++ 7 files changed, 297 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 src/lib.rs diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d5df85 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +.direnv diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..fd14e88 --- /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 = "rustdoku" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..7092887 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "rustdoku" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..41c7650 --- /dev/null +++ b/flake.lock @@ -0,0 +1,140 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1728330715, + "narHash": "sha256-xRJ2nPOXb//u1jaBnDP56M7v5ldavjbtR6lfGqSvcKg=", + "owner": "numtide", + "repo": "devshell", + "rev": "dd6b80932022cea34a019e2bb32f6fa9e494dfef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "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" + } + }, + "flake-root": { + "locked": { + "lastModified": 1723604017, + "narHash": "sha256-rBtQ8gg+Dn4Sx/s+pvjdq3CB2wQNzx9XGFq/JVGCB6k=", + "owner": "srid", + "repo": "flake-root", + "rev": "b759a56851e10cb13f6b8e5698af7b59c44be26e", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "flake-root", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1721727458, + "narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=", + "owner": "nix-community", + "repo": "naersk", + "rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1722073938, + "narHash": "sha256-OpX0StkL8vpXyWOGUD6G+MA26wAXK6SpT94kLJXo6B4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e36e9f57337d0ff0cf77aceb58af4c805472bfae", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1727825735, + "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 0, + "narHash": "sha256-HP89HZOT0ReIbI7IJZJQoJgxvB2Tn28V6XS3MNKnfLs=", + "path": "/nix/store/lryfc8mhk1czqsa421di2y5nzz5c3b8m-source", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-parts": "flake-parts", + "flake-root": "flake-root", + "naersk": "naersk", + "nixpkgs": "nixpkgs_3" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..13b9c9b --- /dev/null +++ b/flake.nix @@ -0,0 +1,78 @@ +# github.com/brianmcgee has lots of great ideas for going above and beyond for this +{ + description = "Greg's homepage"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + devshell.url = "github:numtide/devshell"; + flake-parts.url = "github:hercules-ci/flake-parts"; + flake-root.url = "github:srid/flake-root"; + naersk.url = "github:nix-community/naersk"; + #process-compose.url = "github:Platonic-Systems/process-compose-flake"; + #services-flake.url = "github:juspay/services-flake"; + }; + + outputs = { flake-parts, ... }@inputs: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + inputs.devshell.flakeModule + inputs.flake-root.flakeModule + #inputs.process-compose.flakeModule + ]; + flake = { + # Universal things + overlays.default = final: prev: {}; + }; + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + perSystem = { pkgs, ... }@inputs': let + naersk-lib = pkgs.callPackage inputs.naersk { }; + in { + _module.args.pkgs = import inputs.nixpkgs { + inherit (inputs') system; + overlays = []; + }; + # https://numtide.github.io/devshell/intro.html + devshells.default = { + env = [{ + name = "RUST_SRC_PATH"; + value = pkgs.rustPlatform.rustLibSrc; + }]; + # These commands will be shown in the motd that users read + # upon entering the shell + commands = [{ + package = pkgs.cargo; + category = "languages"; + help = "The Cargo tool"; + } { + package = pkgs.rustc; + category = "languages"; + help = "The rust compiler"; + } { + package = pkgs.rustfmt; + category = "tools"; + help = "Formatting tool for Rust"; + } { + package = pkgs.pre-commit; + category = "tools"; + help = "Helps run certain checks"; + } { + package = pkgs.rustPackages.clippy; + category = "tools"; + help = "Standard Rust clippy tool"; + } { + package = pkgs.stdenv.cc; + category = "languages"; + help = "The C compiler, to help things out"; + }]; + }; + + # This is not special, this is just flakes + packages = { + default = naersk-lib.buildPackage ./.; + }; + }; + }; +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..f53c119 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,63 @@ +#[derive(Clone,Debug,Copy)] +pub enum CellValue { + One, + Two, + Three, + Four, + Five, + Six, + Seven, + Eight, + Nine +} + +pub struct Cell { + value: Option, + candidates: Vec, + +} + +impl Default for Cell { + fn default() -> Cell { + Cell { + value : None, + candidates : vec![ + CellValue::One, + CellValue::Two, + CellValue::Three, + CellValue::Four, + CellValue::Five, + CellValue::Six, + CellValue::Seven, + CellValue::Eight, + CellValue::Nine + ] + } + } +} + +#[derive(Default)] +pub struct Board { + cells: [ [ Cell ; 9 ] ; 9 ] +} + +impl Board { + fn value(self, x: usize, y : usize) -> Option { + self.cells[x][y].value + } +} + +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +}