Last active
January 19, 2016 15:14
-
-
Save edef1c/147c075bd92c70e65c31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ stdenv, musl, ... }: | |
stdenv.mkDerivation { | |
name = "env-friendly-1.0.0"; | |
unpackPhase = '' | |
cp -v ${./Makefile} Makefile | |
cp -v ${./env.c} env.c | |
''; | |
CFLAGS = "-isystem ${musl}/include -B${musl}/lib -L${musl}/lib"; | |
LDFLAGS = "-static -Wl,--gc-sections"; | |
meta = with stdenv.lib; { | |
description = "An environmentally friendly replacement for /usr/bin/env"; | |
license = licenses.cc0; | |
maintainers = [ "Nathan Zadoks <[email protected]>" ]; | |
platforms = stdenv.lib.platforms.linux; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <string.h> | |
int main(int argc, char *argv[]) { | |
if (argc < 2) { | |
fprintf(stderr, "%s: no command specified\n", argv[0]); | |
exit(-1); | |
} | |
execvp(argv[1], &argv[1]); | |
char* err = strerror(errno); | |
fprintf(stderr, "%s: %s: %s", argv[0], argv[1], err); | |
exit(127); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: env | |
install: env | |
install -D env $(out)/bin/env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, pkgs, lib, ... }: with lib; let | |
env-friendly = callPackage ./. {}; | |
in { | |
system.activationScripts.usrbinenv = mkForce '' | |
mkdir -m 0755 -p /usr/bin | |
ln -sfn ${env-friendly}/bin/env /usr/bin/.env.tmp | |
mv /usr/bin/.env.tmp /usr/bin/env # atomically replace /usr/bin/env | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment