mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-11-22 08:04:20 +01:00
Fully fixup rolling datasets
Signed-off-by: magic_rb <magic_rb@redalder.org>
This commit is contained in:
parent
729e68b80e
commit
99005cd768
|
@ -4,7 +4,7 @@ source @out@/share/functions/get_old_datasets
|
|||
|
||||
export "PATH=$PATH:@runtimePath@"
|
||||
|
||||
if [[ "$#" != 3 ]] ; then
|
||||
if [[ "$#" != 2 ]] ; then
|
||||
echo "This script requires precisely 2 arguments!"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -21,7 +21,7 @@ zfs rollback "$dataset@blank" && echo "rollback complete"
|
|||
|
||||
while IFS="\n" read gen
|
||||
do
|
||||
printf "$gen < $(("$generation" - "$to_keep")) => "
|
||||
printf -- "$gen < $(("$generation" - "$to_keep")) => "
|
||||
if [ "$gen" -lt "$(("$generation" - "$to_keep"))" ]; then
|
||||
zfs destroy -r "$dataset/$gen"
|
||||
echo "destroyed"
|
||||
|
|
|
@ -1,48 +1,25 @@
|
|||
{ inputs, ... }:
|
||||
{ inputs, lib, ... }:
|
||||
let
|
||||
inherit (lib)
|
||||
filterAttrs
|
||||
mapAttrsToList
|
||||
concatStringsSep
|
||||
;
|
||||
in
|
||||
{
|
||||
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 {
|
||||
writeShellScript = name: text:
|
||||
prev.writeTextFile {
|
||||
inherit name;
|
||||
executable = true;
|
||||
destination = "/bin/${name}";
|
||||
text = ''
|
||||
#!${final.runtimeShell}
|
||||
#!/bin/sh
|
||||
${text}
|
||||
'';
|
||||
checkPhase = ''
|
||||
${final.stdenv.shell} -n $out/bin/${name}
|
||||
${prev.stdenv.shellDryRun} "$target"
|
||||
'';
|
||||
};
|
||||
in
|
||||
|
@ -56,11 +33,14 @@
|
|||
export runtimeShell=${prev.runtimeShell} \
|
||||
runtimePath=${prev.lib.makeBinPath (with prev; [ utillinux zfs ])}
|
||||
|
||||
for binary in ${./bin}/* ; do
|
||||
output_binary="$out/bin/$(basename "$binary")"
|
||||
${concatStringsSep "\n" (mapAttrsToList (name: _: ''
|
||||
{
|
||||
binary=${writeShellScript name (builtins.readFile (./. + "/bin/${name}"))}
|
||||
output_binary="$out/bin/${name}"
|
||||
substituteAll "$binary" "$output_binary"
|
||||
chmod +x "$output_binary"
|
||||
done
|
||||
}
|
||||
'') (filterAttrs (_: v: v == "regular") (builtins.readDir ./bin)))}
|
||||
|
||||
for function in ${./functions}/* ; do
|
||||
substituteAll "$function" "$out/share/functions/$(basename "$function")"
|
||||
|
|
Loading…
Reference in a new issue