{ description = "Environment for the Advent of Code 2023, solved in C++"; inputs.devshell.url = "github:numtide/devshell"; inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.flake-compat = { url = "github:edolstra/flake-compat"; flake = false; }; outputs = { self, flake-utils, devshell, nixpkgs, ... }: flake-utils.lib.eachDefaultSystem (system: { devShells.default = let pkgs = import nixpkgs { inherit system; overlays = [ devshell.overlays.default ]; }; in pkgs.devshell.mkShell { devshell = { motd = '' {bold}{3}🎄 Advent of Code 2023 🎄{reset} $(for CMD in g++ make gdb clangd ; do "$CMD" --version | head -n1 done) $(type -p menu &>/dev/null && menu) ''; interactive = { prompt.text = '' export PS1="\n> " ''; }; }; packages = with pkgs; [ gcc gnumake gdb clang-tools bear ]; #env = [ # { name = "ENV"; value = "val"; } #]; commands = [ { category = "aoc"; name = "start"; help = "Deploy directory structure for day $1"; command = '' BASE="$(printf %02d $1)" [ -d "$BASE" ] && echo "Existing directory '$BASE'" && exit 1 mkdir -p "$BASE" && cd $_ mkdir -p src resources cat << EOF >> src/part1.cpp #include #include int main(int argc, char* argv[]) { int answer{}; std::ifstream input{ argv[1] }; if (input.is_open()) { std::string line; while (not std::getline(input,line).eof()) { /* ... */ } } input.close(); /* ... */ std::cout << answer << std::endl; return 0; } EOF cp src/part1.cpp src/part2.cpp cat << EOF >> Makefile CXXFLAGS := -std=c++17 CPPFLAGS := -I../include EXE := part1 part2 .PHONY: all clean configure all: \$(EXE) configure: bear -- \$(MAKE) all %.o: %.cpp \$(CXX) -c \$(CPPFLAGS) \$(CXXFLAGS) \$< -o \$@ clean: rm -rf \$(EXE) src/*.o compile_commands.json %: src/%.o \$(CXX) \$^ -o \$@ EOF ''; } ]; }; }); }