Skip to content

Commit

Permalink
ADD initial flake support
Browse files Browse the repository at this point in the history
  • Loading branch information
mwr committed Oct 13, 2023
1 parent 0d1683d commit 01f7967
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.idea
.direnv
/bin
/tmp
/vendor
/rooter
/result
box.phar
rooter.phar
90 changes: 50 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,12 @@ This guide assumes you have successfully installed:

What exactly is being installed on macOS is documented here: https://nixos.org/manual/nix/stable/installation/installing-binary.html#macos-installation.

## Installation
## Installation via flake

Clone the rooter repository to your local and change directory to rooter
```bash
git clone [email protected]:run_as_root/internal/rooter.git rooter
cd rooter
```
No we need to download all dependencies using nix.
This can be triggered using direnv or using nix.
Choose one:

1. direnv
```bash
direnv allow .
```

2. nix
```bash
nix-shell
# … wait for the process to finish, it will take quite a few minutes if executed for the first time
exit # exit the shell
```

Install Composer dependencies required to executed rooter
```bash
composer install
```

Now that all dependencies are installed, we can continue with the rooter installation.
It will initialise directories, configurations, process, ssl certs, etc.
```bash
./rooter install
nix profile install --accept-flake-config "git+ssh://[email protected]/run_as_root/internal/rooter.git?ref=main"
```

Last but not least, we suggest to make sure rooter binary is globally available.
For that you should either create
- an alias for rooter in you `~/.basrc` or `~/.zshrc` e.g. `alias rooter=/<path-to-rooter>/rooter`
- or create a symlink in any dir that is included in your path
- or add the rooter directory to the PATH `export $PATH="$PATH:/<path-to-rooter>/rooter"`

## Project setup

### Quickstart
Expand Down Expand Up @@ -85,7 +51,7 @@ Manually add `.devenv/` and `.env` to .gitignore

This command will also create a `.env` file in your project root or overwrite values for rooter.
It will find available ports for the project and write them to the .env file.
Ports will selected from a range defined for each service type.
Ports will be selected from a range defined for each service type.

### Configure auto-initialisation

Expand Down Expand Up @@ -205,9 +171,53 @@ see [TEMPLATES.md](docs/TEMPLATES.md)

## DEVELOPMENT

For local development of rooter you can use the default installation.
PHP Debugging can be enabled by replacing this line in ``shell.nix``:
### Installation Development

Clone the rooter repository to your local and change directory to rooter
```bash
git clone [email protected]:run_as_root/internal/rooter.git rooter
cd rooter
```
No we need to download all dependencies using nix.
This can be triggered using direnv or using nix.
Choose one:

1. direnv
```bash
direnv allow .
```
use nix -o shell.dev.nix

2. nix
```bash
nix-shell
# … wait for the process to finish, it will take quite a few minutes if executed for the first time
exit # exit the shell
```

Install Composer dependencies required to executed rooter
```bash
composer install
```

Now that all dependencies are installed, we can continue with the rooter installation.
It will initialise directories, configurations, process, ssl certs, etc.
```bash
./rooter install
```

Last but not least, we suggest to make sure rooter binary is globally available.
For that you should either create
- an alias for rooter in you `~/.basrc` or `~/.zshrc` e.g. `alias rooter=/<path-to-rooter>/rooter`
- or create a symlink in any dir that is included in your path
- or add the rooter directory to the PATH `export $PATH="$PATH:/<path-to-rooter>/rooter"`

### Using dev version of rooter

For local development of rooter you can use the default installation.

```bash
nix build ".#rooterDev" --impure
alias rooter-dev="<path-to-rooter>/rooter/result/bin/rooterDev"
# optional per environment:
export ROOTER_BIN="/Volumes/MyData/Entwicklung/Workspace/run-as-root/rooter/result/bin/rooterDev"
```
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"replacements": {
"application_name": "rooter"
},
"git-commit-short": "git_commit_short",
"stub": "build/phar/_cli_stub.php",
"main": false,
"output": "rooter.phar"
}
61 changes: 61 additions & 0 deletions flake.lock

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

87 changes: 87 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
description = "rooter";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
};

outputs = {
self,
utils,
nixpkgs,
...
} @ inputs:
utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
# @todo adapt PHP version if required
php = pkgs.php82.buildEnv {
extensions = { all, enabled }: with all; enabled;
extraConfig = ''
memory_limit=-1
'';
};
phpDev = pkgs.php82.buildEnv {
extensions = { all, enabled }: with all; enabled ++ [ xdebug ];
extraConfig = ''
memory_limit=-1
xdebug.mode=debug
'';
};
in rec {
packages.php = php;
packages.rooter =
let
inherit (pkgs) stdenv lib;
magerun = builtins.fetchurl {
# @todo fetch rooter.phar from github releases
url = "https://github.com/netz98/n98-magerun2/releases/download/7.2.0/n98-magerun2.phar";
sha256 = "0z1dkxz69r9r9gf8xm458zysa51f1592iymcp478wjx87i6prvn3";
};
in
pkgs.writeScriptBin "rooter" ''
#!${pkgs.stdenv.shell}
${php}/bin/php ${magerun} "$@"
'';

packages.rooterDev =
let
inherit (pkgs) stdenv lib;
PROJECT_ROOT = builtins.getEnv "PWD";
in
pkgs.writeShellScriptBin "rooterDev" ''
${phpDev}/bin/php ${PROJECT_ROOT}/rooter.php "$@"
'';

packages.rooterDevPhar =
let
inherit (pkgs) stdenv lib;
box = builtins.fetchurl {
url = "https://github.com/box-project/box/releases/download/4.3.8/box.phar";
sha256 = "061vrxjvmqxy4yyi6j6i28kwl6ixfwhc743b6lw7bjgc4kdkvml3";
};
rooterPharLocal = pkgs.stdenv.mkDerivation {
name = "rooterPharBin";
src = self;
buildPhase = "
${pkgs.php82Packages.composer}/bin/composer install
${phpDev}/bin/php ${box} compile --composer-bin=${pkgs.php82Packages.composer}/bin/composer
";
installPhase = "
mkdir -p $out/bin;
install -t $out/bin rooter.phar;
";
};
in
pkgs.writeShellScriptBin "rooterDevPhar" ''
${phpDev}/bin/php ${rooterPharLocal}/bin/rooter.phar "$@"
'';

defaultPackage = self.packages.${system}.rooter;

devShell = pkgs.mkShell {
buildInputs = [phpDev];
};
});
}
3 changes: 2 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
}:
let
php_custom = pkgs.php82.buildEnv {
extensions = { all, enabled }: with all; enabled ++ [ xsl ];
extensions = { all, enabled }: with all; enabled ++ [ xdebug xsl ];
extraConfig = ''
memory_limit=-1
xdebug.mode=debug
'';
};

Expand Down

0 comments on commit 01f7967

Please sign in to comment.