lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Travis A. Everett and committed by
Raphael Megzari
a649cbca 7b03c7ee

+80 -73
+4 -1
pkgs/development/misc/resholve/default.nix
··· 12 12 inherit (source) version; 13 13 inherit (deps.oil) oildev; 14 14 }; 15 + resholve-utils = callPackage ./resholve-utils.nix { 16 + inherit resholve; 17 + }; 15 18 resholvePackage = callPackage ./resholve-package.nix { 16 - inherit resholve; 19 + inherit resholve resholve-utils; 17 20 }; 18 21 }
+2 -72
pkgs/development/misc/resholve/resholve-package.nix
··· 1 - { stdenv, lib, resholve, binlore }: 1 + { stdenv, lib, resholve, resholve-utils }: 2 2 3 3 { pname 4 4 , src ··· 9 9 }@attrs: 10 10 let 11 11 inherit stdenv; 12 - /* These functions break up the work of partially validating the 13 - 'solutions' attrset and massaging it into env/cli args. 14 - 15 - Note: some of the left-most args do not *have* to be passed as 16 - deep as they are, but I've done so to provide more error context 17 - */ 18 - 19 - # for brevity / line length 20 - spaces = l: builtins.concatStringsSep " " l; 21 - semicolons = l: builtins.concatStringsSep ";" l; 22 - 23 - /* Throw a fit with dotted attr path context */ 24 - nope = path: msg: 25 - throw "${builtins.concatStringsSep "." path}: ${msg}"; 26 - 27 - /* Special-case directive value representations by type */ 28 - makeDirective = solution: env: name: val: 29 - if builtins.isInt val then builtins.toString val 30 - else if builtins.isString val then name 31 - else if true == val then name 32 - else if false == val then "" # omit! 33 - else if null == val then "" # omit! 34 - else if builtins.isList val then "${name}:${semicolons val}" 35 - else nope [ solution env name ] "unexpected type: ${builtins.typeOf val}"; 36 - 37 - /* Build fake/fix/keep directives from Nix types */ 38 - makeDirectives = solution: env: val: 39 - lib.mapAttrsToList (makeDirective solution env) val; 40 - 41 - /* Special-case value representation by type/name */ 42 - makeEnvVal = solution: env: val: 43 - if env == "inputs" then lib.makeBinPath val 44 - else if builtins.isString val then val 45 - else if builtins.isList val then spaces val 46 - else if builtins.isAttrs val then spaces (makeDirectives solution env val) 47 - else nope [ solution env ] "unexpected type: ${builtins.typeOf val}"; 48 - 49 - /* Shell-format each env value */ 50 - shellEnv = solution: env: value: 51 - lib.escapeShellArg (makeEnvVal solution env value); 52 - 53 - /* Build a single ENV=val pair */ 54 - makeEnv = solution: env: value: 55 - "RESHOLVE_${lib.toUpper env}=${shellEnv solution env value}"; 56 - 57 - /* Discard attrs claimed by makeArgs */ 58 - removeCliArgs = value: 59 - removeAttrs value [ "scripts" "flags" ]; 60 - 61 - /* Verify required arguments are present */ 62 - validateSolution = { scripts, inputs, interpreter, ... }: true; 63 - 64 - /* Pull out specific solution keys to build ENV=val pairs */ 65 - makeEnvs = solution: value: 66 - spaces (lib.mapAttrsToList (makeEnv solution) (removeCliArgs value)); 67 - 68 - /* Pull out specific solution keys to build CLI argstring */ 69 - makeArgs = { flags ? [ ], scripts, ... }: 70 - spaces (flags ++ scripts); 71 - 72 - /* Build a single resholve invocation */ 73 - makeInvocation = solution: value: 74 - if validateSolution value then 75 - # we pass resholve a directory 76 - "RESHOLVE_LORE=${binlore.collect { drvs = value.inputs; } } ${makeEnvs solution value} resholve --overwrite ${makeArgs value}" 77 - else throw "invalid solution"; # shouldn't trigger for now 78 - 79 - /* Build resholve invocation for each solution. */ 80 - makeCommands = solutions: 81 - lib.mapAttrsToList makeInvocation solutions; 82 12 83 13 self = (stdenv.mkDerivation ((removeAttrs attrs [ "solutions" ]) 84 14 // { ··· 99 29 PS4=$'\x1f'"\033[33m[resholve context]\033[0m " 100 30 set -x 101 31 : changing directory to $PWD 102 - ${builtins.concatStringsSep "\n" (makeCommands solutions)} 32 + ${builtins.concatStringsSep "\n" (resholve-utils.makeCommands solutions)} 103 33 ) 104 34 ''; 105 35 }));
+74
pkgs/development/misc/resholve/resholve-utils.nix
··· 1 + { lib, resholve, binlore }: 2 + 3 + rec { 4 + /* These functions break up the work of partially validating the 5 + 'solutions' attrset and massaging it into env/cli args. 6 + 7 + Note: some of the left-most args do not *have* to be passed as 8 + deep as they are, but I've done so to provide more error context 9 + */ 10 + 11 + # for brevity / line length 12 + spaces = l: builtins.concatStringsSep " " l; 13 + semicolons = l: builtins.concatStringsSep ";" l; 14 + 15 + /* Throw a fit with dotted attr path context */ 16 + nope = path: msg: 17 + throw "${builtins.concatStringsSep "." path}: ${msg}"; 18 + 19 + /* Special-case directive value representations by type */ 20 + makeDirective = solution: env: name: val: 21 + if builtins.isInt val then builtins.toString val 22 + else if builtins.isString val then name 23 + else if true == val then name 24 + else if false == val then "" # omit! 25 + else if null == val then "" # omit! 26 + else if builtins.isList val then "${name}:${semicolons val}" 27 + else nope [ solution env name ] "unexpected type: ${builtins.typeOf val}"; 28 + 29 + /* Build fake/fix/keep directives from Nix types */ 30 + makeDirectives = solution: env: val: 31 + lib.mapAttrsToList (makeDirective solution env) val; 32 + 33 + /* Special-case value representation by type/name */ 34 + makeEnvVal = solution: env: val: 35 + if env == "inputs" then lib.makeBinPath val 36 + else if builtins.isString val then val 37 + else if builtins.isList val then spaces val 38 + else if builtins.isAttrs val then spaces (makeDirectives solution env val) 39 + else nope [ solution env ] "unexpected type: ${builtins.typeOf val}"; 40 + 41 + /* Shell-format each env value */ 42 + shellEnv = solution: env: value: 43 + lib.escapeShellArg (makeEnvVal solution env value); 44 + 45 + /* Build a single ENV=val pair */ 46 + makeEnv = solution: env: value: 47 + "RESHOLVE_${lib.toUpper env}=${shellEnv solution env value}"; 48 + 49 + /* Discard attrs claimed by makeArgs */ 50 + removeCliArgs = value: 51 + removeAttrs value [ "scripts" "flags" ]; 52 + 53 + /* Verify required arguments are present */ 54 + validateSolution = { scripts, inputs, interpreter, ... }: true; 55 + 56 + /* Pull out specific solution keys to build ENV=val pairs */ 57 + makeEnvs = solution: value: 58 + spaces (lib.mapAttrsToList (makeEnv solution) (removeCliArgs value)); 59 + 60 + /* Pull out specific solution keys to build CLI argstring */ 61 + makeArgs = { flags ? [ ], scripts, ... }: 62 + spaces (flags ++ scripts); 63 + 64 + /* Build a single resholve invocation */ 65 + makeInvocation = solution: value: 66 + if validateSolution value then 67 + # we pass resholve a directory 68 + "RESHOLVE_LORE=${binlore.collect { drvs = value.inputs; } } ${makeEnvs solution value} ${resholve}/bin/resholve --overwrite ${makeArgs value}" 69 + else throw "invalid solution"; # shouldn't trigger for now 70 + 71 + /* Build resholve invocation for each solution. */ 72 + makeCommands = solutions: 73 + lib.mapAttrsToList makeInvocation solutions; 74 + }