{ inputs, ... }: { flake.overlays.rolling_datasets = final: prev: let writeTextFile = { name # the name of the derivation , text , executable ? false # run chmod +x ? , destination ? "" # relative path appended to $out eg "/bin/foo" , checkPhase ? "" # syntax checks, e.g. for scripts , env ? {} }: final.runCommand name ({ inherit text executable; passAsFile = [ "text" ]; # Pointless to do this on a remote machine. preferLocalBuild = true; allowSubstitutes = false; } // env) '' n=$out${destination} mkdir -p "$(dirname "$n")" if [ -e "$textPath" ]; then mv "$textPath" "$n" else echo -n "$text" > "$n" fi ${checkPhase} (test -n "$executable" && chmod +x "$n") || true ''; writeShellScriptBin = name : text : env : writeTextFile { inherit name; executable = true; destination = "/bin/${name}"; text = '' #!${final.runtimeShell} ${text} ''; checkPhase = '' ${final.stdenv.shell} -n $out/bin/${name} ''; }; in { rolling_datasets = final.runCommand "rolling_datasets" { } '' mkdir -p $out/bin mkdir -p $out/share/functions for binary in ${./bin}/* ; do substituteAll "$binary" "$out/bin/$(basename "$binary")" done for function in ${./functions}/* ; do substituteAll "$function" "$out/share/functions/$(basename "$function")" done ''; }; }