-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
121 lines (108 loc) · 4.12 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{
description = "Advent of Code";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs@{ self, nixpkgs, rust-overlay, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems =
[ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }:
let
crane = rec {
lib = self.inputs.crane.mkLib pkgs;
stable = lib.overrideToolchain self'.packages.rust-stable;
};
days = map (pkgs.lib.fixedWidthNumber 2) (pkgs.lib.range 1 15);
days2023 = map (pkgs.lib.fixedWidthNumber 2) (pkgs.lib.range 1 11);
days2024 = map (pkgs.lib.fixedWidthNumber 2) (pkgs.lib.range 1 1);
in {
packages = {
new-day = pkgs.writeShellApplication {
name = "new-day";
runtimeInputs = [ self'.packages.rust-stable ];
text = ''
cd "$1"
cargo new "$2" --name="aoc-$1-$2"
echo "aoc-$1-common = { path = \"../common/\" }" >> ./"$2"/Cargo.toml
mkdir "$2"/input
touch "$2"/input/example.txt
touch "$2"/input/1.txt
echo "use aoc_$1_common::challenge_input;
fn main() {
let input = challenge_input();
println!(\"{input}\");
}" > ./"$2"/src/main.rs
echo "Cargo project created!";
echo "You should add $2 to ./$1/Cargo.toml";
echo "and also add $2 to days in ./flake.nix";
'';
};
rust-stable = inputs'.rust-overlay.packages.rust.override {
extensions = [ "rust-src" "rust-analyzer" "clippy" ];
};
# TODO: generate for each year
} // (builtins.listToAttrs (map (day: {
name = "2022-${day}";
value = let
build = crane.stable.buildPackage {
src = ./2022;
cargoBuildCommand = "cargo build --release -p aoc-2022-${day}";
};
in pkgs.writeShellApplication {
name = "aoc-2022-${day}";
text = ''
${build}/bin/aoc-2022-${day} "$@"
'';
};
}) days))
// (builtins.listToAttrs (map (day: {
name = "2023-${day}";
value = let
build = let pname = "aoc-2023-${day}"; in crane.stable.buildPackage {
src = ./2023;
cargoBuildCommand = "cargo build --release -p ${pname}";
version = "0.1.0";
inherit pname;
};
in pkgs.writeShellApplication {
name = "aoc-2023-${day}";
text = ''
${build}/bin/aoc-2023-${day} "$@"
'';
};
}) days2023))
// (builtins.listToAttrs (map (day: {
name = "2024-${day}";
value = let
build = let pname = "aoc-2024-${day}"; in crane.stable.buildPackage {
src = ./2024;
cargoBuildCommand = "cargo build --release -p ${pname}";
version = "0.1.0";
inherit pname;
};
in pkgs.writeShellApplication {
name = "aoc-2024-${day}";
text = ''
${build}/bin/aoc-2024-${day} "$@"
'';
};
}) days2024));
devShells = {
default = pkgs.mkShell {
buildInputs = [ self'.packages.rust-stable self'.packages.new-day ]
++ (with pkgs; [ bacon nil hyperfine cargo-flamegraph lldb llvmPackages_14.llvm ]);
};
};
};
};
}