diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f89e60a --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1733024928, + "narHash": "sha256-n/DOfpKH1vkukuBnach91QBQId2dr5tkE7/7UrkV2zw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2c27ab2e60502d1ebb7cf38909de38663f762a79", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1733020719, + "narHash": "sha256-Chv9+3zrf1DhdB9JyskjoV0vJbCQEgkVqrU3p4RPLv8=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "8e18f10703112e6c33e1c0d8b93e8305f6f0a75c", + "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..32c568b --- /dev/null +++ b/flake.nix @@ -0,0 +1,43 @@ +{ + description = "Advent of Code"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { nixpkgs, rust-overlay, ... }: + let + lib = nixpkgs.lib; + systems = ["x86_64-linux"]; + + forEachSystem = fn: lib.genAttrs systems (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + in fn { inherit pkgs; } ); + + mkRustToolchain = pkgs: pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + in { + devShells = forEachSystem ({ pkgs }: let + rustToolchain = mkRustToolchain pkgs; + rustNightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith (t: t.minimal.override { + extensions = [ "rustfmt" ]; + }); + + rustShell = pkgs.mkShell { + name = "AoC"; + + nativeBuildInputs = [ + rustToolchain + rustNightlyToolchain + ]; + }; + in { + default = rustShell; + }); + }; +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..cc8f0d4 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "stable" +components = ["clippy", "rust-analyzer", "rust-src"] +targets = ["x86_64-unknown-linux-gnu"] +profile = "minimal" # includes rustc, cargo, and rust-std diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..b99c2a4 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,18 @@ +edition = "2021" + +# Just enforce it here as well instead of relying on editorconfig alone +hard_tabs = false +tab_spaces = 4 +newline_style = "Unix" + +imports_granularity = "Module" +group_imports = "StdExternalCrate" + +force_multiline_blocks = false +fn_single_line = false +comment_width = 100 +wrap_comments = true +hex_literal_case = "Upper" +blank_lines_upper_bound = 2 +overflow_delimited_expr = true +reorder_impl_items = true