-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90b50c8
commit 1314b73
Showing
9 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; }; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
main = putStrLn "hello world" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ]; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"nixpkgs": { | ||
"owner": "NixOS", | ||
"repo": "nixpkgs-channels", | ||
"rev": "314775040bb5e32101458f3afe93bfc0e0591112", | ||
"sha256": "1scq233g7vcw6v6axc1ga19a0q1b6bj8qy76pmc76d2bafhrvjrn" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |