advent-of-code-2023/flake.nix

94 lines
3.3 KiB
Nix

{
description = "Dev Setup";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = {nixpkgs, flake-utils, ...}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
ghcOverrides = hself: hsuper: rec {
aoc2023 = hsuper.callPackage ./haskell/default.nix {};
};
ghc94Pkgs = pkgs.haskell.packages.ghc94.override {
overrides = ghcOverrides;
};
answers = import ./answers.nix;
in rec {
packages = rec {
dev-env = ghc94Pkgs.shellFor {
packages = p: [p.aoc2023];
buildInputs = [
pkgs.haskellPackages.cabal-install
(pkgs.haskell-language-server.override {supportedGhcVersions = ["948"];})
pkgs.cabal2nix
pkgs.ormolu
pkgs.shellcheck
pkgs.rustc
pkgs.cargo
pkgs.rustfmt
pkgs.rust-analyzer
pkgs.clippy
];
};
aoc2023-haskell = ghc94Pkgs.aoc2023;
aoc2023-bash =
let bashDir = pkgs.runCommandLocal "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 "''${@}"
'';
};
aoc2023-rust = pkgs.rustPlatform.buildRustPackage {
name = "aoc2023";
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type:
let baseName = baseNameOf (toString path);
in pkgs.lib.cleanSourceFilter path type &&
(pkgs.lib.strings.hasInfix "rust" path ||
baseName == "Cargo.toml" ||
baseName == "Cargo.lock");
};
cargoSha256 = "sha256-e27WE9K2yby+6vzu0cDojtG0+aTdED7vt7wFgEd2dAw=";
};
};
checks =
let mkCheck = (lang: exec: day: assertions:
if assertions."check${lang}" then {
name = "${lang}-${day}";
value = pkgs.testers.testEqualContents {
assertion = "${lang}: ${day}";
expected = pkgs.writeText "expected" ''
Part 1 Answer: ${assertions.part1}
Part 2 Answer: ${assertions.part2}
'';
actual = pkgs.runCommandLocal "actual" {} ''
"${exec}" "${day}" < "${./input}/${day}" >$out
'';
};
}
else {
name = "${lang}-${day}-skipped";
value = pkgs.hello;
}
);
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
// pkgs.lib.attrsets.mapAttrs' (mkCheck "Rust" "${packages.aoc2023-rust}/bin/aoc2023") answers;
defaultPackage = packages.dev-env;
});
}