summaryrefslogtreecommitdiff
path: root/2023/flake.nix
diff options
context:
space:
mode:
Diffstat (limited to '2023/flake.nix')
-rw-r--r--2023/flake.nix104
1 files changed, 104 insertions, 0 deletions
diff --git a/2023/flake.nix b/2023/flake.nix
new file mode 100644
index 0000000..6f6ad62
--- /dev/null
+++ b/2023/flake.nix
@@ -0,0 +1,104 @@
1{
2 description = "Environment for the Advent of Code 2023, solved in C++";
3
4 inputs.devshell.url = "github:numtide/devshell";
5 inputs.flake-utils.url = "github:numtide/flake-utils";
6
7 inputs.flake-compat = {
8 url = "github:edolstra/flake-compat";
9 flake = false;
10 };
11
12 outputs = { self, flake-utils, devshell, nixpkgs, ... }:
13 flake-utils.lib.eachDefaultSystem (system: {
14 devShells.default = let
15 pkgs = import nixpkgs {
16 inherit system;
17 overlays = [ devshell.overlays.default ];
18 };
19 in pkgs.devshell.mkShell {
20
21 devshell = {
22 motd = ''
23 {bold}{3}🎄 Advent of Code 2023 🎄{reset}
24 $(for CMD in g++ make gdb clangd ; do
25 "$CMD" --version | head -n1
26 done)
27 $(type -p menu &>/dev/null && menu)
28 '';
29 interactive = {
30 prompt.text = ''
31 export PS1="\n> "
32 '';
33 };
34 };
35
36 packages = with pkgs; [
37 gcc gnumake gdb clang-tools bear
38 ];
39
40 #env = [
41 # { name = "ENV"; value = "val"; }
42 #];
43
44 commands = [
45 {
46 category = "aoc";
47 name = "start";
48 help = "Deploy directory structure for day $1";
49 command = ''
50 BASE="$(printf %02d $1)"
51 [ -d "$BASE" ] && echo "Existing directory '$BASE'" && exit 1
52 mkdir -p "$BASE" && cd $_
53 mkdir -p src resources
54
55 cat << EOF >> src/part1.cpp
56 #include <iostream>
57 #include <fstream>
58
59 int main(void)
60 {
61 int answer{};
62
63 std::ifstream input{ "resources/input_small.txt" };
64 if (input.is_open())
65 {
66 std::string line;
67 while (not std::getline(input,line).eof())
68 {
69 /* ... */
70 }
71 }
72 input.close();
73
74 /* ... */
75
76 std::cout << answer << std::endl;
77 return 0;
78 }
79 EOF
80 cp src/part1.cpp src/part2.cpp
81
82 cat << EOF >> Makefile
83 CXXFLAGS := -std=c++17
84 EXE := part1 part2
85
86 .PHONY: all clean
87
88 all: \$(EXE)
89
90 %.o: %.cpp
91 \$(CXX) -c \$(CXXFLAGS) $< -o $@
92
93 clean:
94 rm -rf \$(EXE) src/*.o
95
96 %: src/%.o
97 \$(CXX) $^ -o $@
98 EOF
99 '';
100 }
101 ];
102 };
103 });
104}