Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions nixos/modules/programs/opendeck.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
config,
lib,
pkgs,
}:
let
cfg = config.programs.opendeck;
format = pkgs.formats.json { };
in
{
options.programs.opendeck = {
enable = lib.mkEnableOption "OpenDeck, a cross-platform desktop application that provides functionality for stream controller devices. ";

package = lib.mkPackageOption pkgs "opendeck" { };

settings = lib.mkOption {
type = lib.types.nullOr lib.types.submodule {
freeformType = format.type;

options = {
language = lib.mkOption {
type = lib.types.str;
default = "en";
example = "de";
description = ''
Display language for the OpenDeck.

While OpenDeck itself is not yet translated, any installed plugins that supports the
selected language would display its text in that language.
'';
};
background = lib.mkOption {
type = lib.types.bool;
default = true;
example = false;
description = ''
Whether OpenDeck should be minimized to tray and run in the background when its window is closed.
'';
};
autolaunch = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = ''
Whether to automatically start OpenDeck on login.
'';
};
darktheme = lib.mkOption {
type = lib.types.bool;
default = true;
example = false;
description = ''
Whether to use dark theme for OpenDeck.
'';
};
brightness = lib.mkOption {
type = lib.types.ints.between 0 100;
default = 50;
example = 100;
description = ''
Brightness of devices connected to OpenDeck.
'';
};
developer = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = ''
Whether to enable developer mode and features that make plugin debugging and development
easier, while also exposing *all* file paths on your device to a local webserver in
order to symbolically link plugins.
'';
};
};
};
default = null;
description = "Settings for OpenDeck.";
};

pluginsDir = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
example = lib.literalExpression ''/path/to/my/plugins'';
description = ''
Path to a folder containing installed plugins.

The folder should contain folders that each contain a `manifest.json`, as well as the plugin itself.
'';
};
};

config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
services.udev.packages = [ cfg.package ];

environment.etc."xdg/opendeck/settings.json".source = format.generate "opendeck-settings.json" cfg.settings;

systemd.tmpfiles.settings."10-opendeck" = {
"etc/xdg/opendeck/plugins"."L+".argument = lib.mkIf (cfg.pluginsDir != null) "${cfg.pluginsDir}";
};
};
}
107 changes: 107 additions & 0 deletions pkgs/by-name/de/deno/fetch-deps/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
lib,
stdenv,
deno,
jq,
}:
{
hash ? "",
pname,
denoLock ? "",
denoJson ? "",
denoEntrypoints ? [ ],
preDenoInstall ? "",
denoInstallFlags ? [ ],
...
}@args:
let
args' = builtins.removeAttrs args [
"hash"
"pname"
];
in
stdenv.mkDerivation (
args'
// {
name = "${pname}-deno-deps";

nativeBuildInputs = [
deno
jq
];

dontConfigure = true;
dontBuild = true;

denoInstallFlags =
(lib.cli.toGNUCommandLine { } {
vendor = true;
frozen = true;
node-modules-dir = true;
entrypoint = if denoEntrypoints == [ ] then null else denoEntrypoints;
})
++ denoInstallFlags;

inherit denoLock denoJson denoEntrypoints;

installPhase = ''
export DENO_DIR=$(mktemp -d)
export DENO_NO_UPDATE_CHECK=true

if [[ -z "$denoLock" ]]; then
echo "autodetecting lock file"
else
if [[ ! -f "$denoLock" ]]; then
echo "error: lock file '$denoLock' is specified but not found" >&2
exit 1
fi
cp "$denoLock" deno.lock
fi

if [[ -z "$denoJson" ]]; then
echo "autodetecting Deno config"
else
if [[ ! -f "$denoJson" ]]; then
echo "error: Deno config '$denoJson' is specified but not found" >&2
exit 1
fi
cp "$denoJson" deno.json
fi

for entrypoint in "''${denoEntrypoints[@]}"; do
if [[ -n "$entrypoint" && ! -f "$entrypoint" ]]; then
echo "error: entrypoint '$entrypoint' is specified but not found" >&2
exit 1
fi
done

${preDenoInstall}

deno install ''${denoInstallFlags[@]}

# Remove redundant & unreproducible files
rm -f node_modules/.deno/.deno.lock{,.poll}

# TODO: I'm not exactly sure if this is necessary anymore
if [[ -f vendor/manifest.json ]]; then
jq -S '.' vendor/manifest.json > vendor/manifest.json.tmp
mv vendor/manifest.json.tmp vendor/manifest.json
fi


mkdir -p $out
[[ -d node_modules ]] && cp -a node_modules -t $out || true
[[ -d vendor ]] && cp -a vendor -t $out || true
[[ -n deno.json ]] && cp deno.json -t $out || true
[[ -n deno.lock ]] && cp deno.lock -t $out || true
'';

dontFixup = true;

outputHash = hash;
outputHashMode = "recursive";
}
// lib.optionalAttrs (hash == "") {
outputHashAlgo = "sha256";
}
)
51 changes: 51 additions & 0 deletions pkgs/by-name/de/deno/hooks/compile-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# shellcheck shell=bash

denoCompileBuildPhase() {
export DENORT_BIN="@deno@/bin/denort"
export DENO_COMPILE_OUT=$(mktemp -d)

if [[ -z "${denoCompileEntrypoints[@]}" ]]; then
if [[ -z "${denoEntrypoints[@]}" ]]; then
echo "error: neither denoEntrypoints nor denoCompileEntrypoints is set - can't compile anything!" >&2
exit 1
fi

denoCompileEntrypoints=("${denoEntrypoints[@]}")
fi
for entrypoint in "${denoCompileEntrypoints[@]}"; do
if [[ -n "$entrypoint" && ! -f "$entrypoint" ]]; then
echo "error: entrypoint '$entrypoint' is specified but not found" >&2
exit 1
fi
done

deno compile \
--output $DENO_COMPILE_OUT/ \
--cached-only \
--vendor \
--node-modules-dir \
${denoCompileFlags[@]} \
${denoCompileEntrypoints[@]}

# `deno compile` works by inserting JavaScript in the data segments of the executables.
# Stripping them would just completely defeat the point and render the executable unusable.
for file in $DENO_COMPILE_OUT/*; do
stripExclude+=("${file#"$DENO_COMPILE_OUT/"}")
done
}

denoCompileInstallPhase() {
mkdir -p $out/bin
cp -a $DENO_COMPILE_OUT/. -t $out/bin
}

# Why don't we have any kind of dontDenoCompile flag? Because if you don't want to run `deno compile`,
# you shouldn't include this hook in your nativeBuildInputs. Simple as.
if [[ -z "${buildPhase-}" ]]; then
setOutputFlags=
buildPhase=denoCompileBuildPhase
fi
if [[ -z "${installPhase-}" ]]; then
setOutputFlags=
installPhase=denoCompileInstallPhase
fi
36 changes: 36 additions & 0 deletions pkgs/by-name/de/deno/hooks/setup-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# shellcheck shell=bash

denoConfigHook() {
echo "Executing denoConfigHook"

if [[ -n "${denoRoot-}" ]]; then
pushd "$denoRoot"
fi

if [[ -z "${denoDeps-}" ]]; then
echo "denoDeps not set - skipping"
exit 0
fi

export DENO_DIR=$(mktemp -d)

if [[ -d $denoDeps/node_modules ]]; then
cp -a $denoDeps/node_modules -t .
chmod -R +w node_modules

echo "Patching scripts"
patchShebangs node_modules/{*,.*}
fi

[[ -d $denoDeps/vendor ]] && cp -a $denoDeps/vendor -t . || true
[[ -f $denoDeps/deno.json ]] && cp $denoDeps/deno.json deno.json || true
[[ -f $denoDeps/deno.lock ]] && cp $denoDeps/deno.lock deno.lock || true

if [[ -n "${denoRoot-}" ]]; then
popd
fi

echo "Finished denoConfigHook"
}

postConfigureHooks+=(denoConfigHook)
18 changes: 16 additions & 2 deletions pkgs/by-name/de/deno/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
librusty_v8 ? callPackage ./librusty_v8.nix {
inherit (callPackage ./fetchers.nix { }) fetchLibrustyV8;
},
makeSetupHook,
deno,
}:

let
Expand Down Expand Up @@ -83,8 +85,20 @@ rustPlatform.buildRustPackage rec {
runHook postInstallCheck
'';

passthru.updateScript = ./update/update.ts;
passthru.tests = callPackage ./tests { };
passthru = {
updateScript = ./update/update.ts;
tests = callPackage ./tests { };
fetchDeps = callPackage ./fetch-deps { };
setupHook = makeSetupHook {
name = "deno-setup-hook";
propagatedBuildInputs = [ deno ];
} ./hooks/setup-hook.sh;
compileHook = makeSetupHook {
name = "deno-compile-hook";
propagatedBuildInputs = [ deno ];
substitutions.deno = deno;
} ./hooks/compile-hook.sh;
};

meta = with lib; {
homepage = "https://deno.land/";
Expand Down
Loading