about summary refs log tree commit diff
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2021-11-12 20:34:45 +0100
committerProfpatsch <mail@profpatsch.de>2021-11-12 20:36:13 +0100
commit81b028afd3d62e36da0924accdbe9b6db5a4eef1 (patch)
tree19397425d06dcef40bfc5187c7c4aee27a4b7ae9
parent129d4a230da847d26faf1a1331c67c614d43d49d (diff)
modules/lazy-packages: factor wrapper to pkgs.vuizvui.lazy-packages
This makes it usable outside of the module; should be a pure refactor.
-rw-r--r--modules/core/lazy-packages.nix44
-rw-r--r--pkgs/build-support/lazy-packages/default.nix51
-rw-r--r--pkgs/default.nix3
3 files changed, 54 insertions, 44 deletions
diff --git a/modules/core/lazy-packages.nix b/modules/core/lazy-packages.nix
index 91c1b8db..a26e2866 100644
--- a/modules/core/lazy-packages.nix
+++ b/modules/core/lazy-packages.nix
@@ -4,49 +4,7 @@ let
   inherit (lib) escapeShellArg;
   inherit (config.vuizvui) lazyPackages;
 
-  # Encode the store path in base 64 so that the wrapper
-  # doesn't have a direct dependency on the package.
-  encoder = "${escapeShellArg "${pkgs.coreutils}/bin/base64"} -w0";
-  decoder = "${escapeShellArg "${pkgs.coreutils}/bin/base64"} -d";
-
-  # The command used to fetch the store path from the binary cache.
-  fetchSubstitute = "${escapeShellArg "${pkgs.nix}/bin/nix-store"} -r";
-
-  mkWrapper = {package, extraErrorMessage ? ""}: pkgs.runCommandLocal "${package.name}-lazy" {
-    inherit package;
-    inherit extraErrorMessage;
-  } ''
-    encoded="$(echo "$package" | ${encoder})"
-
-    if [ ! -e "$package/bin" ]; then
-      echo "Store path $package doesn't have a \`bin' directory" \
-           "so we can't create lazy wrappers for it." \
-           "$extraErrorMessage" >&2
-      exit 1
-    fi
-
-    for bin in "$package"/bin/*; do
-      [ -x "$bin" -a ! -d "$bin" ] || continue
-      binpath="''${bin#$package/}"
-
-      mkdir -p "$out/bin"
-      ( echo ${escapeShellArg "#!${pkgs.stdenv.shell}"}
-        echo "encoded='$encoded'"
-        echo "binpath='$binpath'"
-        echo -n ${escapeShellArg ''
-          storepath="$(echo "$encoded" | ${decoder})"
-          program="$storepath/$binpath"
-          if [ ! -e "$storepath" ]; then
-            ${fetchSubstitute} "$storepath" > /dev/null || exit $?
-          fi
-          exec "$program" "$@"
-        ''}
-      ) > "$out/bin/$(basename "$bin")"
-      chmod +x "$out/bin/$(basename "$bin")"
-    done
-  '';
-
-  vuizvuiWrapper = package: mkWrapper {
+  vuizvuiWrapper = package: pkgs.vuizvui.lazy-packages.mkWrapper {
     inherit package;
     extraErrorMessage = "Please remove `${escapeShellArg package.name}' from `vuizvui.lazyPackages'.";
   };
diff --git a/pkgs/build-support/lazy-packages/default.nix b/pkgs/build-support/lazy-packages/default.nix
new file mode 100644
index 00000000..9040149a
--- /dev/null
+++ b/pkgs/build-support/lazy-packages/default.nix
@@ -0,0 +1,51 @@
+{ pkgs, lib, ... }:
+let
+  inherit (lib) escapeShellArg;
+
+  # Encode the store path in base 64 so that the wrapper
+  # doesn't have a direct dependency on the package.
+  encoder = "${escapeShellArg "${pkgs.coreutils}/bin/base64"} -w0";
+  decoder = "${escapeShellArg "${pkgs.coreutils}/bin/base64"} -d";
+
+  # The command used to fetch the store path from the binary cache.
+  fetchSubstitute = "${escapeShellArg "${pkgs.nix}/bin/nix-store"} -r";
+
+  mkWrapper = {package, extraErrorMessage ? ""}: pkgs.runCommandLocal "${package.name}-lazy" {
+    inherit package;
+    inherit extraErrorMessage;
+  } ''
+    encoded="$(echo "$package" | ${encoder})"
+
+    if [ ! -e "$package/bin" ]; then
+      echo "Store path $package doesn't have a \`bin' directory" \
+           "so we can't create lazy wrappers for it." \
+           "$extraErrorMessage" >&2
+      exit 1
+    fi
+
+    for bin in "$package"/bin/*; do
+      [ -x "$bin" -a ! -d "$bin" ] || continue
+      binpath="''${bin#$package/}"
+
+      mkdir -p "$out/bin"
+      ( echo ${escapeShellArg "#!${pkgs.stdenv.shell}"}
+        echo "encoded='$encoded'"
+        echo "binpath='$binpath'"
+        echo -n ${escapeShellArg ''
+          storepath="$(echo "$encoded" | ${decoder})"
+          program="$storepath/$binpath"
+          if [ ! -e "$storepath" ]; then
+            ${fetchSubstitute} "$storepath" > /dev/null || exit $?
+          fi
+          exec "$program" "$@"
+        ''}
+      ) > "$out/bin/$(basename "$bin")"
+      chmod +x "$out/bin/$(basename "$bin")"
+    done
+  '';
+
+in {
+   inherit
+     mkWrapper
+     ;
+}
diff --git a/pkgs/default.nix b/pkgs/default.nix
index bb2e9531..a508a060 100644
--- a/pkgs/default.nix
+++ b/pkgs/default.nix
@@ -12,7 +12,8 @@ let
 
   self.vuizvui = pkgs.recurseIntoAttrs {
     mkChannel = callPackage ./build-support/channel.nix { };
-    buildSandbox = callPackage build-support/build-sandbox {};
+    buildSandbox = callPackage ./build-support/build-sandbox {};
+    lazy-packages = callPackage ./build-support/lazy-packages {};
 
     list-gamecontrollers = callPackage ./list-gamecontrollers { };