diff --git a/flake.nix b/flake.nix index 53db802..ef08f3e 100644 --- a/flake.nix +++ b/flake.nix @@ -1,324 +1,318 @@ { - description = "MIREA desktop"; - inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11"; - outputs = { self, nixpkgs, ... }: + description = "MIREA desktop"; + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11"; + outputs = + { self, nixpkgs, ... }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + + wallpaper = builtins.readFile "${self}/wallpaper.svg"; + folderIcon = builtins.readFile "${self}/folderIcon.svg"; + pcmanfmConf = "${self}/pcmanfm.conf"; + mimeappsList = "${self}/mimeapps.list"; + + desktopItems0 = ( + pkgs.writeText "desktop-items-0.conf" '' + [*] + wallpaper_mode=center + wallpaper_common=1 + wallpapers_configured=1 + wallpaper=${self}/wallpaper.svg + desktop_bg=#77767b + desktop_fg=#ffffff + desktop_shadow=#000000 + desktop_font=Sans 12 + folder=/home/student + show_wm_menu=1 + sort=mtime;ascending; + show_documents=0 + show_trash=1 + show_mounts=1 + '' + ); + + jgmenu_run_prepared = ( + pkgs.writeShellScript "jgmenu_run_prepared" "${pkgs.jgmenu}/bin/jgmenu_run apps | ${prepare_jgmenu}/bin/prepare_jgmenu | ${pkgs.jgmenu}/bin/jgmenu --simple" + ); + + powermenu = ( let - pkgs = import nixpkgs { system = "x86_64-linux"; }; + zenityDialog = + msg: cmd: + ''${pkgs.zenity}/bin/zenity --question --text "Уверены, что хотите ${msg}?" --default-cancel; && ${cmd}''; + in + pkgs.writeShellScript "powermenu" '' + if [ "$1" = "poweroff" ]; then + ${zenityDialog "Выключить" "poweroff"} + exit 0 + fi - wallpaper = builtins.readFile "${self}/wallpaper.svg"; - folderIcon = builtins.readFile "${self}/folderIcon.svg"; - pcmanfmConf = "${self}/pcmanfm.conf"; - mimeappsList = "${self}/mimeapps.list"; + if [ "$1" = "reboot" ]; then + ${zenityDialog "Выключить" "reboot"} + exit 0 + fi + '' + ); - desktopItems0 = (pkgs.writeText "desktop-items-0.conf" -'' -[*] -wallpaper_mode=center -wallpaper_common=1 -wallpapers_configured=1 -wallpaper=${self}/wallpaper.svg -desktop_bg=#77767b -desktop_fg=#ffffff -desktop_shadow=#000000 -desktop_font=Sans 12 -folder=/home/student -show_wm_menu=1 -sort=mtime;ascending; -show_documents=0 -show_trash=1 -show_mounts=1 -''); + mireaweek = pkgs.stdenv.mkDerivation rec { + pname = "mireaweek"; + version = "0.1.0"; + src = ./weekday.kt; + dontInstall = true; + dontUnpack = true; + nativeBuildInputs = [ pkgs.kotlin ]; + buildPhase = '' + mkdir -p $out/{bin,lib} + kotlinc $src -include-runtime -d mireaweek.jar + mv mireaweek.jar $out/lib + printf "${pkgs.jre}/bin/java -jar $out/lib/mireaweek.jar" > $out/bin/mireaweek + chmod +x $out/bin/mireaweek + ''; + }; - jgmenu_run_prepared = - (pkgs.writeShellScript "jgmenu_run_prepared" - ''${pkgs.jgmenu}/bin/jgmenu_run apps | ${prepare_jgmenu}/bin/prepare_jgmenu | ${pkgs.jgmenu}/bin/jgmenu --simple''); + prepare_jgmenu = pkgs.stdenv.mkDerivation rec { + pname = "prepare_jgmenu"; + version = "0.1.0"; + src = ./JgmenuCorrector.kt; + dontInstall = true; + dontUnpack = true; + nativeBuildInputs = [ pkgs.kotlin ]; + buildPhase = '' + mkdir -p $out/{bin,lib} + kotlinc $src -include-runtime -d prepare.jar + mv prepare.jar $out/lib + printf "${pkgs.jre}/bin/java -jar $out/lib/prepare.jar" > $out/bin/prepare_jgmenu + chmod +x $out/bin/prepare_jgmenu + ''; + }; - powermenu = (pkgs.writeShellScript "powermenu" -'' -if [ "$1" = "poweroff" ]; then - ${pkgs.zenity}/bin/zenity --question --text "Уверены, что хотите выключить?" --default-cancel && poweroff - exit 0 -fi + tint2conf1 = builtins.readFile "${self}/tint2conf.1"; + tint2conf2 = builtins.readFile "${self}/tint2conf.2"; -if [ "$1" = "reboot" ]; then - ${pkgs.zenity}/bin/zenity --question --text "Уверены, что хотите перезагрузить?" --default-cancel && reboot - exit 0 -fi -''); + tint2config = pkgs.writeText "tint2conf" '' + ${tint2conf1} + #------------------------------------- + button = new + button_lclick_command = ${jgmenu_run_prepared} + button_icon = ${self}/wallpaper.svg - mireaweek = pkgs.stdenv.mkDerivation rec { - pname = "mireaweek"; - version = "0.1.0"; - src = ./weekday.kt; - dontInstall = true; - dontUnpack = true; - nativeBuildInputs = [ pkgs.kotlin ]; - buildPhase = '' - mkdir -p $out/{bin,lib} - kotlinc $src -include-runtime -d mireaweek.jar - mv mireaweek.jar $out/lib - printf "${pkgs.jre}/bin/java -jar $out/lib/mireaweek.jar" > $out/bin/mireaweek - chmod +x $out/bin/mireaweek - ''; - }; + separator = new + separator_style = empty + separator_padding = 3 4 - prepare_jgmenu = pkgs.stdenv.mkDerivation rec { - pname = "prepare_jgmenu"; - version = "0.1.0"; - src = ./JgmenuCorrector.kt; - dontInstall = true; - dontUnpack = true; - nativeBuildInputs = [ pkgs.kotlin ]; - buildPhase = '' - mkdir -p $out/{bin,lib} - kotlinc $src -include-runtime -d prepare.jar - mv prepare.jar $out/lib - printf "${pkgs.jre}/bin/java -jar $out/lib/prepare.jar" > $out/bin/prepare_jgmenu - chmod +x $out/bin/prepare_jgmenu - ''; - }; + button = new + button_lclick_command = ${pkgs.chromium}/bin/chromium + button_icon = ${pkgs.chromium}/share/icons/hicolor/48x48/apps/chromium.png - tint2conf1 = builtins.readFile "${self}/tint2conf.1"; - tint2conf2 = builtins.readFile "${self}/tint2conf.2"; + button = new + button_lclick_command = ${pkgs.pcmanfm}/bin/pcmanfm + button_icon = ${self}/folderIcon.svg - tint2config = pkgs.writeText "tint2conf" -'' -${tint2conf1} -#------------------------------------- -button = new -button_lclick_command = ${jgmenu_run_prepared} -button_icon = ${self}/wallpaper.svg + separator = new + separator_style = empty + separator_padding = 3 4 -separator = new -separator_style = empty -separator_padding = 3 4 + #------------------------------------- + execp = new + execp_name = switch + execp_command = ${pkgs.xkb-switch}/bin/xkb-switch + execp_interval = 1 + execp_font = mono 10 + execp_font_color = #dddddd 100 + execp_centered = 1 + execp_has_icon = 0 + execp_padding = 5 5 -button = new -button_lclick_command = ${pkgs.chromium}/bin/chromium -button_icon = ${pkgs.chromium}/share/icons/hicolor/48x48/apps/chromium.png + #------------------------------------- + execp = new + execp_name = mireaweek + execp_command = ${mireaweek}/bin/mireaweek + execp_interval = 0 + execp_font = mono 10 + execp_font_color = #dddddd 100 + execp_centered = 1 + execp_has_icon = 0 + execp_padding = 5 5 -button = new -button_lclick_command = ${pkgs.pcmanfm}/bin/pcmanfm -button_icon = ${self}/folderIcon.svg + ${tint2conf2} + ''; -separator = new -separator_style = empty -separator_padding = 3 4 + screenshotDir = ''"$HOME/Pictures/Screenshots"''; + videoDir = ''"$HOME/Videos/ScreenRecords"''; -#------------------------------------- -execp = new -execp_name = switch -execp_command = ${pkgs.xkb-switch}/bin/xkb-switch -execp_interval = 1 -execp_font = mono 10 -execp_font_color = #dddddd 100 -execp_centered = 1 -execp_has_icon = 0 -execp_padding = 5 5 + screenshotFullClipboard = pkgs.writeShellScript "screenshot-full-clipboard" '' + exec ${pkgs.maim}/bin/maim | ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png + ''; -#------------------------------------- -execp = new -execp_name = mireaweek -execp_command = ${mireaweek}/bin/mireaweek -execp_interval = 0 -execp_font = mono 10 -execp_font_color = #dddddd 100 -execp_centered = 1 -execp_has_icon = 0 -execp_padding = 5 5 + screenshotWindowClipboard = pkgs.writeShellScript "screenshot-window-clipboard" '' + exec ${pkgs.maim}/bin/maim -i "$(${pkgs.xdotool}/bin/xdotool getactivewindow)" | ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png + ''; -${tint2conf2} -''; + screenshotFullFile = pkgs.writeShellScript "screenshot-full-file" '' + mkdir -p ${screenshotDir} + exec ${pkgs.maim}/bin/maim "$HOME/Pictures/Screenshots/$(date +%F-%H-%M-%S).png" + ''; - screenshotDir = ''"$HOME/Pictures/Screenshots"''; - videoDir = ''"$HOME/Videos/ScreenRecords"''; + screenshotRegionClipboard = pkgs.writeShellScript "screenshot-region-clipboard" '' + exec ${pkgs.maim}/bin/maim -s | ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png + ''; - screenshotFullClipboard = pkgs.writeShellScript "screenshot-full-clipboard" -'' -exec ${pkgs.maim}/bin/maim | ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png -''; + screenshotRegionFile = pkgs.writeShellScript "screenshot-region-file" '' + mkdir -p ${screenshotDir} + exec ${pkgs.maim}/bin/maim -s "$HOME/Pictures/Screenshots/$(date +%F-%H-%M-%S).png" + ''; - screenshotWindowClipboard = pkgs.writeShellScript "screenshot-window-clipboard" -'' -exec ${pkgs.maim}/bin/maim -i "$(${pkgs.xdotool}/bin/xdotool getactivewindow)" | ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png -''; + recordFullScreen = pkgs.writeShellScript "record-full-screen" '' + set -eu + mkdir -p "$HOME/.cache" ${videoDir} + pidfile="$HOME/.cache/mirea-screenrecord.pid" - screenshotFullFile = pkgs.writeShellScript "screenshot-full-file" -'' -mkdir -p ${screenshotDir} -exec ${pkgs.maim}/bin/maim "$HOME/Pictures/Screenshots/$(date +%F-%H-%M-%S).png" -''; + if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then + kill -INT "$(cat "$pidfile")" + rm -f "$pidfile" + exit 0 + fi - screenshotRegionClipboard = pkgs.writeShellScript "screenshot-region-clipboard" -'' -exec ${pkgs.maim}/bin/maim -s | ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png -''; + geometry="$(${pkgs.xorg.xrandr}/bin/xrandr | awk '/\*/ { print $1; exit }')" + outfile="$HOME/Videos/ScreenRecords/$(date +%F-%H-%M-%S).mkv" - screenshotRegionFile = pkgs.writeShellScript "screenshot-region-file" -'' -mkdir -p ${screenshotDir} -exec ${pkgs.maim}/bin/maim -s "$HOME/Pictures/Screenshots/$(date +%F-%H-%M-%S).png" -''; + ${pkgs.ffmpeg}/bin/ffmpeg \ + -f x11grab \ + -video_size "$geometry" \ + -framerate 30 \ + -i "$DISPLAY" \ + -c:v libx264 \ + -preset ultrafast \ + "$outfile" >/dev/null 2>&1 & - recordFullScreen = pkgs.writeShellScript "record-full-screen" -'' -set -eu -mkdir -p "$HOME/.cache" ${videoDir} -pidfile="$HOME/.cache/mirea-screenrecord.pid" + echo $! > "$pidfile" + ''; -if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then - kill -INT "$(cat "$pidfile")" - rm -f "$pidfile" - exit 0 -fi + capturePanel = pkgs.writeShellScript "capture-panel" '' + choice="$(${pkgs.zenity}/bin/zenity \ + --list \ + --title="Capture" \ + --column="Action" \ + "Screenshot: whole screen -> clipboard" \ + "Screenshot: active window -> clipboard" \ + "Screenshot: whole screen -> file" \ + "Screenshot: region -> clipboard" \ + "Screenshot: region -> file" \ + "Record: whole screen (start/stop)" \ + "Record: region (start/stop)" \ + --height=320 --width=520)" -geometry="$(${pkgs.xorg.xrandr}/bin/xrandr | awk '/\*/ { print $1; exit }')" -outfile="$HOME/Videos/ScreenRecords/$(date +%F-%H-%M-%S).mkv" + case "$choice" in + "Screenshot: whole screen -> clipboard") + exec ${screenshotFullClipboard} + ;; + "Screenshot: active window -> clipboard") + exec ${screenshotWindowClipboard} + ;; + "Screenshot: whole screen -> file") + exec ${screenshotFullFile} + ;; + "Screenshot: region -> clipboard") + exec ${screenshotRegionClipboard} + ;; + "Screenshot: region -> file") + exec ${screenshotRegionFile} + ;; + "Record: whole screen (start/stop)") + exec ${recordFullScreen} + ;; + *) + exit 0 + ;; + esac + ''; -${pkgs.ffmpeg}/bin/ffmpeg \ - -f x11grab \ - -video_size "$geometry" \ - -framerate 30 \ - -i "$DISPLAY" \ - -c:v libx264 \ - -preset ultrafast \ - "$outfile" >/dev/null 2>&1 & + sxhkdConfig = pkgs.writeText "sxhkdrc" '' + # Windows-like + Print + ${screenshotFullClipboard} -echo $! > "$pidfile" -''; + alt + Print + ${screenshotWindowClipboard} - capturePanel = pkgs.writeShellScript "capture-panel" -'' -choice="$(${pkgs.zenity}/bin/zenity \ - --list \ - --title="Capture" \ - --column="Action" \ - "Screenshot: whole screen -> clipboard" \ - "Screenshot: active window -> clipboard" \ - "Screenshot: whole screen -> file" \ - "Screenshot: region -> clipboard" \ - "Screenshot: region -> file" \ - "Record: whole screen (start/stop)" \ - "Record: region (start/stop)" \ - --height=320 --width=520)" + super + Print + ${screenshotFullFile} -case "$choice" in - "Screenshot: whole screen -> clipboard") - exec ${screenshotFullClipboard} - ;; - "Screenshot: active window -> clipboard") - exec ${screenshotWindowClipboard} - ;; - "Screenshot: whole screen -> file") - exec ${screenshotFullFile} - ;; - "Screenshot: region -> clipboard") - exec ${screenshotRegionClipboard} - ;; - "Screenshot: region -> file") - exec ${screenshotRegionFile} - ;; - "Record: whole screen (start/stop)") - exec ${recordFullScreen} - ;; - *) - exit 0 - ;; -esac -''; + super + shift + s + ${screenshotRegionClipboard} - sxhkdConfig = pkgs.writeText "sxhkdrc" -'' -# Windows-like -Print - ${screenshotFullClipboard} + # macOS-like + super + shift + 3 + ${screenshotFullFile} -alt + Print - ${screenshotWindowClipboard} + control + super + shift + 3 + ${screenshotFullClipboard} -super + Print - ${screenshotFullFile} + super + shift + 4 + ${screenshotRegionFile} -super + shift + s - ${screenshotRegionClipboard} + super + shift + 5 + ${capturePanel} -# macOS-like -super + shift + 3 - ${screenshotFullFile} + # "Run" / terminal + super + r + ${pkgs.sakura}/bin/sakura -control + super + shift + 3 - ${screenshotFullClipboard} + super + Return + ${pkgs.sakura}/bin/sakura -super + shift + 4 - ${screenshotRegionFile} + # tap Super only -> menu + F13 + ${jgmenu_run_prepared} + ''; -super + shift + 5 - ${capturePanel} + sxhkdWrapped = pkgs.writeShellScript "sxhkd-mirea" '' + exec ${pkgs.sxhkd}/bin/sxhkd -c ${sxhkdConfig} + ''; -# "Run" / terminal -super + r - ${pkgs.sakura}/bin/sakura + xcapeWrapped = pkgs.writeShellScript "xcape-mirea" '' + exec ${pkgs.xcape}/bin/xcape -e 'Super_L=F13;Super_R=F13' + ''; -super + Return - ${pkgs.sakura}/bin/sakura + tint2custom = pkgs.writeShellScript "tint2" '' + ${pkgs.tint2}/bin/tint2 -c ${tint2config} + ''; -# tap Super only -> menu -F13 - ${jgmenu_run_prepared} -''; + pcmanfmdesktop = pkgs.writeShellScript "pcmanfm" '' + ${pkgs.pcmanfm}/bin/pcmanfm --desktop + ''; - sxhkdWrapped = pkgs.writeShellScript "sxhkd-mirea" -'' -exec ${pkgs.sxhkd}/bin/sxhkd -c ${sxhkdConfig} -''; + myxinitrc = pkgs.writeText ".xinitrc" '' + ${tint2custom} & + ${pcmanfmdesktop} & + ${sxhkdWrapped} & + ${xcapeWrapped} & + exec ${pkgs.metacity}/bin/metacity + ''; - xcapeWrapped = pkgs.writeShellScript "xcape-mirea" -'' -exec ${pkgs.xcape}/bin/xcape -e 'Super_L=F13;Super_R=F13' -''; - - tint2custom = pkgs.writeShellScript "tint2" -'' -${pkgs.tint2}/bin/tint2 -c ${tint2config} -''; - - pcmanfmdesktop = pkgs.writeShellScript "pcmanfm" -'' -${pkgs.pcmanfm}/bin/pcmanfm --desktop -''; - - myxinitrc = pkgs.writeText ".xinitrc" -'' -${tint2custom} & -${pcmanfmdesktop} & -${sxhkdWrapped} & -${xcapeWrapped} & -exec ${pkgs.metacity}/bin/metacity -''; - - resethome = pkgs.writeShellScript "startmireadesktop" -'' -rm -rf $HOME/{*,.*} 2> /dev/null # wipe student directory, yeah! -printf "[client]\nport=3306\nuser=root" > /home/student/.my.cnf -echo "\set user postgres" > /home/student/.psqlrc -mkdir -p "$HOME/.config/pcmanfm/default" -cp ${desktopItems0} "$HOME/.config/pcmanfm/default/desktop-items-0.conf" -cp ${pcmanfmConf} "$HOME/.config/pcmanfm/default/pcmanfm.conf" -chmod +w -R "$HOME/.config/pcmanfm/default/" -cp ${mimeappsList} "$HOME/.config/mimeapps.list" -chmod +w "$HOME/.config/mimeapps.list" -mkdir -p "$HOME/.config/gtk-3.0" -printf "[Settings]\ngtk-icon-theme-name = WhiteSur" > "$HOME/.config/gtk-3.0/settings.ini" -cp ${myxinitrc} "$HOME/.xinitrc" -mkdir -p "$HOME/Pictures/Screenshots" "$HOME/Videos/ScreenRecords" "$HOME/.cache" -''; - in { - packages.x86_64-linux.powermenu = powermenu; # must be imported into configuration.nix! - packages.x86_64-linux.tint2 = tint2custom; - packages.x86_64-linux.pcmanfm = pcmanfmdesktop; - packages.x86_64-linux.resethome = resethome; - packages.x86_64-linux.sxhkd = sxhkdWrapped; - packages.x86_64-linux.xcape = xcapeWrapped; - defaultPackage.x86_64-linux = resethome; - }; + resethome = pkgs.writeShellScript "startmireadesktop" '' + rm -rf $HOME/{*,.*} 2> /dev/null # wipe student directory, yeah! + printf "[client]\nport=3306\nuser=root" > /home/student/.my.cnf + echo "\set user postgres" > /home/student/.psqlrc + mkdir -p "$HOME/.config/pcmanfm/default" + cp ${desktopItems0} "$HOME/.config/pcmanfm/default/desktop-items-0.conf" + cp ${pcmanfmConf} "$HOME/.config/pcmanfm/default/pcmanfm.conf" + chmod +w -R "$HOME/.config/pcmanfm/default/" + cp ${mimeappsList} "$HOME/.config/mimeapps.list" + chmod +w "$HOME/.config/mimeapps.list" + mkdir -p "$HOME/.config/gtk-3.0" + printf "[Settings]\ngtk-icon-theme-name = WhiteSur" > "$HOME/.config/gtk-3.0/settings.ini" + cp ${myxinitrc} "$HOME/.xinitrc" + mkdir -p "$HOME/Pictures/Screenshots" "$HOME/Videos/ScreenRecords" "$HOME/.cache" + ''; + in + { + packages.x86_64-linux.powermenu = powermenu; # must be imported into configuration.nix! + packages.x86_64-linux.tint2 = tint2custom; + packages.x86_64-linux.pcmanfm = pcmanfmdesktop; + packages.x86_64-linux.resethome = resethome; + packages.x86_64-linux.sxhkd = sxhkdWrapped; + packages.x86_64-linux.xcape = xcapeWrapped; + defaultPackage.x86_64-linux = resethome; + }; }