Skip to content

Instantly share code, notes, and snippets.

@con-f-use
Last active September 10, 2026 22:30
Show Gist options
  • Select an option

  • Save con-f-use/a3581294dd54f44763a2d5f9c9996c76 to your computer and use it in GitHub Desktop.

Select an option

Save con-f-use/a3581294dd54f44763a2d5f9c9996c76 to your computer and use it in GitHub Desktop.
basic shell app
# Build with:
# nix-build -E 'with import <nixpkgs> {}; pkgs.callPackage ./this-file.nix {}'
# Run with:
# result/bin/bunnytest
{ writeShellApplication, fetchurl, sox }:
let
sound = fetchurl {
url = "https://samplelib.com/mp3/sample-3s.mp3";
hash = "sha256-AkRZDytLy2I1K1dOeL6pQOjYnPppgjtSCO9MQ+Cry0Q=";
};
in
writeShellApplication {
name = "bunnytest";
text = '' # or: builtins.readFile ./some-shell-script.sh so you don't have to escape every dollar curly
play "${toString sound}"
'';
runtimeInputs = [ sox ];
}
# Build with:
# nix-build -E 'with import <nixpkgs> {}; pkgs.callPackage ./this-file.nix {}'
# Run with:
# result/bin/bunnytest
{ writeShellApplication, sox, curl }:
writeShellApplication {
name = "bunnytest";
text = '' # or: builtins.readFile ./some-shell-script.sh so you don't have to escape every dollar curly
curl -L 'https://samplelib.com/mp3/sample-3s.mp3' -o /tmp/sample.mp3
play /tmp/sample.mp3
'';
runtimeInputs = [ sox curl ];
}
# requires default.nix from abouve
# run with:
# nix run './'
{
outputs = {nixpkgs, ...}: {
packages = builtins.mapAttrs (system: pkgs: {
default = pkgs.callPackage ./default.nix { };
}) nixpkgs.legacyPackages;
};
}
{
lib,
makeWrapper,
runCommand,
# runtime deps (depend on script)
fish,
tree,
}:
let
# Your external shell script.
src = ./some-script.fish:
binName = "some-script";
deps = [
fish
tree
];
in
runCommand "${binName}"
{
nativeBuildInputs = [ makeWrapper ];
meta = {
mainProgram = "${binName}";
};
}
''
mkdir -p $out/bin
install -m +x ${src} $out/bin/${binName}
wrapProgram $out/bin/${binName} \
--prefix PATH : ${lib.makeBinPath deps}
''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment