NixOS / nix.dev

Official documentation for getting things done with Nix.
https://nix.dev
Creative Commons Attribution Share Alike 4.0 International
2.47k stars 249 forks source link

A collection "How do I ..." cookbook style recipes #173

Open zupo opened 3 years ago

zupo commented 3 years ago

For the task I am currently working on I really need to install https://github.com/aurora/rmate on my NixOS server. It's a simple bash script so I can just wget and chmod +x it, but that feels icky. I want to have it in my configuration.nix so I can use it in the future too.

After considerable Googling I didn't find a tutorial on how to "package a bash script from the Internet". Here it is, this is what you dump into configuration.nix:

{ config, pkgs, ... }:

let
  rmate_src = pkgs.fetchurl {
      url = "https://raw.githubusercontent.com/aurora/rmate/master/rmate";
      sha256 = "152z31xhdq9w0mn9ibv9jsnc2k1p36yr23waa6376d8m05hpmaln";
      executable = true;
    };
  rmate = pkgs.writeShellScriptBin "rmate" ''${rmate_src} "$@"''; 

in
{
...
environment.systemPackages = [ rmate ];
}

It would be nice if nix.dev had a section where we could collect quick recipes like this one.

ghost commented 2 years ago

I also have this need when working with nix. This sounds like a more in depth example of https://github.com/nix-dot-dev/nix.dev/issues/146.