mirror of
https://github.com/vale981/phoebe
synced 2025-03-04 17:31:41 -05:00
rails: New script `railsdo' and rename home symlink to the app
* New script `railsdo' to help run commands as a rails user * The symlink in the home directory is now always called `app'. It was previously named after the application itself.
This commit is contained in:
parent
6c7065945c
commit
b537635028
4 changed files with 78 additions and 15 deletions
|
@ -13,6 +13,7 @@ let
|
|||
options = import ./options.nix { inherit config lib pkgs; };
|
||||
appSystemd = import ./systemd.nix { inherit config pkgs lib; };
|
||||
funcs = import ./functions.nix { inherit config; };
|
||||
scripts = import ./scripts.nix { inherit lib pkgs; };
|
||||
|
||||
##############################################################################
|
||||
# Collect all apps into a single set using the given function:
|
||||
|
@ -111,5 +112,10 @@ in
|
|||
enable = true;
|
||||
config = concatMapStringsSep "\n" appLogRotation (attrValues cfg.apps);
|
||||
};
|
||||
|
||||
# Additional packages to install in the environment:
|
||||
environment.systemPackages = [
|
||||
scripts.system
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
37
modules/services/web/rails/railsdo.sh
Executable file
37
modules/services/web/rails/railsdo.sh
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/sh
|
||||
|
||||
################################################################################
|
||||
set -e
|
||||
set -u
|
||||
|
||||
################################################################################
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "$0") name command [option...]
|
||||
|
||||
Run a command while logged in as the Rails user NAME.
|
||||
|
||||
Example:
|
||||
|
||||
railsdo myapp rake routes
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
################################################################################
|
||||
if [ $# -lt 2 ] || [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
################################################################################
|
||||
name=$1; shift
|
||||
|
||||
################################################################################
|
||||
if ! id -u "rails-$name" > /dev/null 2>&1; then
|
||||
>&2 echo "ERROR: $name doesn't appear to be a valid rails application"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
################################################################################
|
||||
sudo --user="rails-$name" --login sh -c "cd app && $*"
|
|
@ -1,19 +1,39 @@
|
|||
{ lib, pkgs, ...}:
|
||||
|
||||
pkgs.stdenvNoCC.mkDerivation {
|
||||
name = "rails-scripts";
|
||||
phases = [ "installPhase" "fixupPhase" ];
|
||||
{
|
||||
user = pkgs.stdenvNoCC.mkDerivation {
|
||||
name = "rails-user-scripts";
|
||||
phases = [ "installPhase" "fixupPhase" ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
substituteAll ${./db-migrate.sh} $out/bin/db-migrate.sh
|
||||
find $out/bin -type f -exec chmod 555 '{}' ';'
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
substituteAll ${./db-migrate.sh} $out/bin/db-migrate.sh
|
||||
find $out/bin -type f -exec chmod 555 '{}' ';'
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
description = "Scripts for working with Ruby on Rails applications.";
|
||||
homepage = https://git.devalot.com/pjones/phoebe/;
|
||||
maintainers = with maintainers; [ pjones ];
|
||||
platforms = platforms.all;
|
||||
meta = with lib; {
|
||||
description = "Scripts for working with Ruby on Rails applications.";
|
||||
homepage = https://git.devalot.com/pjones/phoebe/;
|
||||
maintainers = with maintainers; [ pjones ];
|
||||
platforms = platforms.all;
|
||||
};
|
||||
};
|
||||
|
||||
system = pkgs.stdenvNoCC.mkDerivation {
|
||||
name = "rails-system-scripts";
|
||||
phases = [ "installPhase" "fixupPhase" ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
substituteAll ${./railsdo.sh} $out/bin/railsdo
|
||||
find $out/bin -type f -exec chmod 555 '{}' ';'
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
description = "Scripts for working with Ruby on Rails applications.";
|
||||
homepage = https://git.devalot.com/pjones/phoebe/;
|
||||
maintainers = with maintainers; [ pjones ];
|
||||
platforms = platforms.all;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ let
|
|||
|
||||
# Additional set up for the home directory:
|
||||
mkdir -p ${app.home}/home
|
||||
ln -nfs ${app.package}/share/${app.name} ${app.home}/home/${app.name}
|
||||
ln -nfs ${app.package}/share/${app.name} ${app.home}/home/app
|
||||
ln -nfs ${plib.attrsToShellExports "rails-${app.name}-env" (funcs.appEnv app)} ${app.home}/home/.env
|
||||
cp ${./profile.sh} ${app.home}/home/.profile
|
||||
chmod 0700 ${app.home}/home/.profile
|
||||
|
@ -79,7 +79,7 @@ let
|
|||
'' + optionalString (service.isMain && app.database.migrate) ''
|
||||
# Migrate the database:
|
||||
${pkgs.sudo}/bin/sudo --user=rails-${app.name} --login \
|
||||
${scripts}/bin/db-migrate.sh \
|
||||
${scripts.user}/bin/db-migrate.sh \
|
||||
-r ${app.package}/share/${app.name} \
|
||||
-s ${app.home}/state
|
||||
'';
|
||||
|
|
Loading…
Add table
Reference in a new issue