Skip to content

Commit

Permalink
packages/nix-cleanup: rewrite it to avoid IFD
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Oct 11, 2023
1 parent 019cc3f commit ccc213e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
48 changes: 35 additions & 13 deletions packages/nix-cleanup/default.nix
Original file line number Diff line number Diff line change
@@ -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
'';
}
3 changes: 3 additions & 0 deletions packages/nix-cleanup/nix-cleanup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash

set -euo pipefail

readonly NIXOS=@isNixOS@
PATH=@path@
AUTO=0
OPTIMIZE=0
HM_PROFILE=0
Expand Down

0 comments on commit ccc213e

Please sign in to comment.