From c631038ee0bebd5ff4f049d31d2e04a800194272 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Thu, 19 Sep 2019 17:32:40 +0200 Subject: [PATCH] Add shell mode with nix-scripts --- default.nix | 5 ++++- nix-script.hs | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/default.nix b/default.nix index 6af4803..1c95966 100644 --- a/default.nix +++ b/default.nix @@ -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; diff --git a/nix-script.hs b/nix-script.hs index 7c0a893..25d264b 100755 --- a/nix-script.hs +++ b/nix-script.hs @@ -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" \ No newline at end of file + _ -> fail "missing or invalid header"