diff --git a/README.md b/README.md index dbddf19..bcf2e55 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ this flake builds a package containing a program for each problem in this years ## 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 @@ -25,3 +25,11 @@ nix build git+https://git.p7.co.nz/thornAvery/aoc2021 ``` 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). diff --git a/code/aoc2021.cabal b/code/aoc2021-programs.cabal similarity index 76% rename from code/aoc2021.cabal rename to code/aoc2021-programs.cabal index f8b1ebc..38ef7db 100644 --- a/code/aoc2021.cabal +++ b/code/aoc2021-programs.cabal @@ -1,12 +1,12 @@ cabal-version: 1.12 -name: aoc2021 +name: aoc2021-programs version: 0.0.0.1 license: MIT build-type: Simple -synopsis: aoc2021 problem 01 -description: aoc2021 problem 01 +synopsis: aoc2021 problems +description: aoc2021 problems author: Thorn Avery maintainer: ta@p7.co.nz diff --git a/code/src/01/01-input.txt b/code/src/01/01-input.txt new file mode 100644 index 0000000..6b3fb17 --- /dev/null +++ b/code/src/01/01-input.txt @@ -0,0 +1,4 @@ +hello this is a test! +this is a second line! +newline! +eof! diff --git a/code/src/01/01.md b/code/src/01/01.md new file mode 100644 index 0000000..f856d9a --- /dev/null +++ b/code/src/01/01.md @@ -0,0 +1,3 @@ +# Problem 01 + + diff --git a/flake.nix b/flake.nix index 3da83ca..70d7b0d 100644 --- a/flake.nix +++ b/flake.nix @@ -14,8 +14,9 @@ }; in rec { defaultPackage = packages.aoc2021; - packages = inputs.flake-utils.lib.flattenTree - ((import ./nix/utils.nix) { inherit pkgs; inherit inputs; }); + packages = (inputs.flake-utils.lib.flattenTree + ((import ./nix/utils.nix) { inherit pkgs; inherit inputs; })) + // { aoc2021 = pkgs.aoc2021; }; hydraJobs = builtins.listToAttrs (map (s: { name = s; value = { ${system} = packages.${s}; diff --git a/nix/overlay.nix b/nix/overlay.nix index 506a8c6..9d53acf 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -1,4 +1,5 @@ inputs: final: prev: { + aoc2021 = final.callPackage (import ./wrapper) { pkgs = final; }; haskellPackages = prev.haskellPackages.override { overrides = haskellSelf: haskellSuper: ((import ./utils.nix) { inherit inputs; pkgs = prev; }) diff --git a/nix/wrapper/default.nix b/nix/wrapper/default.nix new file mode 100644 index 0000000..ba55494 --- /dev/null +++ b/nix/wrapper/default.nix @@ -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 + ''; +}