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