chore: remove unused overlays

This commit is contained in:
arcnmx 2024-02-02 13:15:31 -08:00
parent 7da0924d91
commit 76893ae125
37 changed files with 47 additions and 1530 deletions

View file

@ -3,9 +3,6 @@
inherit system;
overlays =
[
(import ./nur {inherit inputs;})
(import ./local)
(import ./lib)
inputs.deploy-rs.overlay
inputs.arcexprs.overlays.default
(final: prev: {

View file

@ -1,7 +0,0 @@
self: super: {
lib = super.lib.extend (self: super: import ./overlay.nix {
inherit super;
lib = self;
isOverlayLib = true;
});
}

View file

@ -1,21 +0,0 @@
{ lib }: { nixosImports, homeImports, users, hostName, profiles }: with lib;
let
importLists = {
nixos = nixosImports;
home = homeImports;
};
replacedLists = mapAttrs
(_: fileList:
map (builtins.replaceStrings [ "HN" ] [ "${hostName}" ]) fileList
)
importLists;
homeScaffold = user: {
home-manager.users.${user} = {
imports = filter builtins.pathExists replacedLists.home;
};
};
scaffoldedUsers = map homeScaffold users;
baseProfile = singleton profiles.base;
in
filter builtins.pathExists replacedLists.nixos ++ baseProfile ++ scaffoldedUsers

View file

@ -1,16 +0,0 @@
{ pkgs ? import <nixpkgs> { }
, lib ? pkgs.lib
# for internal use...
, super ? if !isOverlayLib then lib else { }
, self ? if isOverlayLib then lib else { }
, before ? if !isOverlayLib then lib else { }
, isOverlayLib ? false
}@args:
let
lib = before // katlib // self;
katlib = with before; with katlib; with self;
{
nodeImport = import ./node-import.nix { inherit lib; };
};
in
katlib

View file

@ -1,35 +0,0 @@
final: prev: {
lib = prev.lib.extend (import ./lib.nix);
requests-oauth = final.python3Packages.callPackage ./requests-oauth.nix {};
withings-api = final.python3Packages.callPackage ./withings-api.nix {};
irlsite = final.callPackage ./irlsite.nix {};
vips = prev.vips.override {libjxl = null;};
sway-scrot = final.callPackage ./sway-scrot {};
vfio-vm = final.callPackage ./vm.nix {};
vfio-vm-pinning = final.callPackage ./vm-pinning.nix {};
vfio-disk-mapper = final.callPackage ./disk-mapper.nix {};
xbackbone = final.callPackage ./xbackbone.nix {};
waybar-gpg = final.callPackage ./waybar-gpg {};
waybar-konawall = final.callPackage ./waybar-konawall {};
hedgedoc-cli = final.callPackage ./hedgedoc-cli.nix {};
gensokyoZone = final.callPackage ./gensokyoZone {};
kittywitCh = final.callPackage ./gensokyoZone/kittywitch.nix {};
oomox = final.callPackage ./oomox.nix {};
wezterm = final.callPackage ./wezterm {
inherit (final.darwin.apple_sdk.frameworks) Cocoa CoreGraphics Foundation UserNotifications;
};
mkSnakeOil = final.callPackage ./snakeoil.nix { };
terraform-providers =
prev.terraform-providers
// {
tailscale = final.terraform-providers.mkProvider rec {
owner = "tailscale";
provider-source-address = "registry.terraform.io/${owner}/${owner}";
repo = "terraform-provider-tailscale";
rev = "v${version}";
hash = "sha256-/qC8TOtoVoBTWeAFpt2TYE8tlYBCCcn/mzVQ/DN51YQ=";
vendorHash = "sha256-8EIxqKkVO706oejlvN79K8aEZAF5H2vZRdr5vbQa0l4=";
version = "0.13.5";
};
};
}

View file

@ -1,46 +0,0 @@
{ pkgs, writeShellScriptBin }:
writeShellScriptBin "disk-mapper-part" ''
set -x
DISK=$1
DM_NAME=$(basename $DISK)
if [[ ! -e /dev/mapper/$DM_NAME ]]; then
DISK_ID=''${2-$(printf %s "$DM_NAME" | sha256sum)}
DISK_TYPE=7 # NTFS
MBR_FILE=$(mktemp -t vm-$DM_NAME-XXXXXXXX.mbr)
BLOCK=$(basename $(readlink $DISK))
BLOCK_START=$(cat /sys/class/block/$BLOCK/start)
BLOCK_SIZE=$(cat /sys/class/block/$BLOCK/size)
DISK_SIZE=$(((BLOCK_SIZE + 2048 + 2047) / 2048 * 2048))
dd if=/dev/zero of=$MBR_FILE bs=512 count=2048 status=none
LDEV=$(losetup --show -f $MBR_FILE)
END_GUARD=$((DISK_SIZE - 2048 - BLOCK_SIZE))
if [[ $END_GUARD -ne 0 ]]; then
END_GUARD="$((BLOCK_SIZE + 2048)) $END_GUARD zero"
else
END_GUARD=
fi
dmsetup create $DM_NAME <<EOF
0 2048 linear $LDEV 0
2048 $BLOCK_SIZE linear $DISK 0
$END_GUARD
EOF
CYL=$((DISK_SIZE / 2048))
if [[ $CYL -gt 65535 ]]; then
CYL=65535
fi
dmsetup setgeometry $DM_NAME $CYL 64 32 0
chown "$USER" /dev/mapper/$DM_NAME
sfdisk --quiet --no-tell-kernel --no-reread /dev/mapper/$DM_NAME <<EOF
label: dos
label-id: 0x''${DISK_ID:8}
device: $DM_NAME
unit: sectors
grain: 512
sector-size: 512
1 : start=2048, size=$BLOCK_SIZE, type=$DISK_TYPE
EOF
fi
''

View file

@ -1,27 +0,0 @@
{ lib, stdenv, makeWrapper, fetchFromGitHub, jq, curl, wget }:
stdenv.mkDerivation {
pname = "hedgedoc-cli";
version = "2021-05-17";
src = fetchFromGitHub {
owner = "hedgedoc";
repo = "cli";
rev = "8b13b8836cf330921856907d905421d34a1e645c";
sha256 = "1971v02jxlnxi09h0c6w3nzgq8w7b6ry09hjnvggypgxfjh53lhk";
};
paths = lib.makeBinPath [
jq curl wget
];
nativeBuildInputs = [
makeWrapper
];
installPhase = ''
install -Dm0755 bin/hedgedoc $out/bin/hdcli
wrapProgram $out/bin/hdcli \
--prefix PATH : "$paths"
'';
}

View file

@ -1,15 +0,0 @@
{ stdenv, fetchFromGitHub, lib }: stdenv.mkDerivation rec {
name = "irlsite";
src = fetchFromGitHub {
owner = "kittywitch";
repo = "inskip.me";
rev = "a430a42d70ca9ddb554e8e0c0ed78a33b3ccb9e5";
sha256 = "sha256-SUhXD0/PdWkvMUGOVTm9PPw8fi+Q+7Psw61VhMKRf2I=";
};
buildPhase = ''
'';
installPhase = ''
mkdir $out
cp -r ./* $out
'';
}

View file

@ -1,27 +0,0 @@
lib: prev: let
inherit (lib.strings) splitString toLower;
inherit (lib.lists) imap0 elemAt;
inherit (lib.attrsets) listToAttrs nameValuePair;
inherit (lib.strings) substring fixedWidthString;
inherit (lib.trivial) flip toHexString toHexStringLower hexCharToInt bitOr;
in {
trivial = prev.trivial // {
toHexStringLower = v: toLower (toHexString v);
hexCharToInt = let
hexChars = [ "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f" ];
pairs = imap0 (flip nameValuePair) hexChars;
idx = listToAttrs pairs;
in char: idx.${char};
eui64 = mac: let
parts = map toLower (splitString ":" mac);
part = elemAt parts;
part0 = part: let
nibble1' = hexCharToInt (substring 1 1 part);
nibble1 = bitOr 2 nibble1';
nibble0 = substring 0 1 part;
in nibble0 + (fixedWidthString 1 "0" (toHexStringLower nibble1));
in "${part0 (part 0)}${part 1}:${part 2}ff:fe${part 3}:${part 4}${part 5}";
};
}

View file

@ -1,64 +0,0 @@
{ gnome
, stdenv
, gdk-pixbuf
, glib
, libxml2
, bc
, librsvg
, sassc
, inkscape
, optipng
, python3
, gtk3
, gobject-introspection
, gtk-engine-murrine
, fetchFromGitHub
, wrapGAppsHook
, makeWrapper
, runtimeShell
}:
python3.pkgs.buildPythonApplication rec {
format = "other";
name = "oomox";
src = fetchFromGitHub {
owner = "themix-project";
repo = "oomox";
rev = "1.14";
sha256 = "0zk2q0z0n64kl6my60vkq11gp4mc442jxqcwbi4kl108242izpjv";
fetchSubmodules = true;
};
dontWrapGApps = true;
dontPatchELF = true;
dontFixup = true;
doCheck = false;
strictDeps = false;
buildPhase = ''
true
'';
nativeBuildInputs = [ makeWrapper wrapGAppsHook libxml2 gobject-introspection glib bc ];
propagatedBuildInputs = with python3.pkgs; [
gnome.gnome-themes-extra gdk-pixbuf librsvg sassc inkscape optipng
gobject-introspection
pygobject3
python3
gtk-engine-murrine
pystache
pyyaml
gtk3
bc
];
propagatedUserEnvPkgs = [ gtk-engine-murrine ];
installPhase = ''
mkdir $out
gappsWrapperArgsHook
make install DESTDIR=/ PREFIX=$out APPDIR=$out/lib/share/oomox
for prog in $out/bin/*; do
sed -i "s/cd /true /" $prog
wrapProgram $prog "''${gappsWrapperArgs[@]}" --prefix PATH : "${bc}/bin:${python3}/bin" --prefix PYTHONPATH : "$out/lib/share/oomox:$PYTHONPATH"
done
#for script in $(find $out -name "change_color.sh"); do
# cp ${./script.sh} $script
#done
'';
}

View file

@ -1,60 +0,0 @@
{ stdenv, glibc, fetchFromGitHub, cmake, writeTextFile
,
}:
let
version = "79";
pname = "pigpio";
pkgConfig = writeTextFile {
name = "${pname}.pc";
text = ''
prefix=@out@
exec_prefix=''${prefix}
includedir=''${prefix}/include
libdir=''${prefix}/lib
Name: pigpio
Description: GPIO library for Raspberry Pi computers
Version: ${version}
Libs: -L''${libdir} -lpigpio -lpthread -lm
Cflags: -I''${includedir}
'';
};
in
stdenv.mkDerivation rec {
inherit pname version;
src = fetchFromGitHub {
owner = "joan2937";
repo = pname;
rev = "v${version}";
sha256 = "0wgcy9jvd659s66khrrp5qlhhy27464d1pildrknpdava19b1r37";
};
patches = [
./Pi4Revision.patch
];
nativeBuildInputs = [
cmake
];
buildInputs = [
glibc
];
meta = with stdenv.lib; {
description = "GPIO library for the Raspberry Pi";
homepage = "http://abyz.me.uk/rpi/pigpio/index.html";
license = licenses.unlicense;
platforms = platforms.unix;
};
installPhase = ''
make install
mkdir -p $out/lib/pkgconfig
substitute ${pkgConfig} $out/lib/pkgconfig/pigpio.pc --subst-var out
'';
}

View file

@ -1,32 +0,0 @@
{ lib
, buildPythonPackage
, pythonOlder
, fetchPypi
, requests
}:
buildPythonPackage rec {
pname = "requests-oauth";
version = "0.4.1";
format = "setuptools";
disabled = pythonOlder "3.6";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-nBsHOJZ+8cD28Osf8JpwAEmc0HpgnqjxdwtRW5U69pI=";
};
propagatedBuildInputs = [
requests
];
doCheck = false; # disabled due to Python 2 tests (?) - missing parenthesis
meta = {
description = " Python's Requests OAuth (Open Authentication) plugin";
homepage = "https://github.com/maraujop/requests-oauth";
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [ kittywitch ];
};
}

View file

@ -1,30 +0,0 @@
{
runCommand,
buildPackages,
lib,
}: let
inherit (lib.strings) concatStringsSep;
inherit (lib.lists) toList head;
in { domain, name }: runCommand name {
domains = concatStringsSep "," (toList domain);
domain = head (toList domain);
nativeBuildInputs = [ buildPackages.minica ];
outputs = [ "out" "key" "cakey" "ca" "cert" "fullchain" ];
} ''
install -d $out
minica \
--ca-key ca.key.pem \
--ca-cert ca.pem \
--domains "$domains"
mv ca.pem $ca
mv ca.key.pem $cakey
mv $domain/cert.pem $cert
mv $domain/key.pem $key
cat $cert $ca > $fullchain
ln -s $fullchain $out/fullchain.pem
ln -s $key $out/key.pem
ln -s $cakey $out/ca.key.pem
ln -s $cert $out/cert.pem
ln -s $ca $out/ca.pem
''

View file

@ -1,5 +0,0 @@
{ wrapShellScriptBin, pkgs }:
wrapShellScriptBin "sway-scrot" ./sway-scrot.sh {
depsRuntimePath = with pkgs; [ coreutils wl-clipboard slurp grim sway jq libnotify xdotool maim xclip ];
}

View file

@ -1,253 +0,0 @@
#!/bin/sh
## Requirements:
## - `grim`: screenshot utility for wayland
## - `slurp`: to select an area
## - `$MSGER`: to read properties of current window
## - `$COPIER`: clipboard utility
## - `jq`: json utility to parse $MSGER output
## - `notify-send`: to show notifications
getTargetDirectory() {
echo "/home/kat/media/scrots"
}
if [ -n "$SWAYSOCK" ]; then
SWAY=yes;
MSGER=swaymsg;
COPIER="wl-copy";
COPIERIMG="wl-copy --type image/png";
else
SWAY=no;
MSGER=i3-msg;
COPIER="xclip -sel c"
COPIERIMG="xclip -sel c -t image/png"
fi
if [ "$1" = "--notify" ]; then
NOTIFY=yes
shift 1
else
NOTIFY=no
fi
ACTION=${1:-usage}
SUBJECT=${2:-screen}
FILENAME="$(date -Ins).png"
FILE=${3:-$(getTargetDirectory)/$FILENAME}
TOKEN=$(bitw get secrets/xbackbone -f token)
if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "check" ] && [ "$ACTION" != "upload" ] && [ "$ACTION" != "copys" ]; then
echo "Usage:"
echo " kat-scrot [--notify] (copy|save|upload|copys) [active|screen|output|area|window] [FILE]"
echo " kat-scrot check"
echo " kat-scrot usage"
echo ""
echo "Commands:"
echo " copy: Copy the screenshot data into the clipboard."
echo " upload: Uses SCP to transfer the screenshot to a remote server."
echo " copys: Copy the screenshot data into the clipboard and save it to a regular file."
echo " save: Save the screenshot to a regular file."
echo " check: Verify if required tools are installed and exit."
echo " usage: Show this message and exit."
echo ""
echo "Targets:"
echo " active: Currently active window."
echo " screen: All visible outputs."
echo " output: Currently active output."
echo " area: Manually select a region."
echo " window: Manually select a window."
exit
fi
notify() {
notify-send -t 3000 -a grimshot "$@"
}
notifyOk() {
[ "$NOTIFY" = "no" ] && return
TITLE=${2:-"Screenshot"}
MESSAGE=${1:-"OK"}
notify "$TITLE" "$MESSAGE"
}
notifyError() {
if [ $NOTIFY = "yes" ]; then
TITLE=${2:-"Screenshot"}
MESSAGE=${1:-"Error taking screenshot with grim"}
notify -u critical "$TITLE" "$MESSAGE"
else
echo $1
fi
}
die() {
MSG=${1:-Bye}
notifyError "Error: $MSG"
exit 2
}
check() {
COMMAND=$1
if command -v "$COMMAND" > /dev/null 2>&1; then
RESULT="OK"
else
RESULT="NOT FOUND"
fi
echo " $COMMAND: $RESULT"
}
takeScreenshot() {
FILE=$1
GEOM=$2
OUTPUT=$3
if [ "$SWAY" = "yes" ]; then
if [ ! -z "$OUTPUT" ]; then
grim -o "$OUTPUT" "$FILE" || die "Unable to invoke grim"
elif [ -z "$GEOM" ]; then
grim "$FILE" || die "Unable to invoke grim"
else
grim -g "$GEOM" "$FILE" || die "Unable to invoke grim"
fi
else
if [ "$GEOM" = "maim-cur" ]; then
maim -i $(xdotool getactivewindow) "$FILE"
elif [ "$GEOM" = "maim-s" ]; then
maim -s "$FILE"
elif [ "$GEOM" = "maim-out" ]; then
maim -g "$OUTPUT" "$FILE"
elif [ "$GEOM" = "maim-screen" ]; then
maim "$FILE"
fi
fi
}
if [ "$ACTION" = "check" ] ; then
echo "Checking if required tools are installed. If something is missing, install it to your system and make it available in PATH..."
check grim
check slurp
check $MSGER
check $COPIER
check jq
check notify-send
exit
elif [ "$SUBJECT" = "area" ] ; then
GEOM=$(slurp -d)
# Check if user exited slurp without selecting the area
if [ -z "$GEOM" ]; then
exit
fi
WHAT="Area"
elif [ "$SUBJECT" = "active" ] ; then
if [ "$SWAY" = "yes" ]; then
FOCUSED=$($MSGER -t get_tree | jq -r 'recurse(.nodes[]?, .floating_nodes[]?) | select(.focused)')
GEOM=$(echo "$FOCUSED" | jq -r '.rect | "\(.x),\(.y) \(.width)x\(.height)"')
APP_ID=$(echo "$FOCUSED" | jq -r '.app_id')
WHAT="$APP_ID window"
else
GEOM="maim-cur"
fi
elif [ "$SUBJECT" = "screen" ] ; then
if [ "$SWAY" = "yes" ]; then
GEOM=""
WHAT="Screen"
else
GEOM="maim-screen";
fi
elif [ "$SUBJECT" = "output" ] ; then
if [ "$SWAY" = "yes" ]; then
GEOM=""
OUTPUT=$($MSGER -t get_outputs | jq -r '.[] | select(.focused)' | jq -r '.name')
WHAT="$OUTPUT"
else
MONITORS=$(xrandr | grep -o '[0-9]*x[0-9]*[+-][0-9]*[+-][0-9]*')
# Get the location of the mouse
XMOUSE=$(xdotool getmouselocation | awk -F "[: ]" '{print $2}')
YMOUSE=$(xdotool getmouselocation | awk -F "[: ]" '{print $4}')
for mon in ${MONITORS}; do
# Parse the geometry of the monitor
MONW=$(echo ${mon} | awk -F "[x+]" '{print $1}')
MONH=$(echo ${mon} | awk -F "[x+]" '{print $2}')
MONX=$(echo ${mon} | awk -F "[x+]" '{print $3}')
MONY=$(echo ${mon} | awk -F "[x+]" '{print $4}')
# Use a simple collision check
if (( ${XMOUSE} >= ${MONX} )); then
if (( ${XMOUSE} <= ${MONX}+${MONW} )); then
if (( ${YMOUSE} >= ${MONY} )); then
if (( ${YMOUSE} <= ${MONY}+${MONH} )); then
# We have found our monitor!
GEOM="maim-out"
OUTPUT="${MONW}x${MONH}+${MONX}+${MONY}"
break
fi
fi
fi
fi
done
fi
elif [ "$SUBJECT" = "window" ] ; then
if [ "$SWAY" = "yes" ]; then
GEOM=$($MSGER -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp)
else
GEOM="maim-s"
fi
# Check if user exited slurp without selecting the area
if [ -z "$GEOM" ]; then
exit
fi
WHAT="Window"
else
die "Unknown subject to take a screen shot from" "$SUBJECT"
fi
if [ "$ACTION" = "copy" ] ; then
takeScreenshot - "$GEOM" "$OUTPUT" | $COPIERIMG || die "Clipboard error"
echo $FILE
notifyOk "$WHAT copied to buffer"
elif [ "$ACTION" = "copys" ]; then
if takeScreenshot "$FILE" "$GEOM" "$OUTPUT"; then
TITLE="Screenshot of $SUBJECT"
MESSAGE=$(basename "$FILE")
notifyOk "$MESSAGE" "$TITLE"
echo $FILE
cat "$FILE" | $COPIER || die "Clipboard error"
else
notifyError "Error taking screenshot with grim"
fi
elif [ "$ACTION" = "upload" ]; then
if takeScreenshot "$FILE" "$GEOM" "$OUTPUT"; then
RESPONSE="$(curl -s -F "token=$TOKEN" -F "upload=@\"$FILE\"" https://files.kittywit.ch/upload)";
if [[ "$(echo "${RESPONSE}" | jq -r '.message')" == "OK" ]]; then
URL="$(echo "${RESPONSE}" | jq -r '.url')/raw";
echo "${URL}" | $COPIER;
echo "${URL}";
notify-send "Upload completed!" "${URL}";
exit 0;
else
MESSAGE="$(echo "${RESPONSE}" | jq -r '.message')";
if [ $? -ne 0 ]; then
echo "Unexpected response:";
echo "${RESPONSE}";
exit 1;
fi
if [ "${DESKTOP_SESSION}" != "" ]; then
notify-send "Error!" "${MESSAGE}";
else
echo "Error! ${MESSAGE}";
fi
exit 1;
fi
else
notifyError "Error taking screenshot with grim"
fi
else
if takeScreenshot "$FILE" "$GEOM" "$OUTPUT"; then
TITLE="Screenshot of $SUBJECT"
MESSAGE=$(basename "$FILE")
notifyOk "$MESSAGE" "$TITLE"
echo $FILE
else
notifyError "Error taking screenshot with grim"
fi
fi

View file

@ -1,88 +0,0 @@
{ pkgs, writeShellScriptBin }:
writeShellScriptBin "win10-vm-pinning" ''
set -eu
CPUSET=/sys/fs/cgroup/cpuset
#CPUSET=/dev/cpuset
cpuset_move() {
local FROM=$1
local TO=$2
for proc in $(cat $CPUSET/$FROM/tasks); do
echo $proc > $CPUSET/$TO/tasks || true
done 2> /dev/null
}
echo 1 > $CPUSET/cpuset.sched_load_balance
if [[ ! -d $CPUSET/qemu ]]; then
mkdir $CPUSET/qemu
echo 0 > $CPUSET/qemu/cpuset.sched_load_balance
fi
if [[ ! -d $CPUSET/system ]]; then
mkdir $CPUSET/system
echo 1 > $CPUSET/system/cpuset.sched_load_balance
fi
cpuset_move qemu .
cpuset_move system .
echo "" > $CPUSET/qemu/cpuset.cpus
if [[ $# -lt 1 ]]; then
exit 0
fi
QEMU_PID=$1
shift
echo "0-1,6-7" > $CPUSET/system/cpuset.cpus
cat < $CPUSET/cpuset.mems > $CPUSET/system/cpuset.mems
cat < $CPUSET/cpuset.mems > $CPUSET/qemu/cpuset.mems
echo "2-5,8-11" > $CPUSET/qemu/cpuset.cpus
#echo "1-3,5-7" > $CPUSET/qemu/cpuset.cpus
#echo "0,1,2" > $CPUSET/qemu/cpuset.cpus
cpuset_move . system
echo 1 > $CPUSET/qemu/cpuset.cpu_exclusive
chrt -f -p 1 $QEMU_PID
for task in /proc/$QEMU_PID/task/*; do
TASKNAME=$(grep -F "Name:" $task/status | cut -d $'\t' -f2)
TASK=$(basename $task)
case $TASKNAME in
worker | qemu-system-*)
echo worker is $TASKNAME
;;
IO*)
regex="IO iothread([0-9]*)"
if [[ $TASKNAME =~ $regex ]]; then
chrt -f -p 1 $TASK
fi
;;
CPU*)
regex="CPU ([0-9]*)/KVM"
if [[ $TASKNAME =~ $regex ]]; then
CPU_ID=''${BASH_REMATCH[1]}
echo $TASK > $CPUSET/qemu/tasks
CPU_PIN=$((CPU_ID / 2 + (CPU_ID % 2) * 6 + 2))
#CPU_PIN=$((CPU_ID * 2))
taskset -p --cpu-list $CPU_PIN $TASK
chrt -f -p 1 $TASK
else
echo unknown CPU $TASKNAME
exit 1
fi
;;
*)
echo unknown task $TASKNAME
;;
esac
done
''

View file

@ -1,92 +0,0 @@
{ pkgs, writeShellScriptBin }:
writeShellScriptBin "win10-vm" ''
cat ${pkgs.OVMF.fd}/FV/OVMF_VARS.fd > /tmp/OVMF_VARS.fd
exec ${pkgs.qemu-vfio}/bin/qemu-system-x86_64 -name guest=win10,debug-threads=on \
-blockdev '{"driver":"file","filename":"${pkgs.OVMF.fd}/FV/OVMF_CODE.fd","node-name":"libvirt-pflash0-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-pflash0-format","read-only":true,"driver":"raw","file":"libvirt-pflash0-storage"}' \
-blockdev '{"driver":"file","filename":"/tmp/OVMF_VARS.fd","node-name":"libvirt-pflash1-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-pflash1-format","read-only":false,"driver":"raw","file":"libvirt-pflash1-storage"}' \
-machine pc-q35-5.1,accel=kvm,usb=off,vmport=off,dump-guest-core=off,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format \
-monitor stdio \
-cpu host,topoext=on,host-cache-info=on,+invtsc,smep=off,hv_time,hv_relaxed,hv_spinlocks=0x1fff,hv_vendor_id=ab12341234ab$,hv_vapic,-amd-stibp \
-m 12288 \
-mem-path /dev/hugepages1G/qemu-win10-vm -mem-prealloc \
-smp 8,sockets=1,dies=1,cores=4,threads=2 \
-object iothread,id=iothread1 \
-object iothread,id=iothread2 \
-object iothread,id=iothread3 \
-object iothread,id=iothread4 \
-uuid 96052919-6a83-4e9f-8e9b-628de3e27cc1 \
-display none \
-no-user-config \
-nodefaults \
-rtc base=localtime,driftfix=slew -global kvm-pit.lost_tick_policy=delay \
-no-hpet -no-shutdown \
-global ICH9-LPC.disable_s3=1 \
-global ICH9-LPC.disable_s4=1 \
-boot strict=on \
-device pcie-root-port,port=0x10,chassis=1,id=pci.1,bus=pcie.0,multifunction=on,addr=0x2 \
-device pcie-root-port,port=0x11,chassis=2,id=pci.2,bus=pcie.0,addr=0x2.0x1 \
-device pcie-root-port,port=0x12,chassis=3,id=pci.3,bus=pcie.0,addr=0x2.0x2 \
-device pcie-root-port,port=0x13,chassis=4,id=pci.4,bus=pcie.0,addr=0x2.0x3 \
-device pcie-root-port,port=0x14,chassis=5,id=pci.5,bus=pcie.0,addr=0x2.0x4 \
-device pcie-root-port,port=0x15,chassis=6,id=pci.6,bus=pcie.0,addr=0x2.0x5 \
-device pcie-root-port,port=0x16,chassis=7,id=pci.7,bus=pcie.0,addr=0x2.0x6 \
-device pcie-pci-bridge,id=pci.8,bus=pci.4,addr=0x0 \
-device pcie-root-port,port=0x17,chassis=9,id=pci.9,bus=pcie.0,addr=0x2.0x7 \
-device pcie-root-port,port=0x8,chassis=10,id=pci.10,bus=pcie.0,multifunction=on,addr=0x1 \
-device pcie-root-port,port=0xa,chassis=11,id=pci.11,bus=pcie.0,addr=0x1.0x1 \
-device pcie-root-port,port=0xa,chassis=12,id=pci.12,bus=pcie.0,addr=0x1.0x2 \
-device pcie-root-port,port=0xb,chassis=13,id=pci.13,bus=pcie.0,addr=0x1.0x3 \
-device pcie-root-port,port=0xc,chassis=14,id=pci.14,bus=pcie.0,addr=0x1.0x4 \
-device pcie-root-port,port=0xd,chassis=15,id=pci.15,bus=pcie.0,addr=0x1.0x5 \
-device pcie-root-port,port=0xe,chassis=16,id=pci.16,bus=pcie.0,addr=0x1.0x6 \
-device pcie-root-port,port=0xf,chassis=17,id=pci.17,bus=pcie.0,addr=0x1.0x7 \
-device pcie-root-port,port=0x18,chassis=18,id=pci.18,bus=pcie.0,multifunction=on,addr=0x3 \
-device pcie-root-port,port=0x19,chassis=19,id=pci.19,bus=pcie.0,addr=0x3.0x1 \
-device pcie-root-port,port=0x1a,chassis=20,id=pci.20,bus=pcie.0,addr=0x3.0x2 \
-device pcie-root-port,port=0x1b,chassis=21,id=pci.21,bus=pcie.0,addr=0x3.0x3 \
-device pcie-root-port,port=0x1c,chassis=22,id=pci.22,bus=pcie.0,addr=0x3.0x4 \
-device pcie-root-port,port=0x1d,chassis=23,id=pci.23,bus=pcie.0,multifunction=on,addr=0x3.0x5 \
-device pcie-pci-bridge,id=pci.24,bus=pci.10,addr=0x0 \
-device ich9-usb-ehci1,id=usb -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,multifunction=on -device ich9-usb-uhci2,masterbus=usb.0,firstport=2 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4 \
-device qemu-xhci,id=usb3,p2=4,p3=8 \
-device virtio-scsi-pci,id=scsi0,bus=pci.6,addr=0x0 \
-device virtio-serial-pci,id=virtio-serial0,bus=pci.3,addr=0x0 \
-device ich9-intel-hda,id=sound0 \
-device hda-output,audiodev=pa1 \
-device hda-micro,audiodev=pa1 \
-audiodev pa,id=pa1,server=/run/user/1000/pulse/native,out.buffer-length=4000,timer-period=1000 \
-blockdev '{"driver":"host_device","filename":"/dev/disk/by-id/ata-HFS256G32TNF-N3A0A_MJ8BN15091150BM1Z","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-2-format","read-only":false,"discard":"unmap","driver":"raw","file":"libvirt-2-storage"}' \
-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,device_id=drive-scsi0-0-0-0,drive=libvirt-2-format,id=scsi0-0-0-0,bootindex=2 \
-blockdev '{"driver":"host_device","filename":"/dev/mapper/ata-ST2000DM008-2FR102_WK301C3H-part2","aio":"native","node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},"auto-read-only":true,"discard":"unmap"}' \
-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=1,device_id=drive-scsi0-0-0-1,drive=libvirt-1-format,id=scsi0-0-0-1,bootindex=3 \
-blockdev '{"node-name":"libvirt-1-format","read-only":false,"cache":{"direct":true,"no-flush":false},"driver":"raw","file":"libvirt-1-storage"}' \
-netdev user,id=smbnet0,restrict=no,net=10.1.2.0/24,host=10.1.2.1,smb=/home/kat/shared/,smbserver=10.1.2.2 \
-device virtio-net-pci,netdev=smbnet0,id=net1,mac=2b:c6:c4:ac:67:ba \
-device vfio-pci,host=0000:29:00.0,id=hostdev0,bus=pci.7,addr=0x0 \
-device vfio-pci,host=0000:29:00.1,id=hostdev1,bus=pci.9,addr=0x0 \
-device vfio-pci,host=0000:28:00.0,id=hostdev3,bus=pci.11,addr=0x0 \
-device vfio-pci,host=0000:2b:00.3,id=hostdev4,bus=pci.19,addr=0x0 \
-device virtio-balloon-pci,id=balloon0,bus=pci.5,addr=0x0 \
-chardev socket,path=/tmp/vfio-qmp,server,nowait,id=qmp0 \
-mon chardev=qmp0,id=qmp,mode=control \
-chardev socket,path=/tmp/vfio-qga,server,nowait,id=qga0 \
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
-set device.scsi0-0-0-0.rotation_rate=1 \
-cpu host,hv_time,kvm=off,hv_vendor_id=null,-hypervisor \
-msg timestamp=on "$@"''
# -device vfio-pci,host=0000:21:00.0,id,addr=0x0 \
# -device virtio-net-pci,netdev=hostnet0,id=net0,mac=5b:f2:eb:3c:0b:46 \
# -netdev bridge,id=hostnet0,br=br,helper=$(type -P qemu-bridge-helper) \
# -vcpu vcpunum=0,affinity=0 \
# -vcpu vcpunum=1,affinity=1 \
# -vcpu vcpunum=2,affinity=2 \
# -vcpu vcpunum=3,affinity=3 \
# -vcpu vcpunum=4,affinity=6 \
# -vcpu vcpunum=5,affinity=7 \
# -vcpu vcpunum=6,affinity=8 \
# -vcpu vcpunum=7,affinity=9 \

View file

@ -1,5 +0,0 @@
{ wrapShellScriptBin, pkgs }:
wrapShellScriptBin "kat-gpg-status" ./kat-gpg-status.sh {
depsRuntimePath = with pkgs; [ coreutils-full gawk gnugrep gnupg ];
}

View file

@ -1,12 +0,0 @@
#!/bin/bash
set -eu
set -o pipefail
if gpg --card-status &> /dev/null; then
user="$(gpg --card-status | grep 'Login data' | awk '{print $NF}')";
status='{"text": "", "alt": "User: '"$user"'", "class": "enabled"}'
else
status='{"text": "", "alt": "No card is connected.", "class": "disabled"}'
fi
echo $status

View file

@ -1,22 +0,0 @@
{ stdenv, wrapShellScriptBin, pkgs }:
let
toggle = wrapShellScriptBin "konawall-toggle" ./toggle.sh { };
status = wrapShellScriptBin "konawall-status" ./status.sh { };
in
stdenv.mkDerivation {
pname = "konawall-toggle";
version = "0.0.1";
propagatedBuildInputs = with pkgs; [
gawk
coreutils-full
bash
];
unpackPhase = "true";
installPhase = ''
mkdir -p $out/bin
cp ${status}/bin/konawall-status $out/bin/konawall-status
cp ${toggle}/bin/konawall-toggle $out/bin/konawall-toggle
chmod +x $out/bin/konawall-{status,toggle}
'';
}

View file

@ -1,13 +0,0 @@
#!/bin/bash
set -eu
set -o pipefail
sleep 0.5s
if systemctl --user is-active konawall-rotation.timer --quiet; then
status='{"text": "", "alt": "Konawall is enabled.", "class": "enabled"}'
else
status='{"text": "", "alt": "Konawall is disabled.", "class": "disabled"}'
fi
echo $status

View file

@ -1,12 +0,0 @@
#!/bin/bash
set -eu
set -o pipefail
if systemctl --user is-active konawall-rotation.timer --quiet; then
systemctl --user stop konawall-rotation.timer
else
systemctl --user start konawall-rotation.timer
fi
pkill -SIGRTMIN+8 waybar

View file

@ -1,127 +0,0 @@
{ stdenv
, rustPlatform
, lib
, fetchFromGitHub
, ncurses
, perl
, pkg-config
, python3
, fontconfig
, openssl
, libGL
, libX11
, libxcb
, libxkbcommon
, xcbutil
, xcbutilimage
, xcbutilkeysyms
, xcbutilwm
, wayland
, zlib
, CoreGraphics
, Cocoa
, Foundation
, UserNotifications
, libiconv
, nixosTests
, runCommand
}:
rustPlatform.buildRustPackage rec {
pname = "wezterm";
version = "20220624-141144-bd1b7c5d";
src = fetchFromGitHub {
owner = "wez";
repo = pname;
rev = "cb89f2c36e08e74512ee7b8e1aff3bf461f774c2";
fetchSubmodules = true;
sha256 = "sha256-Pmd5I2p2BDhJ3Mm7uGZjWYladZN2x8MMtquP4+TVtJ0=";
};
postPatch = ''
echo ${version} > .tag
# tests are failing with: Unable to exchange encryption keys
rm -r wezterm-ssh/tests
'';
cargoSha256 = "sha256-0jhJzz3lrQf+7vv373J1HfzzVw+eottdto/ephnz4HM=";
nativeBuildInputs = [
pkg-config
python3
ncurses # tic for terminfo
] ++ lib.optional stdenv.isDarwin perl;
buildInputs = [
fontconfig
zlib
] ++ lib.optionals stdenv.isLinux [
libX11
libxcb
libxkbcommon
openssl
wayland
xcbutil
xcbutilimage
xcbutilkeysyms
xcbutilwm # contains xcb-ewmh among others
] ++ lib.optionals stdenv.isDarwin [
Cocoa
CoreGraphics
UserNotifications
Foundation
libiconv
];
postInstall = ''
mkdir -p $out/nix-support
echo "${passthru.terminfo}" >> $out/nix-support/propagated-user-env-packages
# desktop icon
install -Dm644 assets/icon/terminal.png $out/share/icons/hicolor/128x128/apps/org.wezfurlong.wezterm.png
install -Dm644 assets/wezterm.desktop $out/share/applications/org.wezfurlong.wezterm.desktop
install -Dm644 assets/wezterm.appdata.xml $out/share/metainfo/org.wezfurlong.wezterm.appdata.xml
# helper scripts
install -Dm644 assets/shell-integration/wezterm.sh -t $out/etc/profile.d
'';
preFixup = lib.optionalString stdenv.isLinux ''
patchelf --add-needed "${libGL}/lib/libEGL.so.1" $out/bin/wezterm-gui
'' + lib.optionalString stdenv.isDarwin ''
mkdir -p "$out/Applications"
OUT_APP="$out/Applications/WezTerm.app"
cp -r assets/macos/WezTerm.app "$OUT_APP"
rm $OUT_APP/*.dylib
cp -r assets/shell-integration/* "$OUT_APP"
ln -s $out/bin/{wezterm,wezterm-mux-server,wezterm-gui,strip-ansi-escapes} "$OUT_APP"
'';
passthru = {
tests = {
all-terminfo = nixosTests.allTerminfo;
terminal-emulators = nixosTests.terminal-emulators.wezterm;
};
terminfo = runCommand "wezterm-terminfo"
{
nativeBuildInputs = [
ncurses
];
} ''
mkdir -p $out/share/terminfo $out/nix-support
tic -x -o $out/share/terminfo ${src}/termwiz/data/wezterm.terminfo
'';
};
meta = with lib; {
description = "A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust";
homepage = "https://wezfurlong.org/wezterm";
license = licenses.mit;
maintainers = with maintainers; [ SuperSandro2000 ];
platforms = platforms.unix;
# Fails on missing UserNotifications framework while linking
broken = stdenv.isDarwin;
};
}

View file

@ -1,41 +0,0 @@
{ lib
, buildPythonPackage
, pythonOlder
, fetchPypi
, poetry
, arrow
, requests-oauth
, requests-oauthlib
, typing-extensions
, pydantic
}:
buildPythonPackage rec {
pname = "withings-api";
version = "2.4.0";
format = "pyproject";
disabled = pythonOlder "3.6";
src = fetchPypi {
pname = "withings_api"; # source and whl distribution use _ instead of -
inherit version;
sha256 = "sha256-vQ6MKeD4g4QTkXx638FW53mTkx78af7NQXF00kxgM10=";
};
propagatedBuildInputs = [
poetry
arrow
requests-oauth
requests-oauthlib
typing-extensions
pydantic
];
meta = {
description = "Library for the Withings Health API";
homepage = "https://github.com/vangorra/python_withings_api";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ kittywitch ];
};
}

View file

@ -1,35 +0,0 @@
{ lib
, stdenv
, php
, fetchurl
, unzip
}:
stdenv.mkDerivation rec {
pname = "XBackBone";
version = "3.5.0";
nativeBuildInputs = [
unzip
];
src = fetchurl {
url = "https://github.com/SergiX44/XBackBone/releases/download/${version}/release-v${version}.zip";
sha256 = "17p180yhsgjsm9pa5vkmqfrk71avss33vw2bjb6py90dwknbkipl";
};
sourceRoot = ".";
installPhase = ''
mkdir -p $out
mv * $out
'';
meta = {
description = "A lightweight file manager with full ShareX, Screencloud support and more";
homepage = "https://xbackbone.app/";
license = lib.licenses.agpl3;
maintainers = [ lib.maintainers.kittywitch ];
platforms = lib.platforms.unix;
};
}

View file

@ -1,6 +0,0 @@
{ inputs }: final: prev: {
nur = import inputs.nur {
nurpkgs = final;
pkgs = final;
};
}

View file

@ -1,446 +0,0 @@
From 179af0e572c1f5e9e124fea96bf8597e3212967d Mon Sep 17 00:00:00 2001
SPDX-FileCopyrightText: Yusuke Tanaka <yusuktan@maguro.dev>
SPDX-License-Identifier: Apache-2.0
From: Yusuke Tanaka <yusuktan@maguro.dev>
Date: Sat, 30 Jan 2021 14:50:28 +0900
Subject: [PATCH] Implement `One` option for imports_granularity (#4669)
This option merges all imports into a single `use` statement as long as
they have the same visibility.
---
src/tools/rustfmt/Configurations.md | 19 ++-
src/tools/rustfmt/src/config/options.rs | 2 +
src/tools/rustfmt/src/imports.rs | 146 +++++++++++++++---
src/tools/rustfmt/src/reorder.rs | 1 +
.../tests/source/imports_granularity_one.rs | 60 +++++++
.../tests/target/imports_granularity_one.rs | 79 ++++++++++
6 files changed, 288 insertions(+), 19 deletions(-)
create mode 100644 src/tools/rustfmt/tests/source/imports_granularity_one.rs
create mode 100644 src/tools/rustfmt/tests/target/imports_granularity_one.rs
diff --git a/src/tools/rustfmt/Configurations.md b/src/tools/rustfmt/Configurations.md
index 37cb7474130..601f6eeb9bd 100644
--- a/src/tools/rustfmt/Configurations.md
+++ b/src/tools/rustfmt/Configurations.md
@@ -1665,7 +1665,7 @@ pub enum Foo {}
How imports should be grouped into `use` statements. Imports will be merged or split to the configured level of granularity.
- **Default value**: `Preserve`
-- **Possible values**: `Preserve`, `Crate`, `Module`, `Item`
+- **Possible values**: `Preserve`, `Crate`, `Module`, `Item`, `One`
- **Stable**: No
#### `Preserve` (default):
@@ -1719,6 +1719,23 @@ use qux::h;
use qux::i;
```
+#### `One`:
+
+Merge all imports into a single `use` statement as long as they have the same visibility.
+
+```rust
+pub use foo::{x, y};
+use {
+ bar::{
+ a,
+ b::{self, f, g},
+ c,
+ d::e,
+ },
+ qux::{h, i},
+};
+```
+
## `merge_imports`
This option is deprecated. Use `imports_granularity = "Crate"` instead.
diff --git a/src/tools/rustfmt/src/config/options.rs b/src/tools/rustfmt/src/config/options.rs
index 3b91021813c..db15ee97a40 100644
--- a/src/tools/rustfmt/src/config/options.rs
+++ b/src/tools/rustfmt/src/config/options.rs
@@ -125,6 +125,8 @@ pub enum ImportGranularity {
Module,
/// Use one `use` statement per imported item.
Item,
+ /// Use one `use` statement including all items.
+ One,
}
#[config_type]
diff --git a/src/tools/rustfmt/src/imports.rs b/src/tools/rustfmt/src/imports.rs
index 0f635fe1ccb..f5e780eb1ec 100644
--- a/src/tools/rustfmt/src/imports.rs
+++ b/src/tools/rustfmt/src/imports.rs
@@ -138,6 +138,29 @@ fn remove_alias(&self) -> UseSegment {
}
}
+ // Check if self == other with their aliases removed.
+ fn equal_except_alias(&self, other: &Self) -> bool {
+ match (self, other) {
+ (UseSegment::Ident(ref s1, _), UseSegment::Ident(ref s2, _)) => s1 == s2,
+ (UseSegment::Slf(_), UseSegment::Slf(_))
+ | (UseSegment::Super(_), UseSegment::Super(_))
+ | (UseSegment::Crate(_), UseSegment::Crate(_))
+ | (UseSegment::Glob, UseSegment::Glob) => true,
+ (UseSegment::List(ref list1), UseSegment::List(ref list2)) => list1 == list2,
+ _ => false,
+ }
+ }
+
+ fn get_alias(&self) -> Option<&str> {
+ match self {
+ UseSegment::Ident(_, a)
+ | UseSegment::Slf(a)
+ | UseSegment::Super(a)
+ | UseSegment::Crate(a) => a.as_deref(),
+ _ => None,
+ }
+ }
+
fn from_path_segment(
context: &RewriteContext<'_>,
path_seg: &ast::PathSegment,
@@ -561,6 +584,7 @@ fn share_prefix(&self, other: &UseTree, shared_prefix: SharedPrefix) -> bool {
SharedPrefix::Module => {
self.path[..self.path.len() - 1] == other.path[..other.path.len() - 1]
}
+ SharedPrefix::One => true,
}
}
}
@@ -602,7 +626,7 @@ fn flatten(self) -> Vec<UseTree> {
fn merge(&mut self, other: &UseTree, merge_by: SharedPrefix) {
let mut prefix = 0;
for (a, b) in self.path.iter().zip(other.path.iter()) {
- if *a == *b {
+ if a.equal_except_alias(b) {
prefix += 1;
} else {
break;
@@ -637,14 +661,20 @@ fn merge_rest(
return Some(new_path);
}
} else if len == 1 {
- let rest = if a.len() == len { &b[1..] } else { &a[1..] };
- return Some(vec![
- b[0].clone(),
- UseSegment::List(vec![
- UseTree::from_path(vec![UseSegment::Slf(None)], DUMMY_SP),
- UseTree::from_path(rest.to_vec(), DUMMY_SP),
- ]),
- ]);
+ let (common, rest) = if a.len() == len {
+ (&a[0], &b[1..])
+ } else {
+ (&b[0], &a[1..])
+ };
+ let mut list = vec![UseTree::from_path(
+ vec![UseSegment::Slf(common.get_alias().map(ToString::to_string))],
+ DUMMY_SP,
+ )];
+ match rest {
+ [UseSegment::List(rest_list)] => list.extend(rest_list.clone()),
+ _ => list.push(UseTree::from_path(rest.to_vec(), DUMMY_SP)),
+ }
+ return Some(vec![b[0].clone(), UseSegment::List(list)]);
} else {
len -= 1;
}
@@ -659,18 +689,54 @@ fn merge_rest(
}
fn merge_use_trees_inner(trees: &mut Vec<UseTree>, use_tree: UseTree, merge_by: SharedPrefix) {
- let similar_trees = trees
- .iter_mut()
- .filter(|tree| tree.share_prefix(&use_tree, merge_by));
+ struct SimilarTree<'a> {
+ similarity: usize,
+ path_len: usize,
+ tree: &'a mut UseTree,
+ }
+
+ let similar_trees = trees.iter_mut().filter_map(|tree| {
+ if tree.share_prefix(&use_tree, merge_by) {
+ // In the case of `SharedPrefix::One`, `similarity` is used for deciding with which
+ // tree `use_tree` should be merge.
+ // In other cases `similarity` won't be used, so set it to `0` as a dummy value.
+ let similarity = if merge_by == SharedPrefix::One {
+ tree.path
+ .iter()
+ .zip(&use_tree.path)
+ .take_while(|(a, b)| a.equal_except_alias(b))
+ .count()
+ } else {
+ 0
+ };
+
+ let path_len = tree.path.len();
+ Some(SimilarTree {
+ similarity,
+ tree,
+ path_len,
+ })
+ } else {
+ None
+ }
+ });
+
if use_tree.path.len() == 1 && merge_by == SharedPrefix::Crate {
- if let Some(tree) = similar_trees.min_by_key(|tree| tree.path.len()) {
- if tree.path.len() == 1 {
+ if let Some(tree) = similar_trees.min_by_key(|tree| tree.path_len) {
+ if tree.path_len == 1 {
return;
}
}
- } else if let Some(tree) = similar_trees.max_by_key(|tree| tree.path.len()) {
- if tree.path.len() > 1 {
- tree.merge(&use_tree, merge_by);
+ } else if merge_by == SharedPrefix::One {
+ if let Some(sim_tree) = similar_trees.max_by_key(|tree| tree.similarity) {
+ if sim_tree.similarity > 0 {
+ sim_tree.tree.merge(&use_tree, merge_by);
+ return;
+ }
+ }
+ } else if let Some(sim_tree) = similar_trees.max_by_key(|tree| tree.path_len) {
+ if sim_tree.path_len > 1 {
+ sim_tree.tree.merge(&use_tree, merge_by);
return;
}
}
@@ -888,6 +954,7 @@ fn rewrite(&self, context: &RewriteContext<'_>, mut shape: Shape) -> Option<Stri
pub(crate) enum SharedPrefix {
Crate,
Module,
+ One,
}
#[cfg(test)]
@@ -912,7 +979,7 @@ fn bump(&mut self) {
}
fn eat(&mut self, c: char) {
- assert!(self.input.next().unwrap() == c);
+ assert_eq!(self.input.next().unwrap(), c);
}
fn push_segment(
@@ -1102,6 +1169,49 @@ fn test_use_tree_merge_module() {
);
}
+ #[test]
+ fn test_use_tree_merge_one() {
+ test_merge!(One, ["a", "b"], ["{a, b}"]);
+
+ test_merge!(One, ["a::{aa, ab}", "b", "a"], ["{a::{self, aa, ab}, b}"]);
+
+ test_merge!(One, ["a as x", "b as y"], ["{a as x, b as y}"]);
+
+ test_merge!(
+ One,
+ ["a::{aa as xa, ab}", "b", "a"],
+ ["{a::{self, aa as xa, ab}, b}"]
+ );
+
+ test_merge!(
+ One,
+ ["a", "a::{aa, ab::{aba, abb}}"],
+ ["a::{self, aa, ab::{aba, abb}}"]
+ );
+
+ test_merge!(One, ["a", "b::{ba, *}"], ["{a, b::{ba, *}}"]);
+
+ test_merge!(One, ["a", "b", "a::aa"], ["{a::{self, aa}, b}"]);
+
+ test_merge!(
+ One,
+ ["a::aa::aaa", "a::ac::aca", "a::aa::*"],
+ ["a::{aa::{aaa, *}, ac::aca}"]
+ );
+
+ test_merge!(
+ One,
+ ["a", "b::{ba, bb}", "a::{aa::*, ab::aba}"],
+ ["{a::{self, aa::*, ab::aba}, b::{ba, bb}}"]
+ );
+
+ test_merge!(
+ One,
+ ["b", "a::ac::{aca, acb}", "a::{aa::*, ab}"],
+ ["{a::{aa::*, ab, ac::{aca, acb}}, b}"]
+ );
+ }
+
#[test]
fn test_flatten_use_trees() {
assert_eq!(
diff --git a/src/tools/rustfmt/src/reorder.rs b/src/tools/rustfmt/src/reorder.rs
index ac65ff2c108..2c58350d4fe 100644
--- a/src/tools/rustfmt/src/reorder.rs
+++ b/src/tools/rustfmt/src/reorder.rs
@@ -113,6 +113,7 @@ fn rewrite_reorderable_or_regroupable_items(
merge_use_trees(normalized_items, SharedPrefix::Module)
}
ImportGranularity::Item => flatten_use_trees(normalized_items),
+ ImportGranularity::One => merge_use_trees(normalized_items, SharedPrefix::One),
ImportGranularity::Preserve => normalized_items,
};
diff --git a/src/tools/rustfmt/tests/source/imports_granularity_one.rs b/src/tools/rustfmt/tests/source/imports_granularity_one.rs
new file mode 100644
index 00000000000..c21707df395
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/imports_granularity_one.rs
@@ -0,0 +1,60 @@
+// rustfmt-imports_granularity: One
+
+use b;
+use a::ac::{aca, acb};
+use a::{aa::*, ab};
+
+use a as x;
+use b::ba;
+use a::{aa, ab};
+
+use a::aa::aaa;
+use a::ab::aba as x;
+use a::aa::*;
+
+use a::aa;
+use a::ad::ada;
+#[cfg(test)]
+use a::{ab, ac::aca};
+use b;
+#[cfg(test)]
+use b::{
+ ba, bb,
+ bc::bca::{bcaa, bcab},
+};
+
+pub use a::aa;
+pub use a::ae;
+use a::{ab, ac, ad};
+use b::ba;
+pub use b::{bb, bc::bca};
+
+use a::aa::aaa;
+use a::ac::{aca, acb};
+use a::{aa::*, ab};
+use b::{
+ ba,
+ bb::{self, bba},
+};
+
+use crate::a;
+use crate::b::ba;
+use c::ca;
+
+use super::a;
+use c::ca;
+use super::b::ba;
+
+use crate::a;
+use super::b;
+use c::{self, ca};
+
+use a::{
+ // some comment
+ aa::{aaa, aab},
+ ab,
+ // another comment
+ ac::aca,
+};
+use b as x;
+use a::ad::ada;
diff --git a/src/tools/rustfmt/tests/target/imports_granularity_one.rs b/src/tools/rustfmt/tests/target/imports_granularity_one.rs
new file mode 100644
index 00000000000..78ec5e7325c
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/imports_granularity_one.rs
@@ -0,0 +1,79 @@
+// rustfmt-imports_granularity: One
+
+use {
+ a::{
+ aa::*,
+ ab,
+ ac::{aca, acb},
+ },
+ b,
+};
+
+use {
+ a::{self as x, aa, ab},
+ b::ba,
+};
+
+use a::{
+ aa::{aaa, *},
+ ab::aba as x,
+};
+
+#[cfg(test)]
+use a::{ab, ac::aca};
+#[cfg(test)]
+use b::{
+ ba, bb,
+ bc::bca::{bcaa, bcab},
+};
+use {
+ a::{aa, ad::ada},
+ b,
+};
+
+pub use {
+ a::{aa, ae},
+ b::{bb, bc::bca},
+};
+use {
+ a::{ab, ac, ad},
+ b::ba,
+};
+
+use {
+ a::{
+ aa::{aaa, *},
+ ab,
+ ac::{aca, acb},
+ },
+ b::{
+ ba,
+ bb::{self, bba},
+ },
+};
+
+use {
+ crate::{a, b::ba},
+ c::ca,
+};
+
+use {
+ super::{a, b::ba},
+ c::ca,
+};
+
+use {
+ super::b,
+ crate::a,
+ c::{self, ca},
+};
+
+use {
+ a::{
+ aa::{aaa, aab},
+ ab,
+ ac::aca,
+ ad::ada,
+ },
+ b as x,
+};
--
2.32.0

View file

@ -1,9 +0,0 @@
final: prev: {
rustfmt = prev.rustfmt.overrideAttrs ({ patches ? [ ], ... }: {
patches = patches ++ [
# Adds an option variant that merges all use statements into a single block.
# Taken from https://github.com/rust-lang/rustfmt/pull/4680
./Implement-One-option-for-imports_granularity-4669.patch
];
});
}