From 0cfe277878425794df5804b71d828161f5a95b43 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 22 Sep 2018 23:09:03 +0200 Subject: pkgs.profpatsch: switch to different import scheme Reference files in `bin` outputs for a derivation as an attribute set, with renaming capabilities. --- pkgs/profpatsch/default.nix | 50 +++++++++++++++---------- pkgs/profpatsch/execline/run-execline-tests.nix | 27 ++++++------- pkgs/profpatsch/execline/run-execline.nix | 12 +++--- pkgs/profpatsch/testing/default.nix | 8 ++-- 4 files changed, 52 insertions(+), 45 deletions(-) (limited to 'pkgs') diff --git a/pkgs/profpatsch/default.nix b/pkgs/profpatsch/default.nix index 5477b83a..692820e6 100644 --- a/pkgs/profpatsch/default.nix +++ b/pkgs/profpatsch/default.nix @@ -1,4 +1,4 @@ -{ stdenv, pkgs }: +{ stdenv, lib, pkgs }: let inherit (pkgs) callPackage; @@ -15,18 +15,20 @@ let ''${eldir}/execlineb $@ ''; - # TODO: use imports! - execlinebCommand = "${execlineb-with-builtins}/bin/execlineb"; - redirfdCommand = "${pkgs.execline}/bin/redirfd"; - importasCommand = "${pkgs.execline}/bin/importas"; - s6TouchCommand = "${pkgs.s6-portable-utils}/bin/s6-touch"; - s6EchoCommand = "${pkgs.s6-portable-utils}/bin/s6-echo"; - ifCommand = "${pkgs.execline}/bin/if"; - s6GrepCommand = "${pkgs.s6-portable-utils}/bin/s6-grep"; - s6CatCommand = "${pkgs.s6-portable-utils}/bin/s6-cat"; - s6TestCommand = "${pkgs.s6-portable-utils}/bin/s6-test"; - s6ChmodCommand = "${pkgs.s6-portable-utils}/bin/s6-chmod"; - execCommand = "${pkgs.execline}/bin/exec"; + # Takes a derivation and a list of binary names + # and returns an attribute set of `name -> path`. + # The list can also contain renames in the form of + # { use, as }, which goes `as -> usePath`. + bins = drv: xs: + let f = x: + # TODO: typecheck + let x' = if builtins.isString x then { use = x; as = x; } else x; + in { + name = x'.as; + value = "${lib.getBin drv}/bin/${x'.use}"; + }; + in builtins.listToAttrs (builtins.map f xs); + in rec { backlight = callPackage ./backlight { inherit (pkgs.xorg) xbacklight; }; @@ -62,22 +64,30 @@ in rec { # todo: factor out calling tests let it = import ./execline/run-execline.nix { - inherit stdenv execlinebCommand redirfdCommand - importasCommand execCommand; + bin = (bins execlineb-with-builtins [ "execlineb" ]) + // (bins pkgs.execline [ "redirfd" "importas" "exec" ]); + inherit stdenv; }; tests = import ./execline/run-execline-tests.nix { runExecline = it; inherit (testing) drvSeqL; inherit (pkgs) coreutils; - inherit stdenv ifCommand redirfdCommand s6CatCommand - s6GrepCommand importasCommand s6TouchCommand - s6TestCommand execlinebCommand s6ChmodCommand; + inherit stdenv; + bin = (bins execlineb-with-builtins [ "execlineb" ]) + // (bins pkgs.execline [ + { use = "if"; as = "execlineIf"; } + "redirfd" "importas" + ]) + // (bins pkgs.s6PortableUtils + [ "s6-cat" "s6-grep" "s6-touch" "s6-test" "s6-chmod" ]); }; in tests; - testing = pkgs.callPackage ./testing { - inherit runExecline s6TouchCommand s6EchoCommand; + testing = import ./testing { + inherit stdenv lib runExecline; + inherit (pkgs) runCommand; + bin = bins pkgs.s6PortableUtils [ "s6-touch" "s6-echo" ]; }; symlink = pkgs.callPackage ./execline/symlink.nix { diff --git a/pkgs/profpatsch/execline/run-execline-tests.nix b/pkgs/profpatsch/execline/run-execline-tests.nix index c2c4c23e..ebfdeb20 100644 --- a/pkgs/profpatsch/execline/run-execline-tests.nix +++ b/pkgs/profpatsch/execline/run-execline-tests.nix @@ -1,7 +1,4 @@ -{ stdenv, drvSeqL, runExecline -, ifCommand, redirfdCommand, s6GrepCommand -, importasCommand, s6TouchCommand, s6CatCommand -, execlinebCommand, s6TestCommand, s6ChmodCommand +{ stdenv, drvSeqL, runExecline, bin # https://www.mail-archive.com/skaware@list.skarnet.org/msg01256.html , coreutils }: @@ -22,7 +19,7 @@ let foreground { ${coreutils}/bin/mv $s $out } - ${s6ChmodCommand} 0755 $out + ${bin.s6-chmod} 0755 $out ''; }; @@ -35,16 +32,16 @@ let fileHasLine = line: file: derivation { name = "file-${file.name}-has-line"; inherit (stdenv) system; - builder = ifCommand; + builder = bin.execlineIf; args = (block [ - redirfdCommand "-r" "0" file # read file to stdin - s6GrepCommand "-F" "-q" line # and grep for the line + bin.redirfd "-r" "0" file # read file to stdin + bin.s6-grep "-F" "-q" line # and grep for the line ]) ++ [ # if the block succeeded, touch $out - importasCommand "-ui" "out" "out" - s6TouchCommand "$out" + bin.importas "-ui" "out" "out" + bin.s6-touch "$out" ]; }; @@ -53,7 +50,7 @@ let name = "basic"; execline = '' importas -ui out out - ${s6TouchCommand} $out + ${bin.s6-touch} $out ''; }; @@ -65,21 +62,21 @@ let importas -ui out out # this pipes stdout of s6-cat to $out # and s6-cat redirects from stdin to stdout - redirfd -w 1 $out ${s6CatCommand} + redirfd -w 1 $out ${bin.s6-cat} ''; }); wrapWithVar = runExecline { name = "wrap-with-var"; builderWrapper = writeScript "var-wrapper" '' - #!${execlinebCommand} -S0 + #!${bin.execlineb} -S0 export myvar myvalue $@ ''; execline = '' importas -ui v myvar - if { ${s6TestCommand} myvalue = $v } + if { ${bin.s6-test} myvalue = $v } importas out out - ${s6TouchCommand} $out + ${bin.s6-touch} $out ''; }; diff --git a/pkgs/profpatsch/execline/run-execline.nix b/pkgs/profpatsch/execline/run-execline.nix index 61c8c2e6..dbc6f4fd 100644 --- a/pkgs/profpatsch/execline/run-execline.nix +++ b/pkgs/profpatsch/execline/run-execline.nix @@ -1,4 +1,4 @@ -{ stdenv, importasCommand, execCommand, redirfdCommand, execlinebCommand }: +{ stdenv, bin }: { name # the execline script as string , execline @@ -6,7 +6,7 @@ , stdin ? "" # a program wrapping the acutal execline invocation; # should be in Bernstein-chaining style -, builderWrapper ? execCommand +, builderWrapper ? bin.exec # additional arguments to pass to the derivation , derivationArgs ? {} }: @@ -37,23 +37,23 @@ derivation (derivationArgs // { builder = builderWrapper; args = [ - importasCommand # import script file as $script + bin.importas # import script file as $script "-ui" # drop the envvar afterwards "script" # substitution name "_runExeclineScriptPath" # passed script file # TODO: can we scrap stdin via builderWrapper? - importasCommand # do the same for $stdin + bin.importas # do the same for $stdin "-ui" "stdin" "_runExeclineStdinPath" - redirfdCommand # now we + bin.redirfd # now we "-r" # read the file "0" # into the stdin of execlineb "$stdin" # that was given via stdin - execlinebCommand # the actual invocation + bin.execlineb # the actual invocation # TODO: depending on the use-case, -S0 might not be enough # in all use-cases, then a wrapper for execlineb arguments # should be added (-P, -S, -s). diff --git a/pkgs/profpatsch/testing/default.nix b/pkgs/profpatsch/testing/default.nix index 55a141d9..21f814e4 100644 --- a/pkgs/profpatsch/testing/default.nix +++ b/pkgs/profpatsch/testing/default.nix @@ -1,5 +1,5 @@ { stdenv, runCommand, lib -, runExecline, s6TouchCommand, s6EchoCommand }: +, runExecline, bin }: let @@ -13,7 +13,7 @@ let /* TODO DOCS */ drvSeqL = drvDeps: drvOut: let - drvOutOutputs = drvOut.outputs or ["out"]; + drvOutOutputs = drvOut.outputs or ["out"]; in runCommand drvOut.name { # we inherit all attributes in order to replicate @@ -76,10 +76,10 @@ let # importas -i out out # ifte # # if $@ succeeds, $out is touched - # { ${s6TouchCommand} $out } + # { ${bin.s6-touch} $out } # # otherwise we return the exit code # { importas exit ? - # ${s6EchoCommand} $exit } + # ${bin.s6-echo} $exit } # # condition # $@ # ''; -- cgit 1.4.1