main
 1{
 2  writeShellApplication,
 3  bubblewrap,
 4  php,
 5  callPackage,
 6  shimmie2-unwrapped ? callPackage ./unwrapped.nix {},
 7  defaultDataDir ? "$HOME/.shimmie2",
 8}:
 9writeShellApplication {
10  name = "shimmie2";
11
12  derivationArgs = {
13    inherit (shimmie2-unwrapped) meta version;
14  };
15
16  runtimeInputs = [bubblewrap php];
17  text = ''
18    show_help() {
19      cat <<EOF
20    Usage: shimmie2 [OPTIONS]
21
22    Wrapper of shimmie2, an easy-to-install community image gallery (aka booru)
23
24    Options:
25      -h, --help                Show this help message
26      -a, --address ADDRESS     Set the service address (default: 127.0.0.1:9000)
27      -d, --data-dir DIR        Set the data directory mapping (default: ${defaultDataDir})
28      --                        Pass all subsequent arguments directly to the PHP process
29
30    Example:
31      shimmie2 -a 0.0.0.0:9000 -- -d upload_max_filesize=100M -d post_max_size=100M
32    EOF
33    }
34
35    ADDRESS="127.0.0.1:9000"
36    DATA_DIR="${defaultDataDir}"
37    PHP_ARGS=()
38
39    while [[ "$#" -gt 0 ]]; do
40      case $1 in
41        -h|--help)
42          show_help
43          exit 0
44          ;;
45        -a|--address)
46          ADDRESS="$2"
47          shift
48          ;;
49        -d|--data-dir)
50          DATA_DIR="$2"
51          shift
52          ;;
53        --)
54          shift
55          PHP_ARGS=("$@")
56          break
57          ;;
58        *)
59          echo "Unknown parameter: $1"
60          show_help
61          exit 1
62          ;;
63      esac
64      shift
65    done
66
67    mkdir -p "$DATA_DIR"
68
69    APP_ROOT="${shimmie2-unwrapped}/share/php/${shimmie2-unwrapped.pname}"
70
71    echo "Starting Shimmie2 on $ADDRESS..."
72    echo "Mapping data dir to writeable $DATA_DIR"
73
74    exec bwrap \
75      --dev-bind / / \
76      --bind "$DATA_DIR" "$APP_ROOT/data" \
77      --chdir "$APP_ROOT" \
78      php "''${PHP_ARGS[@]}" -S "$ADDRESS" tests/router.php
79  '';
80}