diff --git a/answers.nix b/answers.nix new file mode 100644 index 0000000..b6eb801 --- /dev/null +++ b/answers.nix @@ -0,0 +1,6 @@ +{ + day1 = { + part1 = "53194"; + part2 = "54249"; + }; +} diff --git a/flake.nix b/flake.nix index 051910c..36af9c4 100644 --- a/flake.nix +++ b/flake.nix @@ -34,6 +34,7 @@ ghc94Pkgs = pkgs.haskell.packages.ghc94.override { overrides = ghcOverrides; }; + answers = import ./answers.nix; in rec { packages = rec { dev-env = ghc94Pkgs.shellFor { @@ -43,10 +44,42 @@ (pkgs.haskell-language-server.override {supportedGhcVersions = ["948"];}) pkgs.cabal2nix pkgs.ormolu + pkgs.shellcheck ]; }; - aoc2023 = ghc94Pkgs.aoc2023; + aoc2023-haskell = ghc94Pkgs.aoc2023; + aoc2023-bash = + let bashDir = pkgs.runCommand "aoc2023-bash" {} '' + mkdir $out + cp -r ${./bash} $out/bin + chmod -R +w $out + patchShebangs $out + ''; + in pkgs.writeShellApplication { + name = "aoc2023"; + runtimeInputs = [ pkgs.util-linux ]; + text = '' + ${bashDir}/bin/main.sh "''${@}" + ''; + }; }; + checks = + let mkCheck = (prefix: exec: day: parts: { + name = "${prefix}-${day}"; + value = pkgs.testers.testEqualContents { + assertion = day; + expected = pkgs.writeText "expected" '' + Part 1 Answer: ${parts.part1} + Part 2 Answer: ${parts.part2} + ''; + actual = pkgs.runCommand "actual" {} '' + "${exec}" "${day}" < "${./input}/${day}" >$out + ''; + }; + }); + + in pkgs.lib.attrsets.mapAttrs' (mkCheck "haskell" "${packages.aoc2023-haskell}/bin/aoc2023") answers + // pkgs.lib.attrsets.mapAttrs' (mkCheck "bash" "${packages.aoc2023-bash}/bin/aoc2023") answers; defaultPackage = packages.dev-env; - }); + }); }