Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nix as a installation method #4185

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ GEM
libv8-node (18.16.0.0-arm64-darwin)
libv8-node (18.16.0.0-x86_64-darwin)
libv8-node (18.16.0.0-x86_64-linux)
libv8-node (18.16.0.0)
lint_roller (1.1.0)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
Expand Down Expand Up @@ -347,6 +348,7 @@ GEM
method_source (1.0.0)
mini_magick (4.11.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
mini_racer (0.8.0)
libv8-node (~> 18.16.0.0)
minitest (5.22.2)
Expand Down Expand Up @@ -377,6 +379,9 @@ GEM
net-protocol
newrelic_rpm (9.7.1)
nio4r (2.7.0)
nokogiri (1.16.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.16.2-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.2-x86_64-darwin)
Expand Down Expand Up @@ -662,6 +667,7 @@ PLATFORMS
x86_64-darwin-21
x86_64-darwin-22
x86_64-linux
ruby

DEPENDENCIES
annotate
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ You can sign up [here](https://join.slack.com/t/rubyforgood/shared_invite/zt-21p
```
</details>

### Additional Install Options

- [Nix](doc/NIX_SETUP.md)

## Troubleshooting 👷🏼‍♀️

Please let us know by opening up an issue! We have many new contributors come through and it is likely what you experienced will happen to them as well.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ $sf-floating-input-padding-y: $input-padding-y * 2 !default;
background-color: $input-bg;
padding: 0 0 0 $sf-floating-input-padding-x;
margin-top: $input-border-width;
margin-left: $input-border-width * 2;
margin-left: calc($input-border-width * 2);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk why but sassc is very unhappy unless the line is fixed,

width: 99%;
}
}
Expand Down
22 changes: 22 additions & 0 deletions doc/NIX_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
**Nix**

If you have [Nix](https://nixos.org) installed you can use the [flake.nix](flake.nix) configuration file located at the root of the project to build and develop within an environment without needing to install `rvm`, `postgresql` or other tools separately.
The environment also uses the `gemset.nix` file to automatically download and install all the gems necessary to get the server up and running. This means you will not need run `bundle exec` or any `bundle` commands.

INSTRUCTIONS:

1. Install [Nix](https://zero-to-nix.com/concepts/nix-installer)
2. Add the following to `~/.config/nix/nix.conf` or `/etc/nix/nix.conf`:

```
experimental-features = nix-command flakes
```

3. `cd` into human-essentials
4. Copy `.env.example` to `.env` and set correct values
5. `nix develop` and wait for the packages to be downloaded and the environment to be built
6. If the Gemfile changes run `update-deps` to update `gemset.nix`

The database will be created when running `nix develop` for the first time. If you did not set up your `.env` and database creating failed you can run `setup-db` or use `rails db:` commands.

This will run on Linux and macOS.
173 changes: 173 additions & 0 deletions flake.lock

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

145 changes: 145 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
description = "A Ruby dev environment for Human Essentials Development";

nixConfig = {
extra-substituters = "https://nixpkgs-ruby.cachix.org";
extra-trusted-public-keys =
"nixpkgs-ruby.cachix.org-1:vrcdi50fTolOxWCZZkw0jakOnUI1T19oYJ+PRYdK4SM=";
};

inputs = {
nixpkgs.url = "nixpkgs";
ruby-nix = {
url = "github:inscapist/ruby-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
bundix = {
url = "github:inscapist/bundix/main";
inputs.nixpkgs.follows = "nixpkgs";
};
fu.url = "github:numtide/flake-utils";
bob-ruby = {
url = "github:bobvanderlinden/nixpkgs-ruby";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, fu, ruby-nix, bundix, bob-ruby }:
with fu.lib;
eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ bob-ruby.overlays.default ];
};
rubyNix = ruby-nix.lib pkgs;

gemset =
if builtins.pathExists ./gemset.nix then import ./gemset.nix else { };

gemConfig = {
mini_racer = attrs: {
buildInputs = [ pkgs.icu ];
dontBuild = false;
NIX_LDFLAGS = "-licui18n";
};
libv8-node =
let
noopScript = pkgs.writeShellScript "noop" "exit 0";
linkFiles = pkgs.writeShellScript "link-files" ''
cd ../..

mkdir -p vendor/v8/${system}/libv8/obj/
ln -s "${pkgs.nodejs_18.libv8}/lib/libv8.a" "vendor/v8/${system}/libv8/obj/libv8_monolith.a"

ln -s ${pkgs.nodejs_18.libv8}/include vendor/v8/include

mkdir -p ext/libv8-node
echo '--- !ruby/object:Libv8::Node::Location::Vendor {}' >ext/libv8-node/.location.yml
'';
in
attrs: {
dontBuild = false;
postPatch = ''
cp ${noopScript} libexec/build-libv8
cp ${noopScript} libexec/build-monolith
cp ${noopScript} libexec/download-node
cp ${noopScript} libexec/extract-node
cp ${linkFiles} libexec/inject-libv8
'';
};
};

updateDeps = pkgs.writeScriptBin "update-deps" (builtins.readFile
(pkgs.substituteAll {
src = ./scripts/nix-update.sh;
bundix = "${pkgs.bundix}/bin/bundix";
}));
setupDb = pkgs.writeScriptBin "setup-db" (builtins.readFile
(pkgs.substituteAll {
src = ./scripts/nix-db-setup.sh;
}));

# See available versions here: https://github.com/bobvanderlinden/nixpkgs-ruby/blob/master/ruby/versions.json
ruby = pkgs."ruby-3.2.2";

bundixcli = bundix.packages.${system}.default;
in rec {
inherit (rubyNix {
inherit gemset ruby;
name = "ruby-env-human-essentials";
gemConfig = pkgs.defaultGemConfig // gemConfig;
})
env;

devShells = rec {
default = dev;
dev = pkgs.mkShell {
BUNDLE_FORCE_RUBY_PLATFORM = "true";
shellHook = ''
export PS1='\n\[\033[1;34m\][💎:\w]\$\[\033[0m\] '

# Setup postgres database
export PGHOST=$HOME/postgres
export PG_HOST=$PGHOST
export PGDATA=$PGHOST/data
export PGDATABASE=postgres
export PGLOG=$PGHOST/postgres.log

mkdir -p $PGHOST

if [ ! -d $PGDATA ]; then
initdb --auth=trust --no-locale --encoding=UTF8
pg_ctl start -l $PGLOG -o "--unix_socket_directories='$PGHOST'"
setup-db
fi

if ! pg_ctl status
then
pg_ctl start -l $PGLOG -o "--unix_socket_directories='$PGHOST'"
fi

trap 'pg_ctl stop -D "$PGDATA" -s -m fast' EXIT
'';

buildInputs = [
env
updateDeps
setupDb
bundixcli
pkgs.bundix
pkgs.bundler-audit
pkgs.direnv
pkgs.git
pkgs.gnumake
pkgs.libpcap
pkgs.libpqxx
pkgs.libxml2
pkgs.libxslt
pkgs.pkg-config
pkgs.postgresql
];
};
};
});
}