From ccc213e0e5f1e18bb3443e65c282723d7aadc2a4 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 11 Oct 2023 11:56:03 +0100 Subject: [PATCH] packages/nix-cleanup: rewrite it to avoid IFD --- packages/nix-cleanup/default.nix | 48 +++++++++++++++++++++-------- packages/nix-cleanup/nix-cleanup.sh | 3 ++ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/packages/nix-cleanup/default.nix b/packages/nix-cleanup/default.nix index 0fef542c..750901b2 100644 --- a/packages/nix-cleanup/default.nix +++ b/packages/nix-cleanup/default.nix @@ -1,30 +1,52 @@ -{ writeShellApplication -, lib +{ lib +, stdenvNoCC , coreutils , gawk +, findutils , gnugrep , home-manager , nix +, shellcheck , substituteAll , isNixOS ? false }: -writeShellApplication { +stdenvNoCC.mkDerivation { name = if isNixOS then "nixos-cleanup" else "nix-cleanup"; - text = lib.readFile (substituteAll { + src = substituteAll { src = ./nix-cleanup.sh; isNixOS = if isNixOS then "1" else "0"; - }); - - runtimeInputs = [ - coreutils - gawk - gnugrep - home-manager - nix - ]; + path = lib.makeBinPath [ + coreutils + findutils + gawk + gnugrep + home-manager + nix + ]; + }; + + dontUnpack = true; + + installPhase = '' + runHook preInstall + + install -Dm0755 $src $out/bin/nix-cleanup + + runHook postInstall + ''; + + doCheck = true; + + checkPhase = '' + runHook preCheck + + ${lib.getExe shellcheck} $src + + runHook postCheck + ''; } diff --git a/packages/nix-cleanup/nix-cleanup.sh b/packages/nix-cleanup/nix-cleanup.sh index cbf5310f..166662f9 100644 --- a/packages/nix-cleanup/nix-cleanup.sh +++ b/packages/nix-cleanup/nix-cleanup.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash +set -euo pipefail + readonly NIXOS=@isNixOS@ +PATH=@path@ AUTO=0 OPTIMIZE=0 HM_PROFILE=0