From 22d0414de5c8178b1432393165db556b235b42d9 Mon Sep 17 00:00:00 2001 From: blahai Date: Thu, 23 Jan 2025 23:12:18 +0200 Subject: [PATCH] stuffies --- .gitignore | 19 +++++++++++++++++++ mafs.c => C/mafs.c | 7 ++++++- rust/.envrc | 1 + rust/Cargo.lock | 7 +++++++ rust/Cargo.toml | 8 ++++++++ rust/default.nix | 30 ++++++++++++++++++++++++++++++ rust/flake.lock | 27 +++++++++++++++++++++++++++ rust/flake.nix | 29 +++++++++++++++++++++++++++++ rust/shell.nix | 21 +++++++++++++++++++++ rust/src/main.rs | 3 +++ 10 files changed, 151 insertions(+), 1 deletion(-) rename mafs.c => C/mafs.c (90%) create mode 100644 rust/.envrc create mode 100644 rust/Cargo.lock create mode 100644 rust/Cargo.toml create mode 100644 rust/default.nix create mode 100644 rust/flake.lock create mode 100644 rust/flake.nix create mode 100644 rust/shell.nix create mode 100644 rust/src/main.rs diff --git a/.gitignore b/.gitignore index cd531cf..57ff7e8 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,22 @@ Module.symvers Mkfile.old dkms.conf +# ---> Rust +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# ---> Nix +# Ignore build outputs from performing a nix-build or `nix build` command +result +result-* + +# Ignore direnv +.direnv/ diff --git a/mafs.c b/C/mafs.c similarity index 90% rename from mafs.c rename to C/mafs.c index e73d88e..e65c351 100644 --- a/mafs.c +++ b/C/mafs.c @@ -56,9 +56,14 @@ int main(int argc, char **argv) { if (strcmp("help", argv[1]) == 0) { printf("help command \n"); return 0; - } else { + }; + if (strcmp("ball", argv[1]) == 0) { ball_vol(); + return 0; + }; + if (strcmp("ooe", argv[1]) == 0) { odd_or_even(); + return 0; }; return 0; 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/Cargo.lock b/rust/Cargo.lock new file mode 100644 index 0000000..10e83e0 --- /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 = "example-rust" +version = "0.0.1" diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 0000000..4bdacfd --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "example-rust" +version = "0.0.1" +license = "MIT" +description = "A example rust project using nix" +homepage = "https://github.com/isabelroses/example-rust" +authors = ["Isabel Roses "] +edition = "2021" diff --git a/rust/default.nix b/rust/default.nix new file mode 100644 index 0000000..e02e624 --- /dev/null +++ b/rust/default.nix @@ -0,0 +1,30 @@ +{ + lib, + rustPlatform, +}: let + toml = (lib.importTOML ./Cargo.toml).package; +in + rustPlatform.buildRustPackage { + pname = "mafs-rust"; + inherit (toml) version; + + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ./.)) ( + lib.fileset.unions [ + ./Cargo.toml + ./Cargo.lock + ./src + ] + ); + }; + + cargoLock.lockFile = ./Cargo.lock; + + meta = { + inherit (toml) homepage description; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [blahai]; + mainPackage = "mafs"; + }; + } diff --git a/rust/flake.lock b/rust/flake.lock new file mode 100644 index 0000000..33d9276 --- /dev/null +++ b/rust/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1737525964, + "narHash": "sha256-3wFonKmNRWKq1himW9N3TllbeGIHFACI5vmLpk6moF8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5757bbb8bd7c0630a0cc4bb19c47e588db30b97c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/rust/flake.nix b/rust/flake.nix new file mode 100644 index 0000000..71f48c3 --- /dev/null +++ b/rust/flake.nix @@ -0,0 +1,29 @@ +{ + description = "Rust Project Template"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + }; + + outputs = + { self, nixpkgs }@inputs: + let + forAllSystems = + function: + nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed ( + system: function nixpkgs.legacyPackages.${system} + ); + in + { + packages = forAllSystems (pkgs: { + example = pkgs.callPackage ./default.nix { }; + default = self.packages.${pkgs.stdenv.hostPlatform.system}.example; + }); + + devShells = forAllSystems (pkgs: { + default = pkgs.callPackage ./shell.nix { inherit inputs; }; + }); + + overlays.default = final: _: { example = final.callPackage ./default.nix { }; }; + }; +} diff --git a/rust/shell.nix b/rust/shell.nix new file mode 100644 index 0000000..9326642 --- /dev/null +++ b/rust/shell.nix @@ -0,0 +1,21 @@ +{ + stdenv, + mkShell, + + # extra tooling + clippy, + rustfmt, + rust-analyzer, + + inputs, # our inputs + self ? inputs.self, +}: +mkShell { + inputsFrom = [ self.packages.${stdenv.hostPlatform.system}.default ]; + + packages = [ + clippy + rustfmt + rust-analyzer + ]; +} diff --git a/rust/src/main.rs b/rust/src/main.rs new file mode 100644 index 0000000..a30eb95 --- /dev/null +++ b/rust/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}