about summary refs log tree commit diff
path: root/users/Profpatsch/execline/default.nix
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2021-01-31T14·47+0100
committerProfpatsch <mail@profpatsch.de>2021-01-31T16·06+0000
commit83634341aa6683e1b96717757557c7d83a89b3fd (patch)
tree8dbea658a13924e26b7dbb262ec8a7dcb7625035 /users/Profpatsch/execline/default.nix
parentf0579313d31ac7fafe0f05ee55ecb305bc1cbe23 (diff)
feat(users/Profpatsch/execline): add args_for_exec r/2175
`exec_into_args` would just read argv and exec into it, but we want to
be able to write commands which take some positional arguments first.

Thus we split the invocation into `args_for_exec`, which returns the
positional arguments and prog, and then pass prog to `exec_into_args`
when we want to exec eventually (prog is still an iterator at this
point).

Change-Id: I0b180c1a100b96363fe33ba2c42034ed41716b7a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2474
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch/execline/default.nix')
-rw-r--r--users/Profpatsch/execline/default.nix17
1 files changed, 1 insertions, 16 deletions
diff --git a/users/Profpatsch/execline/default.nix b/users/Profpatsch/execline/default.nix
index 51f4923e9628..852fcfcfa005 100644
--- a/users/Profpatsch/execline/default.nix
+++ b/users/Profpatsch/execline/default.nix
@@ -3,22 +3,7 @@
 let
   exec-helpers = depot.users.Profpatsch.writers.rustSimpleLib {
     name = "exec-helpers";
-  } ''
-    use std::os::unix::process::CommandExt;
-    use std::ffi::OsStr;
-    use std::os::unix::ffi::OsStrExt;
-    pub fn exec_into_args<'a, I>(prog_name: &str, env_additions: I) -> !
-      where
-        I: IntoIterator<Item = (&'a [u8], &'a [u8])>,
-    {
-        let mut argv = std::env::args_os();
-        let prog = argv.nth(1).expect(&format!("{}: first argument must be an executable", prog_name));
-        let args = argv;
-        let env = env_additions.into_iter().map(|(k,v)| (OsStr::from_bytes(k), OsStr::from_bytes(v)));
-        let err = std::process::Command::new(prog).args(args).envs(env).exec();
-        panic!("{}: exec failed: {:?}", prog_name, err);
-    }
-  '';
+  } (builtins.readFile ./exec_helpers.rs);
 
 in {
   inherit