Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin committed Jul 23, 2019
1 parent 90b50c8 commit 1314b73
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 0 deletions.
11 changes: 11 additions & 0 deletions common-types.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
main =
do
putStrLn ("hask" ++ "ell")

putStrLn ("1+1 = " ++ show (1 + 1))

putStrLn ("7.0/3.0 = " ++ show (7.0 / 3.0))

putStrLn (show (True && False))
putStrLn (show (True || False))
putStrLn (show (not True))
18 changes: 18 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
rec {

versions = import ./versions.nix;

pkgs = import versions.nixpkgs {};

inherit (pkgs) callPackage haskellPackages;

ghc = haskellPackages.ghcWithPackages (p: [
p.bytestring
p.text
]);

inherit (haskellPackages) ghcid;

outputs = callPackage ./outputs.nix { inherit ghc; };

}
1 change: 1 addition & 0 deletions hello-world.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = putStrLn "hello world"
21 changes: 21 additions & 0 deletions outputs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ runCommand, linkFarm, ghc }:

let
run = name: hsFile:
{
name = "${name}.txt";
path = runCommand "phrasebook-output-${name}.txt"
{
buildInputs = [ ghc ];
inherit hsFile;
}
''
runhaskell "$hsFile" > $out
'';
};

in

linkFarm "haskell-phrasebook-outputs" [
(run "hello-world" ./hello-world.hs)
]
35 changes: 35 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# The Haskell Phrasebook

https://typeclasses.com/phrasebook

## Using Nix shell

1. [Install Nix][install]

2. Enter a Nix shell:

```
$ nix-shell --pure
```
3. Within the Nix shell, you have all of the dependencies required by the examples in the Phrasebook. You can run commands such as:
```
$ runhaskell hello-world.hs
hello world
```
```
$ ghcid --command 'ghci hello-world.hs'
```
## Nix dependency versions
The `update-versions` script updates the dependency hashes in `versions.json` to their latest commits. The JSON data is then used by `versions.nix`. This system is described in Vaibhav Sagar's blog post, [*Quick and Easy Nixpkgs Pinning*][vaibhav].
[install]:
https://nixos.org/nix/manual/#chap-installation
[vaibhav]:
https://vaibhavsagar.com/blog/2018/05/27/quick-easy-nixpkgs-pinning/
4 changes: 4 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let
inherit (import ./default.nix) pkgs ghc ghcid;
in
pkgs.mkShell { buildInputs = [ ghc ghcid ]; }
27 changes: 27 additions & 0 deletions update-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash
#! nix-shell -p curl jq nix

set -eufo pipefail

function update {
FILE=$1
PROJECT=$2
BRANCH=${3:-master}

OWNER=$(jq -r '.[$project].owner' --arg project "$PROJECT" < "$FILE")
REPO=$(jq -r '.[$project].repo' --arg project "$PROJECT" < "$FILE")

REV=$(curl "https://api.github.com/repos/$OWNER/$REPO/branches/$BRANCH" | jq -r '.commit.sha')
SHA256=$(nix-prefetch-url --unpack "https://github.com/$OWNER/$REPO/archive/$REV.tar.gz")
TJQ=$(jq '.[$project] = {owner: $owner, repo: $repo, rev: $rev, sha256: $sha256}' \
--arg project "$PROJECT" \
--arg owner "$OWNER" \
--arg repo "$REPO" \
--arg rev "$REV" \
--arg sha256 "$SHA256" \
< "$FILE")
[[ $? == 0 ]] && echo "${TJQ}" >| "$FILE"
}

update versions.json nixpkgs nixos-19.03
8 changes: 8 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"nixpkgs": {
"owner": "NixOS",
"repo": "nixpkgs-channels",
"rev": "314775040bb5e32101458f3afe93bfc0e0591112",
"sha256": "1scq233g7vcw6v6axc1ga19a0q1b6bj8qy76pmc76d2bafhrvjrn"
}
}
11 changes: 11 additions & 0 deletions versions.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let
inherit ((import <nixpkgs> { }).lib) mapAttrs;
inherit (builtins) fetchTarball fromJSON readFile;

fetchFromGitHub = { owner, repo, rev, sha256 }:
builtins.fetchTarball {
inherit sha256;
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
};
in
mapAttrs (_: fetchFromGitHub) (fromJSON (readFile ./versions.json))

0 comments on commit 1314b73

Please sign in to comment.