Skip to content

Instantly share code, notes, and snippets.

@kayvank
Created December 28, 2024 19:22
Show Gist options
  • Select an option

  • Save kayvank/e8a7e8aab2c883fbf6bd31fda52b25c5 to your computer and use it in GitHub Desktop.

Select an option

Save kayvank/e8a7e8aab2c883fbf6bd31fda52b25c5 to your computer and use it in GitHub Desktop.
nix flake to create a simple shell script
{
description = "A better simple script flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {self, nixpkgs, flake-utils}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {system = system;};
my-name = "my-script";
my-src = builtins.readFile ./simple-script.sh;
my-script = (pkgs.writeScriptBin my-name my-src).overrideAttrs(old: {
buildCommand = "${old.buildCommand}\n patchShebangs $out";
});
## create a variable to store the list of dependencies
my-buildInputs = with pkgs; [cowsay ddate];
in rec {
defaultPackage = packages.my-script;
packages.my-script = pkgs.symlinkJoin {
name = my-name;
paths = [ my-script ] ++ my-buildInputs;
buildInputs = [ pkgs.makeWrapper ];
postBuild =
"wrapProgram $out/bin/${my-name} --prefix PATH : $out/bin";
};
});
}
@kayvank
Copy link
Author

kayvank commented Dec 28, 2024

Where the simple-script.sh shell script is:

#!/usr/bin/env sh

DATE="$(ddate +'the %e of %B%, %Y%')"
cowsay "Hello, world! Today is $DATE"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment