summary refs log tree commit diff
path: root/pkgs/applications/video
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2022-10-05 22:48:20 +0200
committerJan Tojnar <jtojnar@gmail.com>2022-10-05 23:21:15 +0200
commit777edf6a604bd759c77d5246d8aa26c66807f56c (patch)
tree622c66fa1362336e137f4149027f1307251637e7 /pkgs/applications/video
parent8edd86b0bdf6e345f634ed4dc2e9503578a1f0db (diff)
epgstation.updateScript: Fix eval and clean up
- `gnused` was not passed, use `callPackage` to prevent such issues in the future.
- Do not pass redundant attributes like `pname` or `version` to the script,
  `update.nix` already passes them as environment variables.
- Do not combine the scripts manually, we have combinators for that.
- Pass the path to update as an argument so that `update.nix`
  can ensure it is a writeable path instead a one in the Nix store.
Diffstat (limited to 'pkgs/applications/video')
-rw-r--r--pkgs/applications/video/epgstation/default.nix20
-rw-r--r--pkgs/applications/video/epgstation/update.nix111
2 files changed, 57 insertions, 74 deletions
diff --git a/pkgs/applications/video/epgstation/default.nix b/pkgs/applications/video/epgstation/default.nix
index 0d058106a7c1a..5fab39fd396a0 100644
--- a/pkgs/applications/video/epgstation/default.nix
+++ b/pkgs/applications/video/epgstation/default.nix
@@ -1,14 +1,11 @@
 { lib
 , stdenv
 , fetchFromGitHub
-, gitUpdater
-, writers
 , makeWrapper
 , bash
 , nodejs
 , gzip
-, jq
-, yq
+, callPackage
 }:
 
 let
@@ -33,7 +30,8 @@ let
   });
 
   server = nodejs.pkgs.epgstation.override (drv: {
-    inherit src;
+    # NOTE: updateScript relies on version matching the src.
+    inherit version src;
 
     # This is set to false to keep devDependencies at build time. Build time
     # dependencies are pruned afterwards.
@@ -108,17 +106,7 @@ let
 
     # NOTE: this may take a while since it has to update all packages in
     # nixpkgs.nodePackages
-    passthru.updateScript = import ./update.nix {
-      inherit lib;
-      inherit (src.meta) homepage;
-      inherit
-        pname
-        version
-        gitUpdater
-        writers
-        jq
-        yq;
-    };
+    passthru.updateScript = callPackage ./update.nix { };
 
     # nodePackages.epgstation is a stub package to fetch npm dependencies and
     # its meta.platforms is made empty to prevent users from installing it
diff --git a/pkgs/applications/video/epgstation/update.nix b/pkgs/applications/video/epgstation/update.nix
index 405dcf53837e2..41b7b9ab1e17b 100644
--- a/pkgs/applications/video/epgstation/update.nix
+++ b/pkgs/applications/video/epgstation/update.nix
@@ -1,67 +1,62 @@
-{ pname
-, version
-, homepage
-, lib
-, gitUpdater
+{ gitUpdater
 , writers
 , jq
 , yq
 , gnused
+, _experimental-update-script-combinators
 }:
 
 let
-  updater = gitUpdater {
-    inherit pname version;
-    attrPath = lib.toLower pname;
+  updateSource = gitUpdater {
     rev-prefix = "v";
   };
-  updateScript = builtins.elemAt updater.command 0;
-  updateArgs = map (lib.escapeShellArg) (builtins.tail updater.command);
-in writers.writeBash "update-epgstation" ''
-  set -euxo pipefail
-
-  # bump the version
-  ${updateScript} ${lib.concatStringsSep " " updateArgs}
-
-  cd "${toString ./.}"
-
-  # Get the path to the latest source. Note that we can't just pass the value
-  # of epgstation.src directly because it'd be evaluated before we can run
-  # updateScript.
-  SRC="$(nix-build ../../../.. --no-out-link -A epgstation.src)"
-  if [[ "${version}" == "$(${jq}/bin/jq -r .version "$SRC/package.json")" ]]; then
-    echo "[INFO] Already using the latest version of ${pname}" >&2
-    exit
-  fi
-
-  # Regenerate package.json from the latest source.
-  ${jq}/bin/jq '. + {
-      dependencies: (.dependencies + .devDependencies),
-    } | del(.devDependencies, .main, .scripts)' \
-    "$SRC/package.json" \
-    > package.json
-  ${jq}/bin/jq '. + {
-      dependencies: (.dependencies + .devDependencies),
-    } | del(.devDependencies, .main, .scripts)' \
-    "$SRC/client/package.json" \
-    > client/package.json
-
-  # Fix issue with old sqlite3 version pinned that depends on very old node-gyp 3.x
-  ${gnused}/bin/sed -i -e 's/"sqlite3":\s*"5.0.[0-9]\+"/"sqlite3": "5.0.11"/' package.json
-
-  # Regenerate node packages to update the pre-overriden epgstation derivation.
-  # This must come *after* package.json has been regenerated.
-  pushd ../../../development/node-packages
-  ./generate.sh
-  popd
-
-  # Generate default streaming settings for the nixos module.
-  pushd ../../../../nixos/modules/services/video/epgstation
-  ${yq}/bin/yq -j '{ urlscheme , stream }' \
-    "$SRC/config/config.yml.template" \
-    > streaming.json
-
-  # Fix generated output for EditorConfig compliance
-  printf '\n' >> streaming.json  # rule: insert_final_newline
-  popd
-''
+  updateLocks = writers.writeBash "update-epgstation" ''
+    set -euxo pipefail
+
+    cd "$1"
+
+    # Get the path to the latest source. Note that we can't just pass the value
+    # of epgstation.src directly because it'd be evaluated before we can run
+    # updateScript.
+    SRC="$(nix-build ../../../.. --no-out-link -A epgstation.src)"
+    if [[ "$UPDATE_NIX_OLD_VERSION" == "$(${jq}/bin/jq -r .version "$SRC/package.json")" ]]; then
+      echo "[INFO] Already using the latest version of $UPDATE_NIX_PNAME" >&2
+      exit
+    fi
+
+    # Regenerate package.json from the latest source.
+    ${jq}/bin/jq '. + {
+        dependencies: (.dependencies + .devDependencies),
+      } | del(.devDependencies, .main, .scripts)' \
+      "$SRC/package.json" \
+      > package.json
+    ${jq}/bin/jq '. + {
+        dependencies: (.dependencies + .devDependencies),
+      } | del(.devDependencies, .main, .scripts)' \
+      "$SRC/client/package.json" \
+      > client/package.json
+
+    # Fix issue with old sqlite3 version pinned that depends on very old node-gyp 3.x
+    ${gnused}/bin/sed -i -e 's/"sqlite3":\s*"5.0.[0-9]\+"/"sqlite3": "5.0.11"/' package.json
+
+    # Regenerate node packages to update the pre-overriden epgstation derivation.
+    # This must come *after* package.json has been regenerated.
+    pushd ../../../development/node-packages
+    ./generate.sh
+    popd
+
+    # Generate default streaming settings for the nixos module.
+    pushd ../../../../nixos/modules/services/video/epgstation
+    ${yq}/bin/yq -j '{ urlscheme , stream }' \
+      "$SRC/config/config.yml.template" \
+      > streaming.json
+
+    # Fix generated output for EditorConfig compliance
+    printf '\n' >> streaming.json  # rule: insert_final_newline
+    popd
+  '';
+in
+_experimental-update-script-combinators.sequence [
+  updateSource
+  [updateLocks ./.]
+]