Shell Scripts: Difference between revisions
imported>Milahu + section Posix Shell |
imported>Milahu + Packaging example |
||
Line 2: | Line 2: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
someBuildHelper = { name, sha256 }: | someBuildHelper = { name, sha256 }: | ||
stdenv.mkDerivation { | stdenv.mkDerivation { | ||
Line 16: | Line 15: | ||
}; | }; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
== Packaging == | |||
example: | |||
<syntaxHighlight lang="nix"> | |||
# nix-build -E 'with import <nixpkgs> { }; callPackage ./default.nix { }' | |||
{ stdenv | |||
, lib | |||
, fetchFromGitHub | |||
, bash | |||
, subversion | |||
, makeWrapper | |||
}: | |||
stdenv.mkDerivation { | |||
pname = "github-downloader"; | |||
version = "08049f6"; | |||
src = fetchFromGitHub { | |||
# https://github.com/Decad/github-downloader | |||
owner = "Decad"; | |||
repo = "github-downloader"; | |||
rev = "08049f6183e559a9a97b1d144c070a36118cca97"; | |||
sha256 = "073jkky5svrb7hmbx3ycgzpb37hdap7nd9i0id5b5yxlcnf7930r"; | |||
}; | |||
buildInputs = [ bash subversion ]; | |||
nativeBuildInputs = [ makeWrapper ]; | |||
installPhase = '' | |||
mkdir -p $out/bin | |||
cp github-downloader.sh $out/bin/github-downloader.sh | |||
wrapProgram $out/bin/github-downloader.sh \ | |||
--prefix PATH : ${lib.makeBinPath [ bash subversion ]} | |||
''; | |||
}; | |||
</syntaxHighlight> | |||
when the dependency <code>subversion</code> is missing, the script throws the error <code>svn: command not found</code> | |||
<code>wrapProgram</code> will move the original script to <code>.github-downloader.sh-wrapped</code> | |||
== Posix Shell == | == Posix Shell == | ||
Line 22: | Line 60: | ||
on nixos, posix shells are provided by the packages <code>dash</code> and <code>posh</code> | on nixos, posix shells are provided by the packages <code>dash</code> and <code>posh</code> | ||
== See also == | |||
* [https://nixos.org/manual/nixpkgs/stable/#ssec-stdenv-functions Shell functions section in the Nixpkgs manual] |