mirror of
https://github.com/bennofs/nix-script
synced 2025-01-09 20:34:20 +01:00
commit
7706b45429
19
README.md
19
README.md
@ -56,6 +56,25 @@ We can also load the script in `ghci`:
|
|||||||
$ nix-scripti ./example.hs
|
$ nix-scripti ./example.hs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or open a nix-shell with the requested packages:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ nix-scripts ./example.hs
|
||||||
|
```
|
||||||
|
|
||||||
|
### Supported languges
|
||||||
|
|
||||||
|
| Identifiers | Language |
|
||||||
|
|:--------------------:|:---------------------|
|
||||||
|
| `haskell` | Haskell |
|
||||||
|
| `python2`, `python3` | Python |
|
||||||
|
| `perl` | Perl 5 |
|
||||||
|
| `javascript` | JavaScript (node.js) |
|
||||||
|
| `shell` | Shell script (bash) |
|
||||||
|
|
||||||
|
Anything else will be treated as "passthough", meaning the rest of
|
||||||
|
the line will be intpreted as nixpkgs attributes as-is.
|
||||||
|
|
||||||
Contributing
|
Contributing
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
@ -5,7 +5,10 @@ pkgs.stdenv.mkDerivation {
|
|||||||
src = ./nix-script.hs;
|
src = ./nix-script.hs;
|
||||||
phases = [ "buildPhase" "installPhase" "fixupPhase" ];
|
phases = [ "buildPhase" "installPhase" "fixupPhase" ];
|
||||||
buildPhase = ''mkdir -p $out/bin; ghc -O2 $src -o $out/bin/nix-script -odir $TMP'';
|
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])) ];
|
buildInputs = [ (pkgs.haskellPackages.ghcWithPackages (hs: with hs; [posix-escape])) ];
|
||||||
meta = {
|
meta = {
|
||||||
homepage = https://github.com/bennofs/nix-script;
|
homepage = https://github.com/bennofs/nix-script;
|
||||||
|
@ -43,7 +43,7 @@ baseEnv = ["LOCALE_ARCHIVE", "SSL_CERT_FILE" ,"LANG", "TERMINFO", "TERM"]
|
|||||||
|
|
||||||
-- | List of supported language definitions
|
-- | List of supported language definitions
|
||||||
languages :: [Language]
|
languages :: [Language]
|
||||||
languages = [haskell, python, javascript, perl, shell]
|
languages = [haskell, python 2, python 3, javascript, perl, shell]
|
||||||
where
|
where
|
||||||
haskell = Language "haskell" d r i where
|
haskell = Language "haskell" d r i where
|
||||||
d pkgs = pure ("haskellPackages.ghcWithPackages (hs: with hs; [" ++
|
d pkgs = pure ("haskellPackages.ghcWithPackages (hs: with hs; [" ++
|
||||||
@ -51,10 +51,12 @@ languages = [haskell, python, javascript, perl, shell]
|
|||||||
r script = ("runghc" , [script])
|
r script = ("runghc" , [script])
|
||||||
i script = ("ghci" , [script])
|
i script = ("ghci" , [script])
|
||||||
|
|
||||||
python = Language "python" d r i where
|
python v = Language ("python" ++ show v) d r i where
|
||||||
d pkgs = "python" : map ("pythonPackages." ++) pkgs
|
d pkgs = pure ("python" ++ (show v) ++
|
||||||
r script = ("python" , [script])
|
".withPackages (py: with py; [" ++
|
||||||
i script = ("python" , ["-i", script])
|
unwords pkgs ++ "])")
|
||||||
|
r script = ("python" ++ show v, [script])
|
||||||
|
i script = ("python" ++ show v, ["-i", script])
|
||||||
|
|
||||||
javascript = Language "javascript" d r i where
|
javascript = Language "javascript" d r i where
|
||||||
d pkgs = "node" : map ("nodePackages." ++) pkgs
|
d pkgs = "node" : map ("nodePackages." ++) pkgs
|
||||||
@ -62,7 +64,8 @@ languages = [haskell, python, javascript, perl, shell]
|
|||||||
i script = ("node" , [])
|
i script = ("node" , [])
|
||||||
|
|
||||||
perl = Language "perl" d r i where
|
perl = Language "perl" d r i where
|
||||||
d pkgs = "perl" : map ("perlPackages." ++) pkgs
|
d pkgs = pure ("perl.withPackages (pl: with pl; [" ++
|
||||||
|
unwords pkgs ++ "])")
|
||||||
r script = ("perl" , [script])
|
r script = ("perl" , [script])
|
||||||
i script = ("perl" , ["-d", script])
|
i script = ("perl" , ["-d", script])
|
||||||
|
|
||||||
@ -143,9 +146,12 @@ main = do
|
|||||||
pkgs = concatMap parseHeader deps
|
pkgs = concatMap parseHeader deps
|
||||||
language = dropWhile isSpace identifier
|
language = dropWhile isSpace identifier
|
||||||
interactive = last progName == 'i'
|
interactive = last progName == 'i'
|
||||||
|
shell = last progName == 's'
|
||||||
interpreter = makeInter language interactive file
|
interpreter = makeInter language interactive file
|
||||||
|
|
||||||
cmd <- makeCmd interpreter args <$> makeEnv env
|
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"
|
||||||
|
Loading…
Reference in New Issue
Block a user