writers: add babashka (#343510)

This commit is contained in:
lassulus
2024-10-04 21:40:48 +01:00
committed by GitHub
2 changed files with 123 additions and 0 deletions
+83
View File
@@ -522,6 +522,89 @@ rec {
*/
writeFishBin = name: writeFish "/bin/${name}";
/**
Like writeScript but the first line is a shebang to babashka
Can be called with or without extra arguments.
:::{.example}
## `pkgs.writers.writeBabashka` without arguments
```nix
writeBabashka "example" ''
(println "hello world")
''
```
:::
:::{.example}
## `pkgs.writers.writeBabashka` with arguments
```nix
writeBabashka "example"
{
makeWrapperArgs = [
"--prefix" "PATH" ":" "${lib.makeBinPath [ pkgs.hello ]}"
];
}
''
(require '[babashka.tasks :as tasks])
(tasks/shell "hello" "-g" "Hello babashka!")
''
```
:::
*/
writeBabashka =
name: argsOrScript:
if lib.isAttrs argsOrScript && !lib.isDerivation argsOrScript then
makeScriptWriter (
argsOrScript
// {
interpreter = "${lib.getExe pkgs.babashka}";
check = "${lib.getExe pkgs.clj-kondo} --lint";
}
) name
else
makeScriptWriter {
interpreter = "${lib.getExe pkgs.babashka}";
check = "${lib.getExe pkgs.clj-kondo} --lint";
} name argsOrScript;
/**
Like writeScriptBin but the first line is a shebang to babashka
Can be called with or without extra arguments.
# Examples
:::{.example}
## `pkgs.writers.writeBabashkaBin` without arguments
```nix
writeBabashkaBin "example" ''
(println "hello world")
''
```
:::
:::{.example}
## `pkgs.writers.writeBabashkaBin` with arguments
```nix
writeBabashkaBin "example"
{
makeWrapperArgs = [
"--prefix" "PATH" ":" "${lib.makeBinPath [ pkgs.hello ]}"
];
}
''
(require '[babashka.tasks :as tasks])
(tasks/shell "hello" "-g" "Hello babashka!")
''
```
:::
*/
writeBabashkaBin = name: writeBabashka "/bin/${name}";
/**
writeHaskell takes a name, an attrset with libraries and haskell version (both optional)
and some haskell source code and returns an executable.
+40
View File
@@ -18,6 +18,8 @@ let
makeFSharpWriter
writeBash
writeBashBin
writeBabashka
writeBabashkaBin
writeDash
writeDashBin
writeFish
@@ -85,6 +87,10 @@ recurseIntoAttrs {
end
'');
babashka = expectSuccessBin (writeBabashkaBin "test-writers-babashka-bin" ''
(println "success")
'');
rust = expectSuccessBin (writeRustBin "test-writers-rust-bin" {} ''
fn main(){
println!("success")
@@ -189,6 +195,10 @@ recurseIntoAttrs {
echo "success"
'');
babashka = expectSuccess (writeBabashka "test-writers-babashka" ''
(println "success")
'');
haskell = expectSuccess (writeHaskell "test-writers-haskell" { libraries = [ haskellPackages.acme-default ]; } ''
import Data.Default
@@ -371,6 +381,36 @@ recurseIntoAttrs {
''
);
babashka-bin = expectSuccessBin (
writeBabashkaBin "test-writers-wrapping-babashka-bin"
{
makeWrapperArgs = [
"--set"
"ThaigerSprint"
"Thailand"
];
}
''
(when (= (System/getenv "ThaigerSprint") "Thailand")
(println "success"))
''
);
babashka = expectSuccess (
writeBabashka "test-writers-wrapping-babashka"
{
makeWrapperArgs = [
"--set"
"ThaigerSprint"
"Thailand"
];
}
''
(when (= (System/getenv "ThaigerSprint") "Thailand")
(println "success"))
''
);
python = expectSuccess (
writePython3 "test-writers-wrapping-python"
{