advent-of-code-2023/flake.nix

87 lines
3.1 KiB
Nix
Raw Normal View History

2023-12-01 08:19:49 +00:00
{
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 {
2023-12-01 20:14:54 +00:00
aoc2023 = hsuper.callPackage ./haskell/default.nix {};
2023-12-01 08:19:49 +00:00
};
ghc94Pkgs = pkgs.haskell.packages.ghc94.override {
overrides = ghcOverrides;
};
2023-12-01 13:34:41 +00:00
answers = import ./answers.nix;
2023-12-01 08:19:49 +00:00
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
2023-12-01 20:14:54 +00:00
2023-12-01 13:34:41 +00:00
pkgs.shellcheck
2023-12-01 20:14:54 +00:00
pkgs.rustc
pkgs.cargo
pkgs.rustfmt
pkgs.rust-analyzer
pkgs.clippy
2023-12-01 08:19:49 +00:00
];
};
2023-12-01 13:34:41 +00:00
aoc2023-haskell = ghc94Pkgs.aoc2023;
aoc2023-bash =
2023-12-01 20:14:54 +00:00
let bashDir = pkgs.runCommandLocal "aoc2023-bash" {} ''
2023-12-01 13:34:41 +00:00
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 "''${@}"
'';
};
2023-12-01 20:14:54 +00:00
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=";
};
2023-12-01 08:19:49 +00:00
};
2023-12-01 13:34:41 +00:00
checks =
2023-12-01 20:14:54 +00:00
let mkCheck = (lang: exec: day: parts: {
name = "${lang}-${day}";
2023-12-01 13:34:41 +00:00
value = pkgs.testers.testEqualContents {
2023-12-01 20:14:54 +00:00
assertion = "${lang}: ${day}";
2023-12-01 13:34:41 +00:00
expected = pkgs.writeText "expected" ''
Part 1 Answer: ${parts.part1}
Part 2 Answer: ${parts.part2}
'';
2023-12-01 20:14:54 +00:00
actual = pkgs.runCommandLocal "actual" {} ''
2023-12-01 13:34:41 +00:00
"${exec}" "${day}" < "${./input}/${day}" >$out
'';
};
});
in pkgs.lib.attrsets.mapAttrs' (mkCheck "haskell" "${packages.aoc2023-haskell}/bin/aoc2023") answers
2023-12-01 20:14:54 +00:00
// pkgs.lib.attrsets.mapAttrs' (mkCheck "bash" "${packages.aoc2023-bash}/bin/aoc2023") answers
// pkgs.lib.attrsets.mapAttrs' (mkCheck "rust" "${packages.aoc2023-rust}/bin/aoc2023") answers;
2023-12-01 08:19:49 +00:00
defaultPackage = packages.dev-env;
2023-12-01 13:34:41 +00:00
});
2023-12-01 08:19:49 +00:00
}