Skip to content

Commit

Permalink
add resources to build docker image via nix
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Gonyeo committed Feb 28, 2018
1 parent 6f9d264 commit 9946df4
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*.ho
*.o
*.swp
docker-rootfs
out*
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine

COPY docker-rootfs/nix /nix
COPY docker-rootfs/root /root
COPY docker-rootfs/bin /bin

ENTRYPOINT /bin/cyanide
38 changes: 10 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@ inventory, and filter recipes by spirit type, glass, and a search string.

## Acquiring cyanide

### Binaries

Cyanide can be downloaded from the [releases page on GitHub][releases]:

```
curl -o cyanide https://github.com/dgonyeo/cyanide/...
chmod +x cyanide
```

Cyanide can also be built from source with [stack][stack]:
Cyanide can also be built from source with [stack][stack]. Note that you'll need
to either modify `stack.yaml` or have a working [nix][nix] install to build
cyanide.

```
git clone https://github.com/dgonyeo/cyanide
cd cyanide
stack install
```

### Docker images



## Running cyanide

Cyanide was developed, tested, and is actively used on Linux. It's possible it
Expand All @@ -34,33 +42,6 @@ will run without issue on MacOS or Windows, but this hasn't been attempted.
Running concurrent copies of cyanide is not recommended. It could be fine, but
if data is being modified the changes may not appear across all instances.

### Dependencies

Cyanide has the following rather unreasonably long list of runtime dependencies:

```
linux-vdso.so.1
libm.so.6
libpq.so.5
libtinfo.so.6
librt.so.1
libutil.so.1
libdl.so.2
libpthread.so.0
libgmp.so.10
libc.so.6
/lib64/ld-linux-x86-64.so.2
libssl.so.1.1
libcrypto.so.1.1
libgssapi_krb5.so.2
libkrb5.so.3
libk5crypto.so.3
libcom_err.so.2
libkrb5support.so.0
libkeyutils.so.1
libresolv.so.2
```

### Configuration

Cyanide can be configured via a configuration file stored at
Expand Down Expand Up @@ -99,3 +80,4 @@ GPLv3

[releases]: https://github.com/dgonyeo/cyanide/releases
[stack]: https://docs.haskellstack.org/en/stable/README/
[nix]: https://nixos.org/nix/
58 changes: 58 additions & 0 deletions build-docker-rootfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

set -e

if [ -e out ]; then
rm -rf out
fi

if [ -e out-* ]; then
rm -rf out-*
fi

if [ -e docker-rootfs ]; then
rm -rf docker-rootfs
fi

nix-env -i cyanide -f . -r -p out
nix-env -i vim -p out

mkdir -p docker-rootfs

for i in $(nix-store -qR out/); do
mkdir -p $(dirname docker-rootfs/$i)
cp -r $i docker-rootfs/$i
done
chmod -R +w docker-rootfs

mkdir -p docker-rootfs/root/.config/cyanide/
mkdir -p docker-rootfs/etc
mkdir -p docker-rootfs/bin

cat > docker-rootfs/root/.config/cyanide/cyanide.conf <<EOF
[DATABASE]
host = localhost
port = 5432
user = cyanide
password = cyanide
database = cyanide
[EDITOR]
editor =
EOF

cat > docker-rootfs/root/.vimrc <<EOF
" Be iMproved
set nocompatible
" Enable spellchecking
set spell
" unicode
set encoding=utf-8 " best default encoding
setglobal fileencoding=utf-8 " ...
set nobomb " do not write utf-8 BOM!
EOF

ln -s ../$(realpath out)/bin/cyanide docker-rootfs/bin/cyanide
ln -s ../$(realpath out)/bin/vim docker-rootfs/bin/vim
9 changes: 9 additions & 0 deletions build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e

source build-docker-rootfs.sh

docker build . -t cyanide

rm -rf out out-* docker-rootfs
1 change: 1 addition & 0 deletions cyanide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ executable cyanide
, directory >=1.3 && <1.4
, process >=1.6 && <1.7
, bytestring >=0.10 && <0.11
, unix >=2.7 && <2.8
36 changes: 36 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:

let

inherit (nixpkgs) pkgs;

f = { mkDerivation, base, brick, bytestring, config-ini
, directory, either, microlens, postgresql-simple, process, SHA
, stdenv, text, time, transformers, vector, vty
}:
mkDerivation {
pname = "cyanide";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
enableSharedExecutables = false;
executableHaskellDepends = [
base brick bytestring config-ini directory either microlens
postgresql-simple process SHA text time transformers vector vty
];
homepage = "https://github.com/dgonyeo/cyanide#readme";
license = stdenv.lib.licenses.gpl3;
};

haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};

variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;

drv = variant (haskellPackages.callPackage f {});

in

if pkgs.lib.inNixShell then drv.env else drv
11 changes: 6 additions & 5 deletions src/Cyanide/UI/RecipeInputScreen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import qualified Brick.Focus as BF
import Data.Monoid
import Data.Maybe
import Control.Monad.IO.Class
import System.Environment
import System.Posix.Env
import System.Process
import System.Directory
import qualified Data.ByteString.Lazy.Char8 as BSL
Expand Down Expand Up @@ -128,10 +128,11 @@ handleEvent s@(CyanideState conn conf scr@(RecipeInputScreen nameEd garnishEd gl
B.continue $ s { stateScreen = (RecipeInputIngredientScreen name amountEditor unitEditor filterEditor ingrListOrig ingList f getBack) }

Vty.EvKey (Vty.KChar 'i') [Vty.MMeta] -> do
editorEnv <- liftIO $ getEnv "EDITOR"
let editor = case Config.editor (Config.editorSection conf) of
"" -> editorEnv
e -> T.unpack e
mEditorEnv <- liftIO $ getEnv "EDITOR"
let editor = case (Config.editor (Config.editorSection conf),mEditorEnv) of
("",Just e) -> e
("",Nothing) -> "vim"
(e,_) -> T.unpack e
tmpDir = "/tmp"
hashOfInstructions = showDigest $ sha512 (BSL.pack $ T.unpack instr)
fileName = tmpDir ++ "/cyanide-" ++ take 8 hashOfInstructions ++ ".md"
Expand Down

0 comments on commit 9946df4

Please sign in to comment.