From b2c95fb68f58e14136134bb42b982caf70addb23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 1 Apr 2025 15:49:15 +0200 Subject: [PATCH 1/3] make devshell usuable on macOS --- flake.nix | 1 + package.nix | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index bcaeb16..dc18b01 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,7 @@ "i686-linux" "aarch64-linux" "riscv64-linux" + "aarch64-darwin" ]; forAllSystems = lib.genAttrs supportedSystems; diff --git a/package.nix b/package.nix index 764d655..5e148ab 100644 --- a/package.nix +++ b/package.nix @@ -8,6 +8,7 @@ nixos-install-tools, binlore, diskoVersion, + stdenv, }: let @@ -21,11 +22,19 @@ let mkdir -p $out/bin $out/share/disko cp -r install-cli.nix cli.nix default.nix disk-deactivate lib $out/share/disko - for i in disko disko-install; do - sed -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" "$i" > "$out/bin/$i" - chmod 755 "$out/bin/$i" - wrapProgram "$out/bin/$i" \ + wrapProgram "$out/bin/disko" \ + --set DISKO_VERSION "${diskoVersion}" \ + --prefix NIX_PATH : "nixpkgs=${path}" + --prefix PATH : ${ + lib.makeBinPath [ + nix + coreutils + ] + } + ${lib.optionalString (!stdenv.isDarwin) '' + wrapProgram "$out/bin/disko" \ --set DISKO_VERSION "${diskoVersion}" \ + --prefix NIX_PATH : "nixpkgs=${path}" \ --prefix PATH : ${ lib.makeBinPath [ nix @@ -33,7 +42,11 @@ let nixos-install-tools ] } \ - --prefix NIX_PATH : "nixpkgs=${path}" + ''} + + for i in $out/bin/; do + sed -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" "$i" > "$out/bin/$i" + chmod 755 "$out/bin/$i" done ''; # Otherwise resholve thinks that disko and disko-install might be able to execute their arguments @@ -46,7 +59,7 @@ let homepage = "https://github.com/nix-community/disko"; license = licenses.mit; maintainers = with maintainers; [ lassulus ]; - platforms = platforms.linux; + platforms = platforms.unix; mainProgram = finalAttrs.name; }; }); From 212ff71553a64485899f82c86034ace0ca388cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 1 Apr 2025 16:04:42 +0200 Subject: [PATCH 2/3] allow to build cli this is useful for format scripts. A remote builder is still necessary --- package.nix | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/package.nix b/package.nix index 5e148ab..8f5a0d1 100644 --- a/package.nix +++ b/package.nix @@ -21,32 +21,28 @@ let installPhase = '' mkdir -p $out/bin $out/share/disko cp -r install-cli.nix cli.nix default.nix disk-deactivate lib $out/share/disko + set -x - wrapProgram "$out/bin/disko" \ - --set DISKO_VERSION "${diskoVersion}" \ - --prefix NIX_PATH : "nixpkgs=${path}" - --prefix PATH : ${ - lib.makeBinPath [ - nix - coreutils - ] - } + scripts=(disko) ${lib.optionalString (!stdenv.isDarwin) '' - wrapProgram "$out/bin/disko" \ + scripts+=(disko-install) + ''} + + for i in "''${scripts[@]}"; do + sed -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" "$i" > "$out/bin/$i" + chmod 755 "$out/bin/$i" + wrapProgram "$out/bin/$i" \ --set DISKO_VERSION "${diskoVersion}" \ --prefix NIX_PATH : "nixpkgs=${path}" \ --prefix PATH : ${ - lib.makeBinPath [ - nix - coreutils - nixos-install-tools - ] - } \ - ''} - - for i in $out/bin/; do - sed -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" "$i" > "$out/bin/$i" - chmod 755 "$out/bin/$i" + lib.makeBinPath ( + [ + nix + coreutils + ] + ++ lib.optional (!stdenv.isDarwin) nixos-install-tools + ) + } done ''; # Otherwise resholve thinks that disko and disko-install might be able to execute their arguments From b36e87600d858f34b8cb90932e87dc61ef0aa28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 1 Apr 2025 16:22:34 +0200 Subject: [PATCH 3/3] zfs: properly disable zfs-based swap --- disk-deactivate/disk-deactivate | 2 ++ disk-deactivate/zfs-swap-deactivate.jq | 10 ++++++++++ flake.nix | 1 + 3 files changed, 13 insertions(+) create mode 100644 disk-deactivate/zfs-swap-deactivate.jq diff --git a/disk-deactivate/disk-deactivate b/disk-deactivate/disk-deactivate index 9ddb2de..f7c678d 100755 --- a/disk-deactivate/disk-deactivate +++ b/disk-deactivate/disk-deactivate @@ -4,5 +4,7 @@ set -efux -o pipefail disk=$(realpath "$1") lsblk -a -f >&2 +# since we currently cannot recursively deactivate swaps on zfs volumes, we need to deactivate all of them. +lsblk --output-all --json | jq -r -f "$(dirname "$0")/zfs-swap-deactivate.jq" | bash -x lsblk --output-all --json | jq -r --arg disk_to_clear "$disk" -f "$(dirname "$0")/disk-deactivate.jq" | bash -x lsblk -a -f >&2 diff --git a/disk-deactivate/zfs-swap-deactivate.jq b/disk-deactivate/zfs-swap-deactivate.jq new file mode 100644 index 0000000..0a8ec87 --- /dev/null +++ b/disk-deactivate/zfs-swap-deactivate.jq @@ -0,0 +1,10 @@ +def turnOffSwaps: + if (.name | test("^zd[0-9]+$")) and .type == "disk" then + "swapoff /dev/" + .name + else + [] + end +; + +.blockdevices | map(turnOffSwaps) | flatten | join("\n") + diff --git a/flake.nix b/flake.nix index dc18b01..cc2ee86 100644 --- a/flake.nix +++ b/flake.nix @@ -71,6 +71,7 @@ checkJqSyntax = pkgs.runCommand "check-jq-syntax" { nativeBuildInputs = [ pkgs.jq ]; } '' echo '{ "blockdevices" : [] }' | jq -r -f ${./disk-deactivate/disk-deactivate.jq} --arg disk_to_clear foo + echo '{ "blockdevices" : [] }' | jq -r -f ${./disk-deactivate/zfs-swap-deactivate.jq} touch $out '';