From 3ee50f9affe352ed086668e8b0517bd183ce6dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20Du=C3=9Fin?= Date: Mon, 18 Nov 2024 22:43:59 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + derivation.nix | 31 +++++++++++++++++++++++ flake.lock | 48 +++++++++++++++++++++++++++++++++++ flake.nix | 62 +++++++++++++++++++++++++++++++++++++++++++++ rust_toolchain.toml | 3 +++ rustfmt.toml | 13 ++++++++++ 6 files changed, 158 insertions(+) create mode 100644 .gitignore create mode 100644 derivation.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust_toolchain.toml create mode 100644 rustfmt.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/derivation.nix b/derivation.nix new file mode 100644 index 0000000..a6665f3 --- /dev/null +++ b/derivation.nix @@ -0,0 +1,31 @@ +{ + lib, + pkgs, + rustPlatform, + name, +}: +(rustPlatform.buildRustPackage { + inherit name; + + buildInputs = with pkgs; [ + dbus + openssl + ]; + + nativeBuildInputs = with pkgs; [ + pkg-config + vulkan-loader + SDL2 + SDL2_ttf + ]; + + src = lib.cleanSource ./.; + cargoLock = { + lockFile = ./Cargo.lock; + }; + + # Make sure the vulkan libraries get patched in properly + postFixup = '' + patchelf --add-rpath ${pkgs.vulkan-loader}/lib $out/bin/* + ''; +}) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e3cbeb5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1731954261, + "narHash": "sha256-xk83zrDElaMXiHI8DH6sLLTix5+ijPYmIusiQ16GDdc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ad2c28c6c5cc04e09bed68db46db5718d40b5b9e", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "release-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1731897198, + "narHash": "sha256-Ou7vLETSKwmE/HRQz4cImXXJBr/k9gp4J4z/PF8LzTE=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "0be641045af6d8666c11c2c40e45ffc9667839b5", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..cf149a1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,62 @@ +{ + description = "Empty Epsilon inspired bridge simulator"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/release-24.05"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, rust-overlay }: + let + inherit (nixpkgs) lib; + systems = ["x86_64-linux"]; + systemClosure = attrs: + builtins.foldl' (acc: system: + lib.recursiveUpdate acc (attrs system)) {} + systems; + in + systemClosure (system: + let + inherit ((builtins.fromTOML (builtins.readFile ./Cargo.toml)).package) name; + pkgs = import nixpkgs { + inherit system; + overlays = [(import rust-overlay)]; + }; + toolchain = ( + pkgs.rust-bin.fromRustupToolchainFile ./rust_toolchain.toml + ); + rustPlatform = pkgs.makeRustPlatform + { + rustc = toolchain; + cargo = toolchain; + }; + libPath = with pkgs; lib.makeLibraryPath [ + openssl + SDL2 + SDL_ttf + vulkan-loader + ]; + in + { + packages.${system}.default = pkgs.callPackage ./derivation.nix { + inherit name rustPlatform; + }; + + devShells.${system}.default = pkgs.mkShell { + buildInputs = with pkgs; [ + toolchain + clang + llvmPackages.bintools + openssl + pkg-config + SDL2 + SDL2_image + SDL2_ttf + ]; + + LD_LIBRARY_PATH = libPath; + }; + }); +} diff --git a/rust_toolchain.toml b/rust_toolchain.toml new file mode 100644 index 0000000..2107678 --- /dev/null +++ b/rust_toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly-2024-10-17" +components = ["rust-src", "rust-analyzer"] diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..9854c6a --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,13 @@ +brace_style = "AlwaysNextLine" +condense_wildcard_suffixes = true +control_brace_style = "ClosingNextLine" +fn_single_line = true +format_strings = true +hard_tabs = true # Please don't cancel me +hex_literal_case = "Lower" +imports_granularity = "Module" +match_block_trailing_comma = true +newline_style = "Unix" +group_imports = "StdExternalCrate" +struct_field_align_threshold = 15 +wrap_comments = true