2021-01-29 15:39:33 +01:00
|
|
|
{ depot, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
netencode = {
|
2021-04-23 22:04:42 +02:00
|
|
|
rust = depot.nix.writers.rustSimpleLib
|
|
|
|
{
|
2021-01-29 15:39:33 +01:00
|
|
|
name = "arglib-netencode";
|
|
|
|
dependencies = [
|
2021-02-08 03:23:53 +01:00
|
|
|
depot.users.Profpatsch.execline.exec-helpers
|
2021-01-29 15:39:33 +01:00
|
|
|
depot.users.Profpatsch.netencode.netencode-rs
|
|
|
|
];
|
|
|
|
} ''
|
|
|
|
extern crate netencode;
|
2021-02-08 03:23:53 +01:00
|
|
|
extern crate exec_helpers;
|
2021-01-29 15:39:33 +01:00
|
|
|
|
|
|
|
use netencode::{T};
|
|
|
|
use std::os::unix::ffi::OsStrExt;
|
|
|
|
|
2021-02-08 03:23:53 +01:00
|
|
|
pub fn arglib_netencode(prog_name: &str, env: Option<&std::ffi::OsStr>) -> T {
|
2021-01-29 15:39:33 +01:00
|
|
|
let env = match env {
|
|
|
|
None => std::ffi::OsStr::from_bytes("ARGLIB_NETENCODE".as_bytes()),
|
|
|
|
Some(a) => a
|
|
|
|
};
|
2021-02-09 20:55:35 +01:00
|
|
|
let t = match std::env::var_os(env) {
|
2021-02-08 03:23:53 +01:00
|
|
|
None => exec_helpers::die_user_error(prog_name, format!("could not read args, envvar {} not set", env.to_string_lossy())),
|
2021-01-29 15:39:33 +01:00
|
|
|
// TODO: good error handling for the different parser errors
|
|
|
|
Some(soup) => match netencode::parse::t_t(soup.as_bytes()) {
|
|
|
|
Ok((remainder, t)) => match remainder.is_empty() {
|
2021-02-08 03:23:53 +01:00
|
|
|
true => t,
|
|
|
|
false => exec_helpers::die_environment_problem(prog_name, format!("arglib: there was some unparsed bytes remaining: {:?}", remainder))
|
2021-01-29 15:39:33 +01:00
|
|
|
},
|
2021-02-08 03:23:53 +01:00
|
|
|
Err(err) => exec_helpers::die_environment_problem(prog_name, format!("arglib parsing error: {:?}", err))
|
2021-01-29 15:39:33 +01:00
|
|
|
}
|
2021-02-09 20:55:35 +01:00
|
|
|
};
|
|
|
|
std::env::remove_var(env);
|
|
|
|
t
|
2021-01-29 15:39:33 +01:00
|
|
|
}
|
|
|
|
'';
|
2022-08-20 02:34:02 +02:00
|
|
|
|
|
|
|
haskell = pkgs.haskellPackages.mkDerivation {
|
|
|
|
pname = "arglib-netencode";
|
|
|
|
version = "0.1.0";
|
|
|
|
|
|
|
|
src = depot.users.Profpatsch.exactSource ./. [
|
|
|
|
./arglib-netencode.cabal
|
|
|
|
./ArglibNetencode.hs
|
|
|
|
];
|
|
|
|
|
|
|
|
libraryHaskellDepends = [
|
|
|
|
depot.users.Profpatsch.my-prelude
|
|
|
|
depot.users.Profpatsch.netencode.netencode-hs
|
|
|
|
depot.users.Profpatsch.execline.exec-helpers-hs
|
|
|
|
];
|
|
|
|
|
|
|
|
isLibrary = true;
|
|
|
|
license = lib.licenses.mit;
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-01-29 15:39:33 +01:00
|
|
|
};
|
|
|
|
|
2021-11-23 14:31:17 +01:00
|
|
|
in
|
|
|
|
depot.nix.readTree.drvTargets netencode
|