advent-of-code-2023/flake.nix
2023-12-01 20:53:46 +01:00

86 lines
3.1 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; };
# Avoids unnecessary recompiles
filteredSource = pkgs.lib.cleanSourceWith {
src = ./haskell;
filter = path: type:
let baseName = baseNameOf (toString path);
in pkgs.lib.cleanSourceFilter path type && !(
baseName == "flake.nix" ||
baseName == "flake.lock" ||
baseName == "dist-newstyle" ||
builtins.match "^cabal\.project\..*$" baseName != null ||
baseName == "hls.sh" ||
baseName == ".envrc" ||
baseName == "hie.yaml" ||
baseName == ".hlint.yaml" ||
baseName == ".hspec" ||
baseName == "ci"
);
};
ghcOverrides = hself: hsuper: rec {
aoc2023 = pkgs.haskell.lib.overrideSrc (hsuper.callPackage ./haskell/default.nix {}) {
src = filteredSource;
};
};
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
];
};
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;
});
}