From 109f2eff37a72d844ad785f7bd2b9dc7d01353b6 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Sun, 3 Dec 2023 18:54:24 +0100 Subject: chore: setup nix flake --- 2023/flake.lock | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2023/flake.nix | 104 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+) create mode 100644 2023/flake.lock create mode 100644 2023/flake.nix 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 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + }, + "locked": { + "lastModified": 1700815693, + "narHash": "sha256-JtKZEQUzosrCwDsLgm+g6aqbP1aseUl1334OShEAS3s=", + "owner": "numtide", + "repo": "devshell", + "rev": "7ad1c417c87e98e56dcef7ecd0e0a2f2e5669d51", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1677383253, + "narHash": "sha256-UfpzWfSxkfXHnb4boXZNaKsAcUrZT9Hw+tao1oZxd08=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9952d6bc395f5841262b006fbace8dd7e143b634", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1701432845, + "narHash": "sha256-06sd2rQ+DPMSueh+hW4MiXbpMSdhQHJOi/sw0vuwqvs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "77da99a144cd341408308e0a37622f5edcc6c5ba", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} 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 @@ +{ + 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(void) + { + int answer{}; + + std::ifstream input{ "resources/input_small.txt" }; + 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 + EXE := part1 part2 + + .PHONY: all clean + + all: \$(EXE) + + %.o: %.cpp + \$(CXX) -c \$(CXXFLAGS) $< -o $@ + + clean: + rm -rf \$(EXE) src/*.o + + %: src/%.o + \$(CXX) $^ -o $@ + EOF + ''; + } + ]; + }; + }); +} -- cgit v1.2.3