first commit

This commit is contained in:
thornAvery 2021-12-01 02:56:43 +00:00
commit 1cb9558160
9 changed files with 158 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
result

27
README.md Normal file
View file

@ -0,0 +1,27 @@
# Advent of Code 2021
this flake builds a package containing a program for each problem in this years advent of code.
## adding a problem
create a folder in `code/src` for the problem, then add an entry with the following format into `code/aoc2021.cabal`:
```
executable aoc2021-XX
main-is: Main.hs
ghc-options: -O2 -Wall
hs-source-dirs: src/XX
build-depends: base
default-language: Haskell2010
```
## building
your choice of:
```
nix shell git+https://git.p7.co.nz/thornAvery/aoc2021
nix build git+https://git.p7.co.nz/thornAvery/aoc2021
```
or you can add the overlay defined in the flake

19
code/aoc2021.cabal Normal file
View file

@ -0,0 +1,19 @@
cabal-version: 1.12
name: aoc2021
version: 0.0.0.1
license: MIT
build-type: Simple
synopsis: aoc2021 problem 01
description: aoc2021 problem 01
author: Thorn Avery
maintainer: ta@p7.co.nz
executable aoc2021-01
main-is: Main.hs
ghc-options: -O2 -Wall
hs-source-dirs: src/01
build-depends: base
default-language: Haskell2010

4
code/src/01/Main.hs Normal file
View file

@ -0,0 +1,4 @@
module Main where
main :: IO ()
main = putStrLn "Hello World 01!"

43
flake.lock Normal file
View file

@ -0,0 +1,43 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1634851050,
"narHash": "sha256-N83GlSGPJJdcqhUxSCS/WwW5pksYf3VP1M13cDRTSVA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c91f3de5adaf1de973b797ef7485e441a65b8935",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1635808042,
"narHash": "sha256-kQg7LzPj+UQlCAgD0dJhJ88QdzduXwIyqnTLXScKBbY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "550dab224a26ec25e20e82c0c8bfc764e01b772e",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

27
flake.nix Normal file
View file

@ -0,0 +1,27 @@
{
description = "Thorn's Haskell Repo";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, ... }@inputs:
inputs.flake-utils.lib.eachSystem
[ "x86_64-linux" ]
(system:
let pkgs = import inputs.nixpkgs {
overlays = [ ((import ./overlay.nix) inputs) ];
inherit system;
};
in rec {
defaultPackage = packages.aoc2021;
packages = inputs.flake-utils.lib.flattenTree
((import ./utils.nix) { inherit pkgs; inherit inputs; });
hydraJobs = builtins.listToAttrs
(map (s: { name = s; value = {
${system} = packages.${s};
}; })
(builtins.attrNames packages));
}) // {
overlay = (import ./overlay.nix) inputs;
};
}

7
overlay.nix Normal file
View file

@ -0,0 +1,7 @@
inputs: final: prev: {
haskellPackages = prev.haskellPackages.override {
overrides = haskellSelf: haskellSuper:
((import ./utils.nix) { inherit inputs; pkgs = prev; })
// { };
};
}

3
packages.nix Normal file
View file

@ -0,0 +1,3 @@
inputs: [
./code
]

27
utils.nix Normal file
View file

@ -0,0 +1,27 @@
{ inputs, pkgs, ... }:
let
fn = root: map (p: "${root}/" + p) (builtins.attrNames (builtins.readDir root));
gn = root:
let items = builtins.readDir root;
fn = file: type:
if type == "regular"
then
(let m = (builtins.match "(.*)\\.cabal" file);
in if !(isNull m)
then { "${builtins.elemAt m 0}" = root; }
else {})
else {};
in builtins.foldl' (x: y: x // y) {} (builtins.attrValues (builtins.mapAttrs fn items));
hn = s:
builtins.filter
(x: (builtins.hasAttr "flake" x) && !x.flake)
s;
packagePaths = builtins.foldl'
(x: y: x // y)
{}
(map gn ((import ./packages.nix) inputs));
in
builtins.mapAttrs
(name: path: pkgs.haskellPackages.callCabal2nix name path {})
packagePaths