From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 2AyGEtIyTGBjZAAA0tVLHw (envelope-from ) for ; Sat, 13 Mar 2021 03:34:42 +0000 Received: from aspmx2.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id yKg/DtIyTGBhDgAAB5/wlQ (envelope-from ) for ; Sat, 13 Mar 2021 03:34:42 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx2.migadu.com (Postfix) with ESMTPS id 556FC2725E for ; Sat, 13 Mar 2021 04:34:41 +0100 (CET) Received: from localhost ([::1]:36414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lKv31-0005RV-KW for larch@yhetil.org; Fri, 12 Mar 2021 22:34:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKv2t-0005RK-3m for help-guix@gnu.org; Fri, 12 Mar 2021 22:34:31 -0500 Received: from mx1.riseup.net ([198.252.153.129]:46460) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKv2r-0001js-7w for help-guix@gnu.org; Fri, 12 Mar 2021 22:34:30 -0500 Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "Sectigo RSA Domain Validation Secure Server CA" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4Dy7b66XCSzDqqR for ; Fri, 12 Mar 2021 19:34:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1615606466; bh=N9rjs9Me0copvMJYIZKXTUkk2xMzd9yBpzfCpohFBjM=; h=Date:From:To:Subject:From; b=Nq3hkMqF0e2DfYztvCxevy9WVfnj8CtO+doXQ3OQtLVAiMLYTrgCjKpYvn544Y/hr jooyo1OQ3taD29k80ijF+H+xr1HDE8JuawIp90G2slaxezpXKuiEp1cLMXILsHgg9u G5emRCdqwRGmVtwYN7Wuw9PM0vgbNRYIa27W2xG0= X-Riseup-User-ID: 937459686E47C48E5AA62D4F9FFBD22B4810672E7F1274D662F5FEC1B926458E Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4Dy7b61ZgDz5vNY for ; Fri, 12 Mar 2021 19:34:25 -0800 (PST) Date: Sat, 13 Mar 2021 04:34:10 +0100 From: raingloom To: "help-guix@gnu.org" Subject: Black magic to pass around environment variables? Message-ID: <20210313043410.2366cddc@riseup.net> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=198.252.153.129; envelope-from=raingloom@riseup.net; helo=mx1.riseup.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-guix@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-guix-bounces+larch=yhetil.org@gnu.org Sender: "Help-Guix" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1615606481; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=N9rjs9Me0copvMJYIZKXTUkk2xMzd9yBpzfCpohFBjM=; b=oeVmgR7O5wH21HStSovKC4kepxI8pYqlZAGp+975g3B4c4lZWk1/z1YyHPlDk3bYQtB7iS L4AfiRUAuCZK/A7jfmOEkufWRsCVdGrZl9zwNtBiw8ryH8ONnG1L9bkfdHzAYE5+5qwZXc 133ReSB23gacBZEwWcbc57sUCpubL6Mvlgkweco2jCa/rQ61zRaOQRk8+ceUuv6AXobSLb 1bE8oEMeJEWPkRmFp77KJD5AtSllvI96RJAu24OpLmlOTDGtxnWJx8RTHYYGWcX2IC7Dx+ U1z0Jk6xCs0u7A37uhl0N1+oOTQzH23VcM7vnfxc5hp0Uj1joypsF6qxchoXOw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615606481; a=rsa-sha256; cv=none; b=FE3LsxzxPGS975EEIxS04aJGluP4Vg/prbEKVikiXY3lOV7Q7AbrFYQkvkqTM5An1xRa3U t60gdQ9ynh0f0j+jaNbb4ljtpKFWIzBd4VdjeJpXkb5AzkDUy8RRgsOhsPuiyt+QZU76+9 nUkS0tC6iWt2qwMeC4+ZY5q79lIMhpxFKC4A9882ZVOg7au7UtODLS6EwtNpLUhrHtCC+l UHi9Yi0YZcQgbKv+0JVKl/tb+Y8ycNnodVxUfFpVBCr/a8Id8mPhnr9NbtXZmO6TuZg/Wf X8iOqnuN3WYbLx0dzarRY+PMI40KX1kxxCvicrZGMuNQ8PrynF8Df4iBgXax5w== ARC-Authentication-Results: i=1; aspmx2.migadu.com; dkim=pass header.d=riseup.net header.s=squak header.b=Nq3hkMqF; spf=pass (aspmx2.migadu.com: domain of help-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=help-guix-bounces@gnu.org X-Migadu-Spam-Score: -2.09 Authentication-Results: aspmx2.migadu.com; dkim=pass header.d=riseup.net header.s=squak header.b=Nq3hkMqF; dmarc=pass (policy=none) header.from=riseup.net; spf=pass (aspmx2.migadu.com: domain of help-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=help-guix-bounces@gnu.org X-Migadu-Queue-Id: 556FC2725E X-Spam-Score: -2.09 X-Migadu-Scanner: scn0.migadu.com X-TUID: Q1FCN62bXRvS Motivation: xfce4-terminal runs as a terminal and doesn't propagate environment variables, which makes it a bit cumbersome to use it with complex `guix environment` setups. While an upstream fix would be nice, this is a general problem and one that shouldn't require special handling in every application. Partial solution: Saving environment variables is relatively easy, just use `env -0`. Since they are all C strings, they can't contain null bytes. Serialization solved. Loading is a bit more difficult, at least if you want to make the solution Bourne Shell friendly. Yes, I too am planning to try Ambrevar's Lisp shell setup, but until then, I need something that works with regular old (bad) Unix tools. This is what I have so far: ``` xargs -x0a <(env -0) -- sh -c 'env - $@ tcc -version' ``` Explanation: xargs: -a lets us load the environment variables from a file, which sidesteps expansions -0 uses null terminated string format, instead of splitting on whitespace -x makes sure that even in the unlikely case when we run into execve limits, xargs still won't split the argument list and will just error instead sh: we need it (or some other wrapper) because xargs can only append argument lists or insert single arguments, but can't insert argument lists, so we reorder them to come before the fixed arguments we want to pass to the command. This mostly works in isolation, but the most important use case - starting a new Zsh session - doesn't. ``` xfce4-terminal -x xargs -x0a <(env -0) -- 'env - $@ zsh' ``` This results in a terminal popping up and closing immediately. It also has the significant downside that trying to wrap it into a script that passes arbitrary arguments to the command will require escaping things for sh again. Any ideas on how to proceed?