added wrapper
This commit is contained in:
		
							parent
							
								
									4148be6ec7
								
							
						
					
					
						commit
						4b6e8d0b87
					
				
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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).
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
							
								
								
									
										4
									
								
								code/src/01/01-input.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								code/src/01/01-input.txt
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										3
									
								
								code/src/01/01.md
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
# Problem 01
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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; })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										14
									
								
								nix/wrapper/default.nix
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								nix/wrapper/default.nix
									
									
									
									
									
										Normal 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
 | 
			
		||||
  '';
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in a new issue