Add shell mode with nix-scripts

pull/5/head
Michele Guerini Rocco 2019-09-19 17:32:40 +02:00
parent b28f58eeee
commit c631038ee0
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
2 changed files with 9 additions and 3 deletions

View File

@ -5,7 +5,10 @@ pkgs.stdenv.mkDerivation {
src = ./nix-script.hs;
phases = [ "buildPhase" "installPhase" "fixupPhase" ];
buildPhase = ''mkdir -p $out/bin; ghc -O2 $src -o $out/bin/nix-script -odir $TMP'';
installPhase = ''ln -s $out/bin/nix-script $out/bin/nix-scripti'';
installPhase = ''
ln -s $out/bin/nix-script $out/bin/nix-scripti
ln -s $out/bin/nix-script $out/bin/nix-scripts
'';
buildInputs = [ (pkgs.haskellPackages.ghcWithPackages (hs: with hs; [posix-escape])) ];
meta = {
homepage = https://github.com/bennofs/nix-script;

View File

@ -146,9 +146,12 @@ main = do
pkgs = concatMap parseHeader deps
language = dropWhile isSpace identifier
interactive = last progName == 'i'
shell = last progName == 's'
interpreter = makeInter language interactive file
cmd <- makeCmd interpreter args <$> makeEnv env
callProcess "nix-shell" ("--pure" : "--command" : cmd : "-p" : pkgs)
if shell
then callProcess "nix-shell" ("-p" : pkgs)
else callProcess "nix-shell" ("--pure" : "--run" : cmd : "-p" : pkgs)
_ -> fail "missing or invalid header"
_ -> fail "missing or invalid header"