Skip to content

Commit

Permalink
Pinned nixpkgs version. Added gcroots to prevent Nix garbage collecto…
Browse files Browse the repository at this point in the history
…r from eating build outputs. Added/updated scripts. Updated README.
  • Loading branch information
Rob Whitaker committed Sep 7, 2018
1 parent dcb9a9e commit 8e4f0ac
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -24,6 +24,9 @@ public/*.html
/elm/elm-stuff
repl-temp-*

## Nix
.gcroots/

### Assorted ###
config/database.yml
config/secrets.yml
Expand Down
35 changes: 7 additions & 28 deletions README.md
@@ -1,37 +1,24 @@
# Midnight Murder Party v2
_Elm, PureScript, JavaScript, Ruby, Sinatra, Nix, SQLite3 (dev), PostgreSQL (prod)_
_Elm, PureScript, JavaScript, Haskell, Ruby, Sinatra, Nix, SQLite3 (dev), PostgreSQL (prod)_

### Requires
- [Nix](https://nixos.org/nix/download.html)

### Dev Setup
- Install Nix
```
$ curl https://nixos.org/nix/install | sh
$ . $HOME/.nix-profile/etc/profile.d/nix.sh
```
- Add the necessary Nix channels (nixos-18.03), and add them to your `$NIX_PATH`:
```
$ nix-channel --add https://nixos.org/channels/nixos-18.03 nixos
$ nix-channel --update
$ export NIX_PATH=nixos=$HOME/.nix-defexpr/channels/nixos:$NIX_PATH
$ # ^ you may want to add this line to your `.bashrc` or `.profile`
```
- Clone and `cd` into the repository
- Run `./setup`

The setup script will create the necessary files/folders, install dependencies, setup the database, and build the reader, editor, and countdown page.
The setup script will create the necessary files/folders, install dependencies via Nix, setup the database, and build the reader, editor, and countdown page. This will probably take between ten and twenty minutes the first time.

### Dev Environment
_Optional:_ The setup script (and the `dev-shell` script) will create Nix roots for this project. This will allow you to use Nix's garbage collector without erasing all of your build output files (thus saving you from having another twenty minute install next time you use the Nix shell). However, to enable keeping the outputs, you must set `keep-outputs = true` in your [Nix config](https://nixos.org/nix/manual/#ch-files).

Once you run the setup script, you can create a dev environment with all the dependencies installed by running `nix-shell`. Unless otherwise noted, all of the following commands will assume you're running in the Nix shell.
### Dev Environment

### Manually Installing Dependencies
Once you run the setup script, you can create a dev environment with all the dependencies installed by running `./dev-shell`. Unless otherwise noted, all of the following commands will assume you're running in this shell.

If you update the dependencies in `bower.json` or the `Gemfile`, you must generate the corresponding Nix file(s) again (bower-packages.nix and gemset.nix, respectively). To do so, leave the Nix shell and enter one or more of the following commands:
### Updating Dependencies

- bower.json: `nix-shell -p nodePackages.bower2nix --run "bower2nix > bower-packages.nix"`
- Gemfile: `nix-shell -p bundix --run "bundix -l"`
If you update the dependencies in `bower.json` or the `Gemfile`, you must generate the corresponding Nix file(s) again (bower-packages.nix and gemset.nix, respectively). To do so, leave the Nix shell and run `./update-deps`.

Once you enter the Nix shell again, those changes will take effect.

Expand All @@ -49,11 +36,3 @@ To update the Reader dependencies, you can just run `npm install` from within th
### Running the Server
- `ruby app.rb`
- Visit `localhost:4567`/`localhost:4567/editor` in your browser

### A Note On `nix-shell`

You don't technically have to be in a Nix shell session to run the above commands, but it will save you some key strokes. You could also run most commands with `nix-shell shell.nix --pure --run "COMMAND"`. For example, to start the server from outside the Nix shell:

```
$ nix-shell shell.nix --pure --run "ruby app.rb"
```
5 changes: 5 additions & 0 deletions dev-shell
@@ -0,0 +1,5 @@
#!/bin/bash

nix-instantiate shell.nix --indirect --add-root $(pwd)/.gcroots/shell.drv

nix-shell
17 changes: 16 additions & 1 deletion setup
Expand Up @@ -36,5 +36,20 @@ gulp build:reader
echo "Building the countdown page..."
gulp build:countdown
echo "Success!"
echo "Project built!"
'

echo ""

echo "Installing Nix roots..."

nix-instantiate shell.nix --indirect --add-root $(pwd)/.gcroots/shell.drv

echo ""

echo "To make use of the Nix roots, set 'keep-outputs = true' in your Nix config (see: https://nixos.org/nix/manual/#ch-files).\
This will prevent Nix's garbage collector from erasing most of your build files."

echo ""

echo "Build complete! To start a dev shell, run './dev-shell'."
6 changes: 5 additions & 1 deletion shell.nix
@@ -1,4 +1,8 @@
with (import <nixos> { config = import ./config.nix; });
with import (fetchTarball {
url = https://github.com/NixOS/nixpkgs/archive/18.03.tar.gz;
sha256 = "0hk4y2vkgm1qadpsm4b0q1vxq889jhxzjx3ragybrlwwg54mzp4f";
}) { config = import ./config.nix; };

let
mmpApp = { outPath = ./.; name = "mmp-website"; };

Expand Down
3 changes: 3 additions & 0 deletions update-deps
@@ -0,0 +1,3 @@
#!/bin/bash

nix-shell -p nodePackages.bower2nix -p bundix --run "bower2nix > bower-packages.nix; bundix -l"

0 comments on commit 8e4f0ac

Please sign in to comment.