diff options
author | Franck Cuny <franck@fcuny.net> | 2023-04-30 14:44:45 -0700 |
---|---|---|
committer | Franck Cuny <franck@fcuny.net> | 2023-04-30 14:47:57 -0700 |
commit | ccebd915be9e267b9f445d31c31e5b34a4b2adbf (patch) | |
tree | c492964ebd623479b81487ca8191f05eda62697e /home | |
parent | home/packages: add a wrapper for restic on the nas (diff) | |
download | world-ccebd915be9e267b9f445d31c31e5b34a4b2adbf.tar.gz |
home/packages: rewrite scripts to use writeShellApplication
This function produces a shell script with dependencies, set the PATH, set some SHELLOPTS, and check the script with shellcheck.
Diffstat (limited to '')
-rw-r--r-- | home/beets/default.nix | 24 | ||||
-rw-r--r-- | home/packages/default.nix | 20 |
2 files changed, 25 insertions, 19 deletions
diff --git a/home/beets/default.nix b/home/beets/default.nix index 0d7a3b9..ab8cc43 100644 --- a/home/beets/default.nix +++ b/home/beets/default.nix @@ -1,17 +1,21 @@ { config, lib, pkgs, ... }: let cfg = config.my.home.beets; - bc-to-beet = pkgs.writeShellScriptBin "bc-to-beet" '' - ALBUM_PATH="''${1}" - ALBUM_NAME=$(basename "''${ALBUM_PATH}") + bc-to-beet = pkgs.writeShellApplication { + name = "bc-to-beet"; + runtimeInputs = [ pkgs.beets ]; + text = '' + ALBUM_PATH="''${1}" + ALBUM_NAME=$(basename "''${ALBUM_PATH}") - mkdir -p ~/import - rm -rf ~/import/tmp-bc - unzip -d ~/import/tmp-bc ~/import/album.zip - beet import ~/import/tmp-bc - rm -rf ~/import/tmp-bc - rm -rf ~/import/album.zip - ''; + mkdir -p ~/import + rm -rf ~/import/tmp-bc + unzip -d ~/import/tmp-bc ~/import/album.zip + beet import ~/import/tmp-bc + rm -rf ~/import/tmp-bc + rm -rf ~/import/album.zip + ''; + }; in { options.my.home.beets = with lib; { diff --git a/home/packages/default.nix b/home/packages/default.nix index fbf258f..e6e4a5b 100644 --- a/home/packages/default.nix +++ b/home/packages/default.nix @@ -1,17 +1,19 @@ { config, lib, pkgs, ... }: let cfg = config.my.home.packages; - album-to-nas = pkgs.writeShellScriptBin "album-to-nas" '' - set -euo pipefail + album-to-nas = pkgs.writeShellApplication { + name = "album-to-nas"; + runtimeInputs = [ pkgs.jq pkgs.tailscale ]; + text = '' + ALBUM_PATH="''${1}" + ALBUM_NAME=$(basename "''${ALBUM_PATH}") - ALBUM_PATH="''${1}" - ALBUM_NAME=$(basename "''${ALBUM_PATH}") - NAS=$(${pkgs.tailscale}/bin/tailscale status --json | ${pkgs.jq}/bin/jq -r '.Peer | map(select(.HostName == "tahoe"))[0].TailscaleIPs[0]') - - scp "''${ALBUM_PATH}" "''${NAS}:~/import/album.zip" - ssh "''${NAS}" bc-to-beet ~/import/album.zip - ''; + NAS=$(tailscale status --json | jq -r '.Peer | map(select(.HostName == "tahoe"))[0].TailscaleIPs[0]') + scp "''${ALBUM_PATH}" "''${NAS}:~/import/album.zip" + ssh "''${NAS}" bc-to-beet ~/import/album.zip + ''; + }; restic-nas = pkgs.writeShellApplication { name = "restic-nas"; |