about summary refs log tree commit diff
path: root/users
diff options
context:
space:
mode:
Diffstat (limited to 'users')
-rw-r--r--users/Profpatsch/execline/default.nix27
1 files changed, 27 insertions, 0 deletions
diff --git a/users/Profpatsch/execline/default.nix b/users/Profpatsch/execline/default.nix
new file mode 100644
index 000000000000..51f4923e9628
--- /dev/null
+++ b/users/Profpatsch/execline/default.nix
@@ -0,0 +1,27 @@
+{ depot, pkgs, lib, ... }:
+
+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);
+    }
+  '';
+
+in {
+  inherit
+    exec-helpers
+    ;
+}