added wrapper

This commit is contained in:
thornAvery 2021-12-01 04:28:52 +00:00
parent 4148be6ec7
commit 4b6e8d0b87
7 changed files with 37 additions and 6 deletions

View file

@ -4,7 +4,7 @@ this flake builds a package containing a program for each problem in this years
## adding a problem ## adding a problem
create a folder in `code/src` for the problem, then add an entry with the following format into `code/aoc2021.cabal`: create a folder in `code/src` for the problem, then add an entry with the following format into `code/aoc2021-programs.cabal`:
``` ```
executable aoc2021-XX executable aoc2021-XX
@ -25,3 +25,11 @@ nix build git+https://git.p7.co.nz/thornAvery/aoc2021
``` ```
or you can add the overlay defined in the flake or you can add the overlay defined in the flake
## running
this flake defines a wrapper script that automates passing input to the problems.
in order to use it, the problem folder must include `XX-input.txt`, where `XX` is the suffix defined in the cabal file.
the default package provides a wrapper `aoc2021`, which when invoked with `aoc2021 XX` will cat the contents of `XX-input.txt` to the program `aoc2021-XX` (as defined in the cabal file).

View file

@ -1,12 +1,12 @@
cabal-version: 1.12 cabal-version: 1.12
name: aoc2021 name: aoc2021-programs
version: 0.0.0.1 version: 0.0.0.1
license: MIT license: MIT
build-type: Simple build-type: Simple
synopsis: aoc2021 problem 01 synopsis: aoc2021 problems
description: aoc2021 problem 01 description: aoc2021 problems
author: Thorn Avery author: Thorn Avery
maintainer: ta@p7.co.nz maintainer: ta@p7.co.nz

4
code/src/01/01-input.txt Normal file
View file

@ -0,0 +1,4 @@
hello this is a test!
this is a second line!
newline!
eof!

3
code/src/01/01.md Normal file
View file

@ -0,0 +1,3 @@
# Problem 01

View file

@ -14,8 +14,9 @@
}; };
in rec { in rec {
defaultPackage = packages.aoc2021; defaultPackage = packages.aoc2021;
packages = inputs.flake-utils.lib.flattenTree packages = (inputs.flake-utils.lib.flattenTree
((import ./nix/utils.nix) { inherit pkgs; inherit inputs; }); ((import ./nix/utils.nix) { inherit pkgs; inherit inputs; }))
// { aoc2021 = pkgs.aoc2021; };
hydraJobs = builtins.listToAttrs hydraJobs = builtins.listToAttrs
(map (s: { name = s; value = { (map (s: { name = s; value = {
${system} = packages.${s}; ${system} = packages.${s};

View file

@ -1,4 +1,5 @@
inputs: final: prev: { inputs: final: prev: {
aoc2021 = final.callPackage (import ./wrapper) { pkgs = final; };
haskellPackages = prev.haskellPackages.override { haskellPackages = prev.haskellPackages.override {
overrides = haskellSelf: haskellSuper: overrides = haskellSelf: haskellSuper:
((import ./utils.nix) { inherit inputs; pkgs = prev; }) ((import ./utils.nix) { inherit inputs; pkgs = prev; })

14
nix/wrapper/default.nix Normal file
View file

@ -0,0 +1,14 @@
{ pkgs, ... }: pkgs.stdenv.mkDerivation {
name = "aoc2021";
buildInputs = [ pkgs.haskellPackages.aoc2021-programs ];
src = ../../.;
installPhase = ''
mkdir -p $out/{bin,files}
cat > $out/bin/aoc2021 << EOF
#!/bin/bash
cat $out/files/\''${1}-input.txt | ${pkgs.haskellPackages.aoc2021-programs}/bin/aoc2021-\''${1}
EOF
chmod +x $out/bin/aoc2021
find code/ -type f | grep -i input.txt$ | xargs -i cp {} $out/files
'';
}