summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2023/flake.lock127
-rw-r--r--2023/flake.nix104
2 files changed, 231 insertions, 0 deletions
diff --git a/2023/flake.lock b/2023/flake.lock
new file mode 100644
index 0000000..e3de56d
--- /dev/null
+++ b/2023/flake.lock
@@ -0,0 +1,127 @@
1{
2 "nodes": {
3 "devshell": {
4 "inputs": {
5 "nixpkgs": "nixpkgs",
6 "systems": "systems"
7 },
8 "locked": {
9 "lastModified": 1700815693,
10 "narHash": "sha256-JtKZEQUzosrCwDsLgm+g6aqbP1aseUl1334OShEAS3s=",
11 "owner": "numtide",
12 "repo": "devshell",
13 "rev": "7ad1c417c87e98e56dcef7ecd0e0a2f2e5669d51",
14 "type": "github"
15 },
16 "original": {
17 "owner": "numtide",
18 "repo": "devshell",
19 "type": "github"
20 }
21 },
22 "flake-compat": {
23 "flake": false,
24 "locked": {
25 "lastModified": 1696426674,
26 "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
27 "owner": "edolstra",
28 "repo": "flake-compat",
29 "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
30 "type": "github"
31 },
32 "original": {
33 "owner": "edolstra",
34 "repo": "flake-compat",
35 "type": "github"
36 }
37 },
38 "flake-utils": {
39 "inputs": {
40 "systems": "systems_2"
41 },
42 "locked": {
43 "lastModified": 1694529238,
44 "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
45 "owner": "numtide",
46 "repo": "flake-utils",
47 "rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
48 "type": "github"
49 },
50 "original": {
51 "owner": "numtide",
52 "repo": "flake-utils",
53 "type": "github"
54 }
55 },
56 "nixpkgs": {
57 "locked": {
58 "lastModified": 1677383253,
59 "narHash": "sha256-UfpzWfSxkfXHnb4boXZNaKsAcUrZT9Hw+tao1oZxd08=",
60 "owner": "NixOS",
61 "repo": "nixpkgs",
62 "rev": "9952d6bc395f5841262b006fbace8dd7e143b634",
63 "type": "github"
64 },
65 "original": {
66 "owner": "NixOS",
67 "ref": "nixpkgs-unstable",
68 "repo": "nixpkgs",
69 "type": "github"
70 }
71 },
72 "nixpkgs_2": {
73 "locked": {
74 "lastModified": 1701432845,
75 "narHash": "sha256-06sd2rQ+DPMSueh+hW4MiXbpMSdhQHJOi/sw0vuwqvs=",
76 "owner": "NixOS",
77 "repo": "nixpkgs",
78 "rev": "77da99a144cd341408308e0a37622f5edcc6c5ba",
79 "type": "github"
80 },
81 "original": {
82 "id": "nixpkgs",
83 "type": "indirect"
84 }
85 },
86 "root": {
87 "inputs": {
88 "devshell": "devshell",
89 "flake-compat": "flake-compat",
90 "flake-utils": "flake-utils",
91 "nixpkgs": "nixpkgs_2"
92 }
93 },
94 "systems": {
95 "locked": {
96 "lastModified": 1681028828,
97 "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
98 "owner": "nix-systems",
99 "repo": "default",
100 "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
101 "type": "github"
102 },
103 "original": {
104 "owner": "nix-systems",
105 "repo": "default",
106 "type": "github"
107 }
108 },
109 "systems_2": {
110 "locked": {
111 "lastModified": 1681028828,
112 "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
113 "owner": "nix-systems",
114 "repo": "default",
115 "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
116 "type": "github"
117 },
118 "original": {
119 "owner": "nix-systems",
120 "repo": "default",
121 "type": "github"
122 }
123 }
124 },
125 "root": "root",
126 "version": 7
127}
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}