diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..dd82de1 --- /dev/null +++ b/.envrc @@ -0,0 +1,8 @@ +use_flake() { + watch_file flake.nix + watch_file default.nix + mkdir -p "$(direnv_layout_dir)" + . <(nix print-dev-env --profile "$(direnv_layout_dir)/flake-profile") +} + +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..49b7b01 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +target +Cargo.lock +.direnv \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..71a20c8 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc_24" +description = "Advent of Code 2024" +authors = ["TheFelidae "] +license = "Unlicense" +version = "0.1.0" +edition = "2021" + +[dependencies] \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..d61fd84 --- /dev/null +++ b/default.nix @@ -0,0 +1,40 @@ +{ pkgs ? import { } +, stdenv ? pkgs.stdenv +, lib ? stdenv.lib +# A set providing `buildRustPackage :: attrsets -> derivation` +, rustPlatform ? pkgs.rustPlatform +, fetchFromGitHub ? pkgs.fetchFromGitHub +, gitignoreSrc ? null +, pkgconfig ? pkgs.pkgconfig +, gtk3 ? pkgs.gtk3 +, glib ? pkgs.glib +, gobject-introspection ? pkgs.gobject-introspection +}: + +rustPlatform.buildRustPackage rec { + pname = "aoc24"; + version = "0.0.1"; + + src = gitignoreSource ./.; + + buildInputs = with pkgs; [ + ]; + nativeBuildInputs = with pkgs; [ + + ]; + + cargoLock = { + lockFile = ./Cargo.lock; + allowBuiltinFetchGit = true; + }; + + shellHook = '' + export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${builtins.toString (pkgs.lib.makeLibraryPath buildInputs)}"; + ''; + + meta = with stdenv.lib; { + homepage = ""; + description = ""; + license = "Unlicense"; + }; +} \ No newline at end of file diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c2f36ef --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # We want to use packages from the binary cache + flake-utils.url = "github:numtide/flake-utils"; + gitignore = { url = "github:hercules-ci/gitignore.nix"; flake = false; }; + }; + + outputs = inputs@{ self, nixpkgs, flake-utils, ... }: + flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: let + pkgs = nixpkgs.legacyPackages.${system}; + gitignoreSrc = pkgs.callPackage inputs.gitignore { }; + in rec { + packages.aoc_24 = pkgs.callPackage ./default.nix { inherit gitignoreSrc; }; + + legacyPackages = packages; + + defaultPackage = packages.aoc_24; + + devShell = pkgs.mkShell rec { + CARGO_INSTALL_ROOT = "${toString ./.}/.cargo"; + + buildInputs = with pkgs; [ cargo rustc git + udev + alsa-lib vulkan-loader + xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr # To use the x11 feature + libxkbcommon wayland # To use the wayland feature + ]; + nativeBuildInputs = [ pkgs.pkg-config ]; + env = { + LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}"; + }; + }; + }); +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..b9be9f0 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,17 @@ +fn main() { + // Run the `cargo test` command using Rust - I prefer using tests for this, and reserving src + // for the actual code + println!("Running tests..."); + + let cmd = std::process::Command::new("cargo") + .arg("test") + .status() + .expect("Failed to run tests"); + + if !cmd.success() { + println!("Tests failed"); + std::process::exit(1); + } + + println!("Tests passed"); +} \ No newline at end of file