bin/hey: fix logic oopsies

+ Fix premature termination on shell command failure
+ Fix :gc always cleaning up user profile, even if --system is given
This commit is contained in:
Henrik Lissner 2021-02-15 19:06:05 -05:00
parent 05faec5801
commit d05afa7ee6

View file

@ -60,11 +60,12 @@ module Hey
raise ArgumentError unless args.kind_of?(Array) raise ArgumentError unless args.kind_of?(Array)
args.unshift('sudo') if sudo args.unshift('sudo') if sudo
if @@opts[:dryrun] if @@opts[:dryrun]
print args.compact print "#{args.compact}\n"
return true return true
else else
result = system "#{args.compact.shelljoin} 2>&1" result = system "#{args.compact.shelljoin} 2>&1"
noerror ? result : exit($?.exitstatus) exit($?.exitstatus) unless noerror or result
return result
end end
end end
def self.rebuild(*args, sudo: false, host: nil) def self.rebuild(*args, sudo: false, host: nil)
@ -217,12 +218,12 @@ module Hey
opts "-a", "--all", "GC both the user and system profiles" opts "-a", "--all", "GC both the user and system profiles"
opts "-s", "--system", "Only GC the system profile" opts "-s", "--system", "Only GC the system profile"
lambda do |_args| lambda do |_args|
if @@opts[:all] or not @@opts[:root] if @@opts[:all] or not @@opts[:system]
puts "Cleaning up your user profile..." puts "Cleaning up your user profile..."
sh %w{nix-collect-garbage -d} sh %w{nix-collect-garbage -d}
end end
if @@opts[:all] or @@opts[:system] if @@opts[:all] or @@opts[:system]
puts "Cleaning up your system..." puts "Cleaning up your system profile..."
sh %w{nix-collect-garbage -d}, sudo: true sh %w{nix-collect-garbage -d}, sudo: true
sh %w{nix-store --optimise}, sudo: true sh %w{nix-store --optimise}, sudo: true
# Clear out left-over secrets. The switch-to-configuration call below will # Clear out left-over secrets. The switch-to-configuration call below will