advent-of-code-2023/flake.nix

94 lines
3.3 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 &&
2023-12-03 20:36:27 +00:00
(pkgs.lib.strings.hasInfix "rust" path ||
baseName == "Cargo.toml" ||
baseName == "Cargo.lock");
2023-12-01 20:14:54 +00:00
};
cargoSha256 = "sha256-e27WE9K2yby+6vzu0cDojtG0+aTdED7vt7wFgEd2dAw=";
};
2023-12-01 08:19:49 +00:00
};
2023-12-01 13:34:41 +00:00
checks =
2023-12-03 20:36:27 +00:00
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;
}
);
2023-12-01 13:34:41 +00:00
2023-12-03 20:36:27 +00:00
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;
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
}