diff --git a/configuration/common/programs.nix b/configuration/common/programs.nix index f9c9d82..87889c9 100644 --- a/configuration/common/programs.nix +++ b/configuration/common/programs.nix @@ -6,6 +6,7 @@ # My system is fucked gptfdisk parted + grow-last-partition-and-filesystem # Normal usage htop diff --git a/pkgs/grow-last-partition-and-filesystem/default.nix b/pkgs/grow-last-partition-and-filesystem/default.nix new file mode 100644 index 0000000..06dac05 --- /dev/null +++ b/pkgs/grow-last-partition-and-filesystem/default.nix @@ -0,0 +1,17 @@ +{ + e2fsprogs, + jq, + parted, + writeShellApplication, +}: + +writeShellApplication { + name = "grow-last-partition-and-filesystem"; + text = builtins.readFile ./grow-last-partition-and-filesystem.sh; + runtimeInputs = [ + e2fsprogs + jq + parted + ]; +} + diff --git a/pkgs/grow-last-partition-and-filesystem/grow-last-partition-and-filesystem.sh b/pkgs/grow-last-partition-and-filesystem/grow-last-partition-and-filesystem.sh new file mode 100755 index 0000000..864b035 --- /dev/null +++ b/pkgs/grow-last-partition-and-filesystem/grow-last-partition-and-filesystem.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if [[ $# -ne 1 ]]; then + echo "Pass device to grow as first argument:" + echo "grow-last-partition-and-filesystem DEVICE" + + exit 1 +fi + +DEVICE="$1" + +PARTITIONDATA="$(parted --script --json --fix "${DEVICE}" print)" +PARTNUMBER="$(echo "${PARTITIONDATA}" | jq -r '.disk.partitions | last | .number')" +PARTNAME="$(echo "${PARTITIONDATA}" | jq -r '.disk.partitions | last | .name')" + +echo "Growing partition ${DEVICE}${PARTNUMBER} (${PARTNAME})" +echo + +parted "${DEVICE}" resizepart "${PARTNUMBER}" 100% + +echo +echo "Resizing filesystem" +echo + +resize2fs "${DEVICE}${PARTNUMBER}" + +echo "Done." diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix index 1d66db8..8fd5cce 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -19,6 +19,7 @@ final: prev: { git-diff-word = final.callPackage ./git-diff-word {}; git-pp = final.callPackage ./git-pp {}; git-show-link = final.callPackage ./git-show-link {}; + grow-last-partition-and-filesystem = final.callPackage ./grow-last-partition-and-filesystem {}; nix-remove-result-links = final.callPackage ./nix-remove-result-links {}; nixfiles-auto-install = final.callPackage ./nixfiles/nixfiles-auto-install.nix {}; nixfiles-generate-config = final.callPackage ./nixfiles/nixfiles-generate-config.nix {};