dotfiles/overlays/rolling_datasets/default.nix
magic_rb 99005cd768
Fully fixup rolling datasets
Signed-off-by: magic_rb <magic_rb@redalder.org>
2023-11-03 20:10:48 +01:00

52 lines
1.4 KiB
Nix

{ inputs, lib, ... }:
let
inherit (lib)
filterAttrs
mapAttrsToList
concatStringsSep
;
in
{
flake.overlays.rolling_datasets =
final: prev:
let
writeShellScript = name: text:
prev.writeTextFile {
inherit name;
executable = true;
text = ''
#!/bin/sh
${text}
'';
checkPhase = ''
${prev.stdenv.shellDryRun} "$target"
'';
};
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 ])}
${concatStringsSep "\n" (mapAttrsToList (name: _: ''
{
binary=${writeShellScript name (builtins.readFile (./. + "/bin/${name}"))}
output_binary="$out/bin/${name}"
substituteAll "$binary" "$output_binary"
chmod +x "$output_binary"
}
'') (filterAttrs (_: v: v == "regular") (builtins.readDir ./bin)))}
for function in ${./functions}/* ; do
substituteAll "$function" "$out/share/functions/$(basename "$function")"
done
'';
};
}