{ inputs, pkgs, ... }: inputs.nixpkgs.lib.extend ( final: prev: let lib = prev; in { ensureZfsMounts = dirs: pkgs.writeShellApplication { name = "zfslistmounted"; runtimeInputs = with pkgs; [ zfs gnugrep gawk coreutils ]; text = '' #!/bin/sh zfs list -o mountpoint,mounted -H | awk '$2 == "yes" {print $1}' | grep -c '${lib.strings.concatStringsSep "\|" dirs}' | grep -Fq ${toString (lib.length dirs)} ''; }; serviceMountDeps = serviceName: dirs: { systemd.services."${serviceName}_mounts" = { unitConfig.Wants = "zfs.target"; serviceConfig = { Type = "oneshot"; RemainAfterExit = true; ExecStart = lib.getExe (final.ensureZfsMounts dirs); }; }; systemd.services.${serviceName} = { wants = [ "${serviceName}_mounts.service" ]; }; }; # stolen from: https://stackoverflow.com/a/42398526 optimizeWithFlags = pkg: flags: lib.overrideDerivation pkg ( old: let newflags = lib.foldl' (acc: x: "${acc} ${x}") "" flags; oldflags = if (lib.hasAttr "NIX_CFLAGS_COMPILE" old) then "${old.NIX_CFLAGS_COMPILE}" else ""; in { NIX_CFLAGS_COMPILE = "${oldflags} ${newflags}"; # stdenv = pkgs.clang19Stdenv; } ); optimizePackage = pkg: final.optimizeWithFlags pkg [ "-O3" "-march=znver3" "-mtune=znver3" ]; } )