Skip to content

Commit

Permalink
chore: added nix setup
Browse files Browse the repository at this point in the history
  • Loading branch information
lsvalina committed Jul 10, 2024
1 parent 07a15a0 commit 8cc8e92
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 4 deletions.
Empty file added .env.default
Empty file.
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dotenv
use nix
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ node_modules
.env.*
!.env.default

# Nix directories
.direnv
# Nix/direnv directories
.direnv
1 change: 1 addition & 0 deletions config/service.procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
api: __api_run; sleep 10
80 changes: 80 additions & 0 deletions config/tmux.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
set -g base-index 1
setw -g pane-base-index 1
set -g status-keys emacs
set -g mode-keys emacs
# rebind main key: C-s
set-option -g prefix C-a
set-option -g prefix2 C-b
bind -N "Send the prefix key through to the application" \
s send-prefix
bind C-s last-window
setw -g aggressive-resize off
setw -g clock-mode-style 12
set -s escape-time 500
set -g history-limit 500000

set -g base-index 1
set -g pane-base-index 1

set -g status-keys vi
setw -g mode-keys vi
setw -g mouse on
setw -g monitor-activity on

# Moving between windows.
unbind [
unbind ]
bind -r [ select-window -t :-
bind -r ] select-window -t :+

# Pane resizing.
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# Maximize and restore a pane.
unbind Up
bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp
unbind Down
bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp

# Log output to a text file on demand.
bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log"

# -- display -------------------------------------------------------------------
# tabs
set -g window-status-current-format "#[fg=black]#[bg=red] #I #[bg=brightblack]#[fg=brightwhite] #W#[fg=brightblack]#[bg=black]"
set -g window-status-format "#[fg=black]#[bg=yellow] #I #[bg=brightblack]#[fg=brightwhite] #W#[fg=brightblack]#[bg=black]"

# status bar
set-option -g status-position bottom
set-option -g status-justify left
set -g status-fg colour1
set -g status-bg colour0
set -g status-left ' '
set -g status-right '#(date +"%_I:%M")'
set-option -g set-titles on
#256 colors
set -g default-terminal "xterm-256color"
set -ga terminal-overrides ",xterm-256color:Tc"
#Don't auto remane windows
set-option -g allow-rename off

# Use Alt-arrow keys without prefix key to switch panes
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# Shift arrow to switch windows
bind -n S-Left previous-window
bind -n S-Right next-window

# allow fn+left/right
bind-key -n Home send Escape "OH"
bind-key -n End send Escape "OF"

setw -g monitor-activity off
setw -g monitor-activity on
set-option -g bell-action none
77 changes: 77 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
with builtins;
{ pkgs ? import
(fetchTarball {
name = "nixpkgs-unstable-2023-09-06";
url = "https://github.com/NixOS/nixpkgs/archive/f884153fb185d60e57d3c706f6eed274efff7d03.tar.gz";
sha256 = "sha256:033g5vak0dh2ckfxfw73kfqw55bifkiglb5p6azx1hgmivmy2apb";
})
{}
, overlays ? [ ]
, config ? { }
, system ? builtins.currentSystem
}:
let
name = "Travel guide";


# DOTENV
env_bootstrap = with pkgs; writeScriptBin "__env_bootstrap" ''
cp .env.default .env.development
cp .env.default .env
'';

# API
api_install = with pkgs; writeScriptBin "__api_install" ''
npm install
'';

api_run = with pkgs; writeScriptBin "__api_run" ''
npm start
'';

# SETUP

install = with pkgs; writeScriptBin "__install" ''
__env_bootstrap
__api_install
'';

overmindPort = 4333;
procfile = "./config/service.procfile";
nginx_conf = "./config/nginx.conf";

run = with pkgs; writeScriptBin "__run" ''
export OVERMIND_NO_PORT="1"
export OVERMIND_SOCKET=":${toString overmindPort}"
export OVERMIND_NETWORK="tcp"
export OVERMIND_TMUX_CONFIG="./tmux.conf"
export PATH="${tmux}/bin/:$PATH"
${overmind}/bin/overmind start -f ${procfile} --title "start" --shell ${bash}/bin/bash -D
sleep 0.2
${overmind}/bin/overmind connect
'';

tools = with pkgs; {
cli = [
coreutils
nodejs_20
overmind
commitizen
];
scripts = [
env_bootstrap
api_install
api_run
install
run
];
};
paths = pkgs.lib.flatten [ (builtins.attrValues tools) ];
in
pkgs.buildEnv {
inherit name paths;
buildInputs = paths;
}
37 changes: 37 additions & 0 deletions docs/install_nix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
### Nix Setup
> If you don't already have nix set up on your machine, follow this steps!
#### Install nix
```bash
sh <(curl -L https://nixos.org/nix/install) --daemon
```
#### configure nix, adding some features that speed things up

```bash
mkdir -p ~/.config/nix/
echo -e 'max-jobs = auto\nexperimental-features = nix-command flakes' > ~/.config/nix/nix.conf
```
#### configure global nix caches

copy & paste the entire entry in your terminal:
```bash
sudo tee /etc/nix/nix.conf <<EOF
build-users-group = nixbld
substituters = https://cache.nixos.org/
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
EOF
```

#### _NOTE: restart your terminal here!_

##### Install and configure direnv + nix-direnv

```bash
nix-env -i direnv nix-direnv
echo "source $HOME/.nix-profile/share/nix-direnv/direnvrc" >~/.direnvrc
echo "[[ -f ~/.bashrc ]] && . ~/.bashrc" >~/.bash_profile
echo 'eval "$(direnv hook bash)"' >>~/.bashrc
echo 'eval "$(direnv hook zsh)"' >>~/.zshrc
```

##### _NOTE: restart your terminal once more here!_
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8cc8e92

Please sign in to comment.