diff --git a/pkgs/applications/backup/timeshift/default.nix b/pkgs/applications/backup/timeshift/default.nix new file mode 100644 index 000000000000..0a6a9bf38865 --- /dev/null +++ b/pkgs/applications/backup/timeshift/default.nix @@ -0,0 +1,33 @@ +{ callPackage +, timeshift-unwrapped +, lib +, rsync +, coreutils +, mount +, umount +, psmisc +, cron +, btrfs-progs +, grubPackage +}: +let + timeshift-wrapper = callPackage ./wrapper.nix { }; +in +(timeshift-wrapper timeshift-unwrapped ([ + rsync + coreutils + mount + umount + psmisc + cron + btrfs-progs + grubPackage +])).overrideAttrs (oldAttrs: { + meta = oldAttrs.meta // { + description = oldAttrs.meta.description; + longDescription = oldAttrs.meta.longDescription + '' + This package comes with runtime dependencies of command utilities provided by rsync, coreutils, mount, umount, psmisc, cron and (optionally) btrfs. + If you want to use the commands provided by the system, override the propagatedBuildInputs or use timeshift-minimal instead + ''; + }; +}) diff --git a/pkgs/applications/backup/timeshift/minimal.nix b/pkgs/applications/backup/timeshift/minimal.nix new file mode 100644 index 000000000000..96946fa72e05 --- /dev/null +++ b/pkgs/applications/backup/timeshift/minimal.nix @@ -0,0 +1,15 @@ +{ callPackage +, timeshift-unwrapped +}: +let + timeshift-wrapper = callPackage ./wrapper.nix { }; +in +(timeshift-wrapper timeshift-unwrapped [ ]).overrideAttrs (oldAttrs: { + meta = oldAttrs.meta // { + description = oldAttrs.meta.description + " (without runtime dependencies)"; + longDescription = oldAttrs.meta.longDescription + '' + This package is a wrapped version of timeshift-unwrapped + without runtime dependencies of command utilities. + ''; + }; +}) diff --git a/pkgs/applications/backup/timeshift/timeshift-launcher.patch b/pkgs/applications/backup/timeshift/timeshift-launcher.patch new file mode 100644 index 000000000000..765c101e1629 --- /dev/null +++ b/pkgs/applications/backup/timeshift/timeshift-launcher.patch @@ -0,0 +1,26 @@ +diff --git a/src/timeshift-launcher b/src/timeshift-launcher +index 29b8fc4..5f6cb17 100755 +--- a/src/timeshift-launcher ++++ b/src/timeshift-launcher +@@ -1,6 +1,6 @@ + #!/bin/bash + +-app_command='timeshift-gtk' ++app_command=''"$(realpath "$(dirname "$0")")"'/timeshift-gtk' + + if [ "$(id -u)" -eq 0 ]; then + # user is admin +@@ -14,11 +14,11 @@ else + # script is running in non-interactive mode + if [ "$XDG_SESSION_TYPE" = "wayland" ] ; then + xhost +SI:localuser:root +- pkexec ${app_command} ++ pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" "${app_command}" + xhost -SI:localuser:root + xhost + elif command -v pkexec >/dev/null 2>&1; then +- pkexec ${app_command} ++ pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" "${app_command}" + elif command -v sudo >/dev/null 2>&1; then + x-terminal-emulator -e "sudo ${app_command}" + elif command -v su >/dev/null 2>&1; then diff --git a/pkgs/applications/backup/timeshift/unwrapped.nix b/pkgs/applications/backup/timeshift/unwrapped.nix new file mode 100644 index 000000000000..1f34491dafdc --- /dev/null +++ b/pkgs/applications/backup/timeshift/unwrapped.nix @@ -0,0 +1,77 @@ +{ lib +, stdenv +, fetchFromGitHub +, gettext +, pkg-config +, vala +, which +, gtk3 +, json-glib +, libgee +, utillinux +, vte +, xapps +}: + +stdenv.mkDerivation rec { + pname = "timeshift"; + version = "22.06.1"; + + src = fetchFromGitHub { + owner = "linuxmint"; + repo = "timeshift"; + rev = "v${version}"; + sha256 = "XcxwVBKMv2YwbrI3FFWDQFs8hHruhkZq3YqzkptE6KE="; + }; + + patches = [ + ./timeshift-launcher.patch + ]; + + postPatch = '' + while IFS="" read -r -d $'\0' FILE; do + substituteInPlace "$FILE" \ + --replace "/sbin/blkid" "${utillinux}/bin/blkid" + done < <(find ./src -mindepth 1 -name "*.vala" -type f -print0) + substituteInPlace ./src/Utility/IconManager.vala \ + --replace "/usr/share" "$out/share" + substituteInPlace ./src/Core/Main.vala \ + --replace "/etc/timeshift/default.json" "$out/etc/timeshift/default.json" \ + --replace "file_copy(app_conf_path_default, app_conf_path);" "if (!dir_exists(file_parent(app_conf_path))){dir_create(file_parent(app_conf_path));};file_copy(app_conf_path_default, app_conf_path);" + ''; + + nativeBuildInputs = [ + gettext + pkg-config + vala + which + ]; + + buildInputs = [ + gtk3 + json-glib + libgee + vte + xapps + ]; + + preBuild = '' + makeFlagsArray+=( \ + "-C" "src" \ + "prefix=$out" \ + "sysconfdir=$out/etc" \ + ) + ''; + + meta = with lib; { + description = "A system restore tool for Linux"; + longDescription = '' + TimeShift creates filesystem snapshots using rsync+hardlinks or BTRFS snapshots. + Snapshots can be restored using TimeShift installed on the system or from Live CD or USB. + ''; + homepage = "https://github.com/linuxmint/timeshift"; + license = licenses.gpl3; + platforms = platforms.linux; + maintainers = with maintainers; [ ShamrockLee ]; + }; +} diff --git a/pkgs/applications/backup/timeshift/wrapper.nix b/pkgs/applications/backup/timeshift/wrapper.nix new file mode 100644 index 000000000000..e72052fda1ba --- /dev/null +++ b/pkgs/applications/backup/timeshift/wrapper.nix @@ -0,0 +1,45 @@ +{ stdenvNoCC +, lib +, wrapGAppsHook +, gdk-pixbuf +, librsvg +, xorg +, shared-mime-info +}: + +timeshift-unwrapped: +runtimeDeps: +stdenvNoCC.mkDerivation { + inherit (timeshift-unwrapped) pname version; + + dontUnpack = true; + + nativeBuildInputs = [ + xorg.lndir + wrapGAppsHook + ]; + + installPhase = '' + runHook preInstall + mkdir -p "$out" + lndir "${timeshift-unwrapped}" "$out" + runHook postInstall + ''; + + dontWrapGApps = true; + + preFixup = '' + makeWrapperArgs=( + --prefix PATH : "${lib.makeBinPath runtimeDeps}" + ) + gappsWrapperArgs+=( + # Thumbnailers + --prefix XDG_DATA_DIRS : "${lib.makeSearchPath "share" [ gdk-pixbuf librsvg shared-mime-info ]}" + "''${makeWrapperArgs[@]}" + ) + wrapProgram "$out/bin/timeshift" "''${makeWrapperArgs[@]}" + wrapProgram "$out/bin/timeshift-gtk" "''${gappsWrapperArgs[@]}" + ''; + + inherit (timeshift-unwrapped) meta; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index a4f5f49ca2a7..9f5fb3af6eda 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -30024,6 +30024,12 @@ with pkgs; timelimit = callPackage ../tools/misc/timelimit { }; + timeshift-unwrapped = callPackage ../applications/backup/timeshift/unwrapped.nix { inherit (cinnamon) xapps; }; + + timeshift = callPackage ../applications/backup/timeshift { grubPackage = grub2_full; }; + + timeshift-minimal = callPackage ../applications/backup/timeshift/minimal.nix { }; + timewarrior = callPackage ../applications/misc/timewarrior { }; timew-sync-server = callPackage ../applications/misc/timew-sync-server { };