From 9907a2d48bf10c8ab39fb5ad165d0522e837b109 Mon Sep 17 00:00:00 2001 From: Tim Steinbach Date: Wed, 4 Nov 2020 18:12:23 -0500 Subject: [PATCH 1/2] oh-my-zsh: Update script --- pkgs/shells/zsh/oh-my-zsh/default.nix | 39 +++++++++++++++++++++++++-- pkgs/shells/zsh/oh-my-zsh/update.sh | 19 ------------- 2 files changed, 37 insertions(+), 21 deletions(-) delete mode 100755 pkgs/shells/zsh/oh-my-zsh/update.sh diff --git a/pkgs/shells/zsh/oh-my-zsh/default.nix b/pkgs/shells/zsh/oh-my-zsh/default.nix index e7433e2de0b8..f4388f6d8614 100644 --- a/pkgs/shells/zsh/oh-my-zsh/default.nix +++ b/pkgs/shells/zsh/oh-my-zsh/default.nix @@ -1,7 +1,8 @@ # This script was inspired by the ArchLinux User Repository package: # # https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=oh-my-zsh-git -{ stdenv, fetchFromGitHub }: +{ stdenv, fetchFromGitHub, nixosTests, writeScript, common-updater-scripts, git +, nix, nixfmt, jq, coreutils, gnused, curl, cacert }: stdenv.mkDerivation rec { version = "2020-10-29"; @@ -12,7 +13,7 @@ stdenv.mkDerivation rec { inherit rev; owner = "ohmyzsh"; repo = "ohmyzsh"; - sha256 = "0021rayw5wiwgjfwy7d6g577xidws58vk7y9xxhidnmk9sr4vri7"; + sha256 = "J+ZNsk6z2hZh78mfuVHRvMV+TnmmHc+dfDzywr3KQQA="; }; installPhase = '' @@ -65,6 +66,40 @@ stdenv.mkDerivation rec { EOF ''; + passthru = { + updateScript = writeScript "update.sh" '' + #!${stdenv.shell} + set -o errexit + PATH=${ + stdenv.lib.makeBinPath [ + common-updater-scripts + curl + cacert + git + nixfmt + nix + jq + coreutils + gnused + ] + } + + oldVersion="$(nix-instantiate --eval -E "with import ./. {}; lib.getVersion oh-my-zsh" | tr -d '"')" + latestSha="$(curl -L -s https://api.github.com/repos/ohmyzsh/ohmyzsh/commits\?sha\=master\&since\=$oldVersion | jq -r '.[0].sha')" + + if [ ! "null" = "$latestSha" ]; then + nixpkgs="$(git rev-parse --show-toplevel)" + default_nix="$nixpkgs/pkgs/shells/zsh/oh-my-zsh/default.nix" + latestDate="$(curl -L -s https://api.github.com/repos/ohmyzsh/ohmyzsh/commits/$latestSha | jq '.commit.author.date' | sed 's|"\(.*\)T.*|\1|g')" + update-source-version oh-my-zsh "$latestSha" --version-key=rev + update-source-version oh-my-zsh "$latestDate" --ignore-same-hash + nixfmt "$default_nix" + else + echo "${pname} is already up-to-date" + fi + ''; + }; + meta = with stdenv.lib; { description = "A framework for managing your zsh configuration"; longDescription = '' diff --git a/pkgs/shells/zsh/oh-my-zsh/update.sh b/pkgs/shells/zsh/oh-my-zsh/update.sh deleted file mode 100755 index 738c0810737a..000000000000 --- a/pkgs/shells/zsh/oh-my-zsh/update.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i bash -p curl common-updater-scripts jq - -set -eu -o pipefail - -oldVersion="$(nix-instantiate --eval -E "with import ./. {}; lib.getVersion oh-my-zsh" | tr -d '"')" -latestSha="$(curl -L -s https://api.github.com/repos/ohmyzsh/ohmyzsh/commits\?sha\=master\&since\=${oldVersion} | jq -r '.[0].sha')" - -if [ ! "null" = "${latestSha}" ]; then - latestDate="$(curl -L -s https://api.github.com/repos/ohmyzsh/ohmyzsh/commits/${latestSha} | jq '.commit.author.date' | sed 's|"\(.*\)T.*|\1|g')" - update-source-version oh-my-zsh "${latestSha}" --version-key=rev - update-source-version oh-my-zsh "${latestDate}" --ignore-same-hash - nixpkgs="$(git rev-parse --show-toplevel)" - default_nix="$nixpkgs/pkgs/shells/zsh/oh-my-zsh/default.nix" - git add "${default_nix}" - git commit -m "oh-my-zsh: ${oldVersion} -> ${latestDate}" -else - echo "oh-my-zsh is already up-to-date" -fi From 9813539969d6071ed1a162a1d45d7521b2980c2a Mon Sep 17 00:00:00 2001 From: Tim Steinbach Date: Wed, 4 Nov 2020 20:37:50 -0500 Subject: [PATCH 2/2] oh-my-zsh: Add test --- nixos/tests/all-tests.nix | 1 + nixos/tests/oh-my-zsh.nix | 18 ++++++++++++++++++ pkgs/shells/zsh/oh-my-zsh/default.nix | 2 ++ 3 files changed, 21 insertions(+) create mode 100644 nixos/tests/oh-my-zsh.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 76b2af9d578c..e2e9a15fc324 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -254,6 +254,7 @@ in novacomd = handleTestOn ["x86_64-linux"] ./novacomd.nix {}; nsd = handleTest ./nsd.nix {}; nzbget = handleTest ./nzbget.nix {}; + oh-my-zsh = handleTest ./oh-my-zsh.nix {}; openarena = handleTest ./openarena.nix {}; openldap = handleTest ./openldap.nix {}; opensmtpd = handleTest ./opensmtpd.nix {}; diff --git a/nixos/tests/oh-my-zsh.nix b/nixos/tests/oh-my-zsh.nix new file mode 100644 index 000000000000..57a073b086e8 --- /dev/null +++ b/nixos/tests/oh-my-zsh.nix @@ -0,0 +1,18 @@ +import ./make-test-python.nix ({ pkgs, ... }: { + name = "oh-my-zsh"; + + machine = { pkgs, ... }: + + { + programs.zsh = { + enable = true; + ohMyZsh.enable = true; + }; + }; + + testScript = '' + start_all() + machine.succeed("touch ~/.zshrc") + machine.succeed("zsh -c 'source /etc/zshrc && echo $ZSH | grep oh-my-zsh-${pkgs.oh-my-zsh.version}'") + ''; +}) diff --git a/pkgs/shells/zsh/oh-my-zsh/default.nix b/pkgs/shells/zsh/oh-my-zsh/default.nix index f4388f6d8614..3660453245bb 100644 --- a/pkgs/shells/zsh/oh-my-zsh/default.nix +++ b/pkgs/shells/zsh/oh-my-zsh/default.nix @@ -67,6 +67,8 @@ stdenv.mkDerivation rec { ''; passthru = { + tests = { inherit (nixosTests) oh-my-zsh; }; + updateScript = writeScript "update.sh" '' #!${stdenv.shell} set -o errexit