mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-11-25 09:36:14 +01:00
72 lines
2 KiB
Nix
72 lines
2 KiB
Nix
{ 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
|
|
export runtimeShell=${prev.runtimeShell} \
|
|
runtimePath=${prev.lib.makeBinPath (with prev; [ utillinux zfs ])}
|
|
|
|
for binary in ${./bin}/* ; do
|
|
output_binary="$out/bin/$(basename "$binary")"
|
|
substituteAll "$binary" "$output_binary"
|
|
chmod +x "$output_binary"
|
|
done
|
|
|
|
for function in ${./functions}/* ; do
|
|
substituteAll "$function" "$out/share/functions/$(basename "$function")"
|
|
done
|
|
'';
|
|
};
|
|
}
|
|
|