This commit is contained in:
Mrrp 2024-12-21 11:09:23 -08:00
parent 66c1566b57
commit 8ae47a991b
6 changed files with 113 additions and 0 deletions

8
.envrc Normal file
View file

@ -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

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
target
Cargo.lock
.direnv

9
Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "aoc_24"
description = "Advent of Code 2024"
authors = ["TheFelidae <https://github.com/TheFelidae>"]
license = "Unlicense"
version = "0.1.0"
edition = "2021"
[dependencies]

40
default.nix Normal file
View file

@ -0,0 +1,40 @@
{ pkgs ? import <nixpkgs> { }
, 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";
};
}

36
flake.nix Normal file
View file

@ -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}";
};
};
});
}

17
src/main.rs Normal file
View file

@ -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");
}