tvl-depot/users/Profpatsch/execline/default.nix
Profpatsch fed41f4959 feat(users/Profpatsch): set up stow for nix-home
nix-home is (hopefully) gonna be a home-manager alternative for my
home directory.

Files are symlinked into the home directory via GNU stow (since that
is a tried and tested tool), so first step is to set up the base code
for that.

Implements a small tool that reads a single environment variable and
prints it to stdout.

Change-Id: Ifa3fd9f9e1cedc52c3002196d3971b02cb840e80
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4832
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
Autosubmit: Profpatsch <mail@profpatsch.de>
2022-01-09 09:32:01 +00:00

33 lines
883 B
Nix

{ depot, pkgs, lib, ... }:
let
exec-helpers = depot.nix.writers.rustSimpleLib {
name = "exec-helpers";
} (builtins.readFile ./exec_helpers.rs);
print-one-env = depot.nix.writers.rustSimple {
name = "print-one-env";
dependencies = [
depot.users.Profpatsch.execline.exec-helpers
];
} ''
extern crate exec_helpers;
use std::os::unix::ffi::OsStrExt;
use std::io::Write;
fn main() {
let args = exec_helpers::args("print-one-env", 1);
let valname = std::ffi::OsStr::from_bytes(&args[0]);
match std::env::var_os(&valname) {
None => exec_helpers::die_user_error("print-one-env", format!("Env variable `{:?}` is not set", valname)),
Some(val) => std::io::stdout().write_all(&val.as_bytes()).unwrap()
}
}
'';
in depot.nix.readTree.drvTargets {
inherit
exec-helpers
print-one-env
;
}