Initial commit

This commit is contained in:
Tobias Berger 2020-11-06 16:27:11 +01:00 committed by Tobias Berger
commit 74a955ee70
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
15 changed files with 1758 additions and 0 deletions

2
.envrc Normal file
View file

@ -0,0 +1,2 @@
dotenv
use flake

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
/target
/result
/result-lib
.direnv
.env

1462
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

36
Cargo.toml Normal file
View file

@ -0,0 +1,36 @@
[package]
authors = ["Toby <toby@tobot.dev>"]
name = "advent-of-code-2024"
version = "24.0.0"
edition = "2021"
default-run = "get_input"
[profile.release]
strip = "symbols"
lto = true
opt-level = 3
codegen-units = 1
[profile.dev.package."*"]
opt-level = 3
codegen-units = 1
[profile.release.package."*"]
opt-level = 3
codegen-units = 1
[profile.release.build-override]
codegen-units = 1
[[bin]]
name = "get_input"
path = "src/get_input.rs"
test = false
[[bin]]
name = "template"
# day00 for alphabetic sorting
path = "src/day00/main.rs"
test = false
[dependencies]
reqwest = { version = "0.12.9", features = ["blocking"] }

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Sridhar Ratnakumar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

36
README.md Normal file
View file

@ -0,0 +1,36 @@
A template Rust project with fully functional and no-frills Nix support, as well as builtin VSCode configuration to get IDE experience without any manual setup (just [install direnv](https://nixos.asia/en/direnv), open in VSCode and accept the suggestions).
>[!NOTE]
> If you are looking for the original template based on [this blog post](https://srid.ca/rust-nix)'s use of `crate2nix`, browse from [this tag](https://github.com/srid/rust-nix-template/tree/crate2nix). The evolution of this template can be gleaned from [releases](https://github.com/srid/rust-nix-template/releases).
## Adapting this template
- Run `nix develop` to have a working shell ready before name change.
- Change `name` in Cargo.toml.
- Run `cargo generate-lockfile` in the nix shell
- There are two CI workflows, and one of them uses Nix which is slower (unless you configure a cache) than the other that is based on rustup. Pick one or the other depending on your trade-offs.
## Development (Flakes)
This repo uses [Flakes](https://nixos.wiki/wiki/Flakes) from the get-go.
```bash
# Dev shell
nix develop
# or run via cargo
nix develop -c cargo run
# build
nix build
```
We also provide a [`justfile`](https://just.systems/) for Makefile'esque commands.
## Discussion
- [Zulip](https://nixos.zulipchat.com/#narrow/stream/413950-nix)
## See Also
- [nixos.wiki: Packaging Rust projects with nix](https://nixos.wiki/wiki/Rust#Packaging_Rust_projects_with_nix)

87
flake.lock Normal file
View file

@ -0,0 +1,87 @@
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1732689334,
"narHash": "sha256-yKI1KiZ0+bvDvfPTQ1ZT3oP/nIu3jPYm4dnbRd6hYg4=",
"owner": "nix-community",
"repo": "fenix",
"rev": "a8a983027ca02b363dfc82fbe3f7d9548a8d3dce",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1732837521,
"narHash": "sha256-jNRNr49UiuIwaarqijgdTR2qLPifxsVhlJrKzQ8XUIE=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "970e93b9f82e2a0f3675757eb0bfc73297cc6370",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"fenix": "fenix",
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1732633904,
"narHash": "sha256-7VKcoLug9nbAN2txqVksWHHJplqK9Ou8dXjIZAIYSGc=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "8d5e91c94f80c257ce6dbdfba7bd63a5e8a03fa6",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1732894027,
"narHash": "sha256-2qbdorpq0TXHBWbVXaTqKoikN4bqAtAplTwGuII+oAc=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "6209c381904cab55796c5d7350e89681d3b2a8ef",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

72
flake.nix Normal file
View file

@ -0,0 +1,72 @@
{
description = "A Nix-flake-based Rust development environment";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
treefmt-nix,
fenix,
}:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forEachSupportedSystem =
f:
nixpkgs.lib.genAttrs supportedSystems (
system:
f (
let
pkgs = import nixpkgs { inherit system; };
fenix' = (import fenix { inherit system pkgs; });
toolchain = fenix'.minimal;
in
{
inherit pkgs toolchain;
}
)
);
in
{
formatter = forEachSupportedSystem (
{ pkgs, ... }: (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper
);
devShells = forEachSupportedSystem (
{ pkgs, toolchain }:
{
default = pkgs.mkShell {
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.openssl
];
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
packages =
[
pkgs.pkg-config
]
++ [
toolchain.cargo
toolchain.rustc
];
};
}
);
};
}

3
rust-toolchain.toml Normal file
View file

@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
components = ["rustfmt", "cargo", "rustc", "rust-src"]

1
src/day00/input.txt Normal file
View file

@ -0,0 +1 @@
404 Not Found

3
src/day00/main.rs Normal file
View file

@ -0,0 +1,3 @@
const INPUT: &str = include_str!("./input.txt");
pub fn main() {}

1
src/day00/part_1.rs Normal file
View file

@ -0,0 +1 @@

1
src/day00/part_2.rs Normal file
View file

@ -0,0 +1 @@

20
src/get_input.rs Normal file
View file

@ -0,0 +1,20 @@
use std::{env, error::Error, fs};
use reqwest::blocking::Client;
fn main() -> Result<(), Box<dyn Error>> {
let session = env!("SESSION");
let args: Vec<_> = env::args().collect();
let day = args[1].parse::<u8>()?;
let client = Client::builder().build()?;
let request = client
.get(format!("https://adventofcode.com/2024/day/{day}/input"))
.header("Cookie", format!("session={session}"))
.build()?;
let input = client.execute(request)?.text()?;
fs::create_dir_all(format!("src/day{day:02}/"))?;
fs::write(format!("src/day{day:02}/input.txt"), input)?;
Ok(())
}

8
treefmt.nix Normal file
View file

@ -0,0 +1,8 @@
{ ... }:
{
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
rustfmt.enable = true;
};
}