From 45f2a37b67d1a890330bf6baa98e3b364a5103c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benno=20F=C3=BCnfst=C3=BCck?= Date: Sun, 31 Aug 2014 18:04:27 +0200 Subject: [PATCH] rename to nix-script (nixbang already exists) --- README.md | 39 ++++++++++++++++++++++++++++-------- default.nix | 12 +++++------ nix-bang.hs => nix-script.hs | 0 3 files changed, 37 insertions(+), 14 deletions(-) rename nix-bang.hs => nix-script.hs (100%) mode change 100755 => 100644 diff --git a/README.md b/README.md index 43c1a33..db794fc 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,15 @@ -nix-bang -======== +nix-script +========== -The Nix-bang script allows you to define dependencies at the top of scripts which will then be used to create a nix-shell environment when run. This project is only useful if you're using the nix package manager. +Nix-script allows you to define dependencies at the top of scripts which will then be used to create a nix-shell environment when run. This project is only useful if you're using the nix package manager. + +Features: + + * Run scripts in an isolated environment with only the required dependencies + * Load scripts in an interpreter in that environment Installation ------------- +------------- Clone the repository and run: @@ -12,24 +17,42 @@ Clone the repository and run: $ nix-env -if. ``` -This will install the `nix-bang` and `nix-bangi` files into your user profile. +This will install the `nix-script` and `nix-scripti` files into your user profile. Usage ----- -To use `nix-bang`, you need to add a header to your file. Here is an example for a haskell file: +To use `nix-script`, you need to add a header to your file. Here is an example for a haskell file `example.hs`: ```haskell -#!nix-bang +#!nix-script #!> haskell #! haskell | text lens optparse-applicative #! shell | nix nix-prefetch-scripts + +{- ... code using text, lens and optparse-applicative -} + +main :: IO () +main = {- ... -} ``` -The first line just tells the shell to use `nix-bang` when executing the script. The next line is then read by `nix-bang` to determine the language used for running the script. In this case, we tell `nix-bang` that we want haskell, so it will use `runhaskell` to execute the script. +The first line just tells the shell to use `nix-script` when executing the script. The next line is then read by `nix-script` to determine the language used for running the script. In this case, we tell `nix-script` that we want haskell, so it will use `runhaskell` to execute the script. The next lines the specify dependencies of the script. The first entry on each line is the language of the following dependencies. This is required so that language-specific names can be converted to the correct nix attribute names. You should have one line per language. In our case, we say that we want to use the `text`, `lens` and `optparse-applicative` haskell packages. We also want that `nix` and `nix-prefetch-scripts` are available in $PATH (the `shell` language doesn't apply any renaming to their dependencies and just passes them through unmodified). +We can now mark the script executable and run it: + +``` +$ chmod +x ./example.hs +$ ./example.hs # This works even if you don't have ghc, text, lens or optparse-applicative installed +``` + +We can also load the script in `ghci`: + +``` +$ nix-scripti ./example.hs +``` + Contributing ------------ diff --git a/default.nix b/default.nix index 22d9540..1b10b31 100644 --- a/default.nix +++ b/default.nix @@ -1,17 +1,17 @@ { pkgs ? import {} }: pkgs.stdenv.mkDerivation { - name = "nix-bang"; - src = ./nix-bang.hs; + name = "nix-script"; + src = ./nix-script.hs; phases = [ "buildPhase" "installPhase" "fixupPhase" ]; - buildPhase = ''mkdir $out; ghc -O2 $src -o $out/nix-bang -odir $TMP''; - installPhase = ''ln -s $out/nix-bang $out/nix-bangi''; + 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''; buildInputs = [ (pkgs.haskellPackages.ghcWithPackages (hs: with hs; [lens text])) ]; meta = { - homepage = https://github.com/bennofs/nix-bang; + homepage = https://github.com/bennofs/nix-script; description = "A shebang for running inside nix-shell."; license = pkgs.lib.licenses.bsd3; maintainers = [ pkgs.lib.maintainers.bennofs ]; platforms = pkgs.haskellPackages.ghc.meta.platforms; }; -} \ No newline at end of file +} diff --git a/nix-bang.hs b/nix-script.hs old mode 100755 new mode 100644 similarity index 100% rename from nix-bang.hs rename to nix-script.hs