Skip to content

Instantly share code, notes, and snippets.

@abathur
Last active March 4, 2021 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abathur/35a61d21fde13a1f389783d069114061 to your computer and use it in GitHub Desktop.
Save abathur/35a61d21fde13a1f389783d069114061 to your computer and use it in GitHub Desktop.
resholve smartmon.sh
{ callPackage, lib, fetchFromGitHub }:
let
version = "0.5.1";
src = fetchFromGitHub {
owner = "abathur";
repo = "resholve";
rev = "v${version}";
hash = "sha256-+9MjvO1H+A3Ol2to5tWqdpNR7osQsYcbkX9avAqyrKw=";
};
in callPackage src {}

eyJhb: Why do people see the need to hardcode paths to bins? https://github.com/prometheus-community/node-exporter-textfile-collector-scripts/blob/master/smartmon.sh#L186

This is one of the reasons resholve treats existing absolute executable paths as an error unless you intentionally exempt them:

$ resholve --interpreter none --path $PATH smartmon.sh
  smartctl_version="$(/usr/sbin/smartctl -V | head -n1 | awk '$1 == "smartctl" {print $2}')"
                      ^~~~~~~~~~~~~~~~~~
/Users/abathur/work/resholved/smartmon.sh:165: Unexpected absolute command path (not supplied by a listed dependency). You should patch/substitute it.

You can also tell resholve to resolve such a path from inputs:

$ resholve --interpreter none --path $PATH --fix /usr/sbin/smartctl smartmon.sh
  smartctl_version="$(/usr/sbin/smartctl -V | head -n1 | awk '$1 == "smartctl" {print $2}')"
                      ^~~~~~~~~~~~~~~~~~
/Users/abathur/work/resholved/smartmon.sh:165: Can't resolve command 'smartctl' to a known function or executable

(this would work if I had smartmontools in my inputs/path)

smartmon = pkgs.resholvePackage {
name = "smartmon.sh";
src = pkgs.fetchFromGitHub{
owner = "prometheus-community";
repo = "node-exporter-textfile-collector-scripts";
rev = "414fb44693444cb96a55c7152cdd84d531888e1f";
sha256 = "13ja3l78bb47xhdfsmsim5sqggb9avg3x872jqah1m7jm9my7m98";
};
installPhase = ''
install -D -m 0755 smartmon.sh $out/bin/smartmon.sh
'';
solutions.smartmon = {
scripts = [ "bin/smartmon.sh" ];
interpreter = "${pkgs.bash}/bin/bash";
inputs = with pkgs; [ smartmontools coreutils findutils gawk gnugrep gnused ];
fix = {
"/usr/bin/smartctl" = true;
};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment