Skip to content

Commit

Permalink
racket-minimal: add writeScript[Bin]
Browse files Browse the repository at this point in the history
  • Loading branch information
rc-zb committed Dec 21, 2024
1 parent a83d79f commit e0cf2f7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkgs/development/interpreters/racket/minimal.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
disableDocs ? false,

callPackage,

writers,
}:

let
Expand Down Expand Up @@ -117,12 +119,31 @@ stdenv.mkDerivation (finalAttrs: {
'';

passthru = {
# Functionalities #
writeScript =
nameOrPath:
{
libraries ? [ ],
...
}@config:
assert lib.assertMsg (libraries == [ ]) "library integration for Racket has not been implemented";
writers.makeScriptWriter (
builtins.removeAttrs config [ "libraries" ]
// {
interpreter = "${lib.getExe finalAttrs.finalPackage}";
}
) nameOrPath;
writeScriptBin = name: finalAttrs.passthru.writeScript "/bin/${name}";

# Tests #
tests = builtins.mapAttrs (name: path: callPackage path { racket = finalAttrs.finalPackage; }) {
## Basic ##
write-greeting = ./tests/write-greeting.nix;
get-current-launcher-variant = ./tests/get-current-launcher-variant.nix;
load-libs = ./tests/load-libs.nix;

## Nixpkgs supports ##
nix-write-script = ./tests/nix-write-script.nix;
};
};

Expand Down
26 changes: 26 additions & 0 deletions pkgs/development/interpreters/racket/tests/nix-write-script.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ runCommandLocal, racket }:

let
script = racket.writeScript "racket-test-nix-write-script-the-script" { } ''
#lang racket/base
(display "success")
(newline)
'';
in

runCommandLocal "racket-test-nix-write-script"
{
nativeBuildInputs = [ racket ];
}
''
expectation="success"
output="$(${script})"
if test "$output" != "$expectation"; then
echo "output mismatch: expected ''${expectation}, but got ''${output}"
exit 1
fi
touch $out
''

0 comments on commit e0cf2f7

Please sign in to comment.