about summary refs log tree commit diff
path: root/users/Profpatsch/execline/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'users/Profpatsch/execline/default.nix')
-rw-r--r--users/Profpatsch/execline/default.nix45
1 files changed, 39 insertions, 6 deletions
diff --git a/users/Profpatsch/execline/default.nix b/users/Profpatsch/execline/default.nix
index 752774e6ad..04d07895c6 100644
--- a/users/Profpatsch/execline/default.nix
+++ b/users/Profpatsch/execline/default.nix
@@ -1,11 +1,22 @@
 { depot, pkgs, lib, ... }:
 
 let
-  exec-helpers = depot.nix.writers.rustSimpleLib
-    {
-      name = "exec-helpers";
-    }
-    (builtins.readFile ./exec_helpers.rs);
+  exec-helpers-hs = pkgs.haskellPackages.mkDerivation {
+    pname = "exec-helpers";
+    version = "0.1.0";
+
+    src = depot.users.Profpatsch.exactSource ./. [
+      ./exec-helpers.cabal
+      ./ExecHelpers.hs
+    ];
+
+    libraryHaskellDepends = [
+      depot.users.Profpatsch.my-prelude
+    ];
+
+    isLibrary = true;
+    license = lib.licenses.mit;
+  };
 
   print-one-env = depot.nix.writers.rustSimple
     {
@@ -28,10 +39,32 @@ let
     }
   '';
 
+  setsid = depot.nix.writers.rustSimple
+    {
+      name = "setsid";
+      dependencies = [
+        depot.users.Profpatsch.execline.exec-helpers
+        depot.third_party.rust-crates.libc
+      ];
+    } ''
+    use std::os::unix::ffi::OsStrExt;
+    use std::ffi::OsStr;
+
+    fn main() {
+      let (args, prog) = exec_helpers::args_for_exec("setsid", 1);
+      let envvar = OsStr::from_bytes(&args.get(0).expect("first argument must be envvar name to set"));
+      let sid: i32 = unsafe { libc::setsid() };
+      std::env::set_var(envvar, format!("{}", sid));
+      let env: Vec<(&[u8], &[u8])> = vec![];
+      exec_helpers::exec_into_args("getid", prog, env);
+    }
+  '';
+
 in
 depot.nix.readTree.drvTargets {
   inherit
-    exec-helpers
+    exec-helpers-hs
     print-one-env
+    setsid
     ;
 }