Finally tutorial with minimal flake example

Hi,

I have finally found tutorial with minimal flake example Shell Scripts with Nix — ertt.ca Shell Scripts with Nix — ertt.ca

I was overwhelmed by most other tutorials which use many additional functions from flake-utils and the like. But this is one is bare bone.

Do you know of other such tutorials?

./simple-script/flake.nix:

{
  description = "A simple script";

  outputs = { self, nixpkgs }: {
    defaultPackage.x86_64-linux = self.packages.x86_64-linux.my-script;

    packages.x86_64-linux.my-script =
      let
        pkgs = import nixpkgs { system = "x86_64-linux"; };
      in
      pkgs.writeShellScriptBin "my-script" ''
        DATE="$(${pkgs.ddate}/bin/ddate +'the %e of %B%, %Y')"
        ${pkgs.cowsay}/bin/cowsay Hello, world! Today is $DATE.
      '';
  };
}
# Let's get our bearings first:
$ pwd
~/code
$ ls ./simple-script/
flake.nix

# Execute the "default package" of ./simple-script/flake.nix
$ nix run ./simple-script#
# or...
$ cd ./simple-script && nix run .#

# Execute a named package of ./simple-script/flake.nix
$ nix run ./simple-script#my-script
# or...
$ cd ./simple-script && nix run .#my-script
5 Likes
Hosted by Flying Circus.