about summary refs log tree commit diff
path: root/pkgs/development/misc
diff options
context:
space:
mode:
authorTravis A. Everett <travis.a.everett@gmail.com>2021-09-23 17:40:35 -0500
committerRaphael Megzari <raphael@megzari.com>2021-09-27 16:01:09 +0900
commita649cbca0948c39c43c63b790c75b5b6e4db1564 (patch)
tree313bb11edb1eeca8e58195d7e35d58deb6e89ac8 /pkgs/development/misc
parent7b03c7ee60844ecab58d45bd06e2c5f2f8336e64 (diff)
downloadnixlib-a649cbca0948c39c43c63b790c75b5b6e4db1564.tar
nixlib-a649cbca0948c39c43c63b790c75b5b6e4db1564.tar.gz
nixlib-a649cbca0948c39c43c63b790c75b5b6e4db1564.tar.bz2
nixlib-a649cbca0948c39c43c63b790c75b5b6e4db1564.tar.lz
nixlib-a649cbca0948c39c43c63b790c75b5b6e4db1564.tar.xz
nixlib-a649cbca0948c39c43c63b790c75b5b6e4db1564.tar.zst
nixlib-a649cbca0948c39c43c63b790c75b5b6e4db1564.zip
resholvePackage: extract util functions
Extract argument-handling utility functions to prepare for adding
resholveScript* functions.

This tracks upstream work, but I broke it up a little more semantically here
in case it aids review. See:
https://github.com/abathur/resholve/commit/6aab74820531673c760d95c24b28f0c29f43fe01
Diffstat (limited to 'pkgs/development/misc')
-rw-r--r--pkgs/development/misc/resholve/default.nix5
-rw-r--r--pkgs/development/misc/resholve/resholve-package.nix74
-rw-r--r--pkgs/development/misc/resholve/resholve-utils.nix74
3 files changed, 80 insertions, 73 deletions
diff --git a/pkgs/development/misc/resholve/default.nix b/pkgs/development/misc/resholve/default.nix
index dae7fdc384c1..2c8b51b6e816 100644
--- a/pkgs/development/misc/resholve/default.nix
+++ b/pkgs/development/misc/resholve/default.nix
@@ -12,7 +12,10 @@ rec {
     inherit (source) version;
     inherit (deps.oil) oildev;
   };
-  resholvePackage = callPackage ./resholve-package.nix {
+  resholve-utils = callPackage ./resholve-utils.nix {
     inherit resholve;
   };
+  resholvePackage = callPackage ./resholve-package.nix {
+    inherit resholve resholve-utils;
+  };
 }
diff --git a/pkgs/development/misc/resholve/resholve-package.nix b/pkgs/development/misc/resholve/resholve-package.nix
index 78ee6603b9d4..836d2df34604 100644
--- a/pkgs/development/misc/resholve/resholve-package.nix
+++ b/pkgs/development/misc/resholve/resholve-package.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, resholve, binlore }:
+{ stdenv, lib, resholve, resholve-utils }:
 
 { pname
 , src
@@ -9,76 +9,6 @@
 }@attrs:
 let
   inherit stdenv;
-  /* These functions break up the work of partially validating the
-    'solutions' attrset and massaging it into env/cli args.
-
-    Note: some of the left-most args do not *have* to be passed as
-    deep as they are, but I've done so to provide more error context
-  */
-
-  # for brevity / line length
-  spaces = l: builtins.concatStringsSep " " l;
-  semicolons = l: builtins.concatStringsSep ";" l;
-
-  /* Throw a fit with dotted attr path context */
-  nope = path: msg:
-    throw "${builtins.concatStringsSep "." path}: ${msg}";
-
-  /* Special-case directive value representations by type */
-  makeDirective = solution: env: name: val:
-    if builtins.isInt val then builtins.toString val
-    else if builtins.isString val then name
-    else if true == val then name
-    else if false == val then "" # omit!
-    else if null == val then "" # omit!
-    else if builtins.isList val then "${name}:${semicolons val}"
-    else nope [ solution env name ] "unexpected type: ${builtins.typeOf val}";
-
-  /* Build fake/fix/keep directives from Nix types */
-  makeDirectives = solution: env: val:
-    lib.mapAttrsToList (makeDirective solution env) val;
-
-  /* Special-case value representation by type/name */
-  makeEnvVal = solution: env: val:
-    if env == "inputs" then lib.makeBinPath val
-    else if builtins.isString val then val
-    else if builtins.isList val then spaces val
-    else if builtins.isAttrs val then spaces (makeDirectives solution env val)
-    else nope [ solution env ] "unexpected type: ${builtins.typeOf val}";
-
-  /* Shell-format each env value */
-  shellEnv = solution: env: value:
-    lib.escapeShellArg (makeEnvVal solution env value);
-
-  /* Build a single ENV=val pair */
-  makeEnv = solution: env: value:
-    "RESHOLVE_${lib.toUpper env}=${shellEnv solution env value}";
-
-  /* Discard attrs claimed by makeArgs */
-  removeCliArgs = value:
-    removeAttrs value [ "scripts" "flags" ];
-
-  /* Verify required arguments are present */
-  validateSolution = { scripts, inputs, interpreter, ... }: true;
-
-  /* Pull out specific solution keys to build ENV=val pairs */
-  makeEnvs = solution: value:
-    spaces (lib.mapAttrsToList (makeEnv solution) (removeCliArgs value));
-
-  /* Pull out specific solution keys to build CLI argstring */
-  makeArgs = { flags ? [ ], scripts, ... }:
-    spaces (flags ++ scripts);
-
-  /* Build a single resholve invocation */
-  makeInvocation = solution: value:
-    if validateSolution value then
-    # we pass resholve a directory
-      "RESHOLVE_LORE=${binlore.collect { drvs = value.inputs; } } ${makeEnvs solution value} resholve --overwrite ${makeArgs value}"
-    else throw "invalid solution"; # shouldn't trigger for now
-
-  /* Build resholve invocation for each solution. */
-  makeCommands = solutions:
-    lib.mapAttrsToList makeInvocation solutions;
 
   self = (stdenv.mkDerivation ((removeAttrs attrs [ "solutions" ])
     // {
@@ -99,7 +29,7 @@ let
         PS4=$'\x1f'"\033[33m[resholve context]\033[0m "
         set -x
         : changing directory to $PWD
-        ${builtins.concatStringsSep "\n" (makeCommands solutions)}
+        ${builtins.concatStringsSep "\n" (resholve-utils.makeCommands solutions)}
       )
     '';
   }));
diff --git a/pkgs/development/misc/resholve/resholve-utils.nix b/pkgs/development/misc/resholve/resholve-utils.nix
new file mode 100644
index 000000000000..2d3c55b87563
--- /dev/null
+++ b/pkgs/development/misc/resholve/resholve-utils.nix
@@ -0,0 +1,74 @@
+{ lib, resholve, binlore }:
+
+rec {
+  /* These functions break up the work of partially validating the
+    'solutions' attrset and massaging it into env/cli args.
+
+    Note: some of the left-most args do not *have* to be passed as
+    deep as they are, but I've done so to provide more error context
+  */
+
+  # for brevity / line length
+  spaces = l: builtins.concatStringsSep " " l;
+  semicolons = l: builtins.concatStringsSep ";" l;
+
+  /* Throw a fit with dotted attr path context */
+  nope = path: msg:
+    throw "${builtins.concatStringsSep "." path}: ${msg}";
+
+  /* Special-case directive value representations by type */
+  makeDirective = solution: env: name: val:
+    if builtins.isInt val then builtins.toString val
+    else if builtins.isString val then name
+    else if true == val then name
+    else if false == val then "" # omit!
+    else if null == val then "" # omit!
+    else if builtins.isList val then "${name}:${semicolons val}"
+    else nope [ solution env name ] "unexpected type: ${builtins.typeOf val}";
+
+  /* Build fake/fix/keep directives from Nix types */
+  makeDirectives = solution: env: val:
+    lib.mapAttrsToList (makeDirective solution env) val;
+
+  /* Special-case value representation by type/name */
+  makeEnvVal = solution: env: val:
+    if env == "inputs" then lib.makeBinPath val
+    else if builtins.isString val then val
+    else if builtins.isList val then spaces val
+    else if builtins.isAttrs val then spaces (makeDirectives solution env val)
+    else nope [ solution env ] "unexpected type: ${builtins.typeOf val}";
+
+  /* Shell-format each env value */
+  shellEnv = solution: env: value:
+    lib.escapeShellArg (makeEnvVal solution env value);
+
+  /* Build a single ENV=val pair */
+  makeEnv = solution: env: value:
+    "RESHOLVE_${lib.toUpper env}=${shellEnv solution env value}";
+
+  /* Discard attrs claimed by makeArgs */
+  removeCliArgs = value:
+    removeAttrs value [ "scripts" "flags" ];
+
+  /* Verify required arguments are present */
+  validateSolution = { scripts, inputs, interpreter, ... }: true;
+
+  /* Pull out specific solution keys to build ENV=val pairs */
+  makeEnvs = solution: value:
+    spaces (lib.mapAttrsToList (makeEnv solution) (removeCliArgs value));
+
+  /* Pull out specific solution keys to build CLI argstring */
+  makeArgs = { flags ? [ ], scripts, ... }:
+    spaces (flags ++ scripts);
+
+  /* Build a single resholve invocation */
+  makeInvocation = solution: value:
+    if validateSolution value then
+    # we pass resholve a directory
+      "RESHOLVE_LORE=${binlore.collect { drvs = value.inputs; } } ${makeEnvs solution value} ${resholve}/bin/resholve --overwrite ${makeArgs value}"
+    else throw "invalid solution"; # shouldn't trigger for now
+
+  /* Build resholve invocation for each solution. */
+  makeCommands = solutions:
+    lib.mapAttrsToList makeInvocation solutions;
+}