Nix Cookbook: Difference between revisions

imported>Dustinlacewell
Added "Creating Shell Scripts" cookbook
imported>Dustinlacewell
m Fix some formatting for "Creating Shell Scripts"
Line 5: Line 5:
Arbitrary system shell scripts can be created with [https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/trivial-builders.nix#L58 pkgs.writeScriptBin]. It creates a derivation which you add to [https://nixos.org/nixos/manual/#sec-declarative-package-mgmt environment.systemPackages].
Arbitrary system shell scripts can be created with [https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/trivial-builders.nix#L58 pkgs.writeScriptBin]. It creates a derivation which you add to [https://nixos.org/nixos/manual/#sec-declarative-package-mgmt environment.systemPackages].
<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
{ config, pkgs, lib, ... }:
{ pkgs, ... }:
 
with lib;


let
let
   helloWorld = pkgs.writeScriptBin "helloWorld" ''
   helloWorld = pkgs.writeScriptBin "helloWorld" ''
#!${pkgs.stdenv.shell}
    #!${pkgs.stdenv.shell}
echo Hello World'';
    echo Hello World
  '';


in {
in {
   config.environment.systemPackages = [ helloWorld ];
   environment.systemPackages = [ helloWorld ];
}
}
</syntaxHighlight>
</syntaxHighlight>