sane-scripts: add sane-bt-rm to remove torrents
also rework statix-nix-shell to support bash
This commit is contained in:
parent
efd45c58f1
commit
0270ccdebd
|
@ -108,11 +108,17 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
py-scripts = {
|
py-scripts = {
|
||||||
|
# anything added to this attrset gets symlink-joined into into `sane-scripts`
|
||||||
bt-search = static-nix-shell.mkPython3Bin {
|
bt-search = static-nix-shell.mkPython3Bin {
|
||||||
pname = "sane-bt-search";
|
pname = "sane-bt-search";
|
||||||
src = ./src;
|
src = ./src;
|
||||||
pyPkgs = [ "natsort" "requests" ];
|
pyPkgs = [ "natsort" "requests" ];
|
||||||
};
|
};
|
||||||
|
bt-rm = static-nix-shell.mkBash {
|
||||||
|
pname = "sane-bt-rm";
|
||||||
|
src = ./src;
|
||||||
|
pkgs = [ "transmission" ];
|
||||||
|
};
|
||||||
date-math = static-nix-shell.mkPython3Bin {
|
date-math = static-nix-shell.mkPython3Bin {
|
||||||
pname = "sane-date-math";
|
pname = "sane-date-math";
|
||||||
src = ./src;
|
src = ./src;
|
||||||
|
|
11
pkgs/additional/sane-scripts/src/sane-bt-rm
Executable file
11
pkgs/additional/sane-scripts/src/sane-bt-rm
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env nix-shell
|
||||||
|
#!nix-shell -i bash -p transmission
|
||||||
|
|
||||||
|
# removes a torrent and trashes its data
|
||||||
|
# usage: sane-bt-rm <torrent>
|
||||||
|
# where <torrent> is a magnet URL, or an identifier from sane-bt-show (e.g. 132)
|
||||||
|
|
||||||
|
endpoint=https://bt.uninsane.org/transmission/rpc
|
||||||
|
PASS=$(sudo cat /run/secrets/transmission_passwd)
|
||||||
|
|
||||||
|
transmission-remote "$endpoint" --auth "colin:$PASS" --torrent "$1" --remove-and-delete
|
|
@ -9,7 +9,49 @@ let
|
||||||
inherit (builtins) attrNames attrValues concatStringsSep foldl' map typeOf;
|
inherit (builtins) attrNames attrValues concatStringsSep foldl' map typeOf;
|
||||||
inherit (lib) concatMapAttrs;
|
inherit (lib) concatMapAttrs;
|
||||||
pkgs' = pkgs;
|
pkgs' = pkgs;
|
||||||
|
# create an attrset of
|
||||||
|
# <name> = expected string in the nix-shell invocation
|
||||||
|
# <value> = package to provide
|
||||||
|
pkgsToAttrs = prefix: pkgSet: expr: ({
|
||||||
|
"lambda" = expr: pkgsToAttrs prefix pkgSet (expr pkgSet);
|
||||||
|
"list" = expr: foldl' (acc: pname: acc // {
|
||||||
|
"${prefix + pname}" = pkgSet."${pname}";
|
||||||
|
}) {} expr;
|
||||||
|
"set" = expr: expr;
|
||||||
|
})."${typeOf expr}" expr;
|
||||||
in {
|
in {
|
||||||
|
mkBash = { pname, pkgs ? {}, srcPath ? pname, ...}@attrs:
|
||||||
|
let
|
||||||
|
pkgsAsAttrs = pkgsToAttrs "" pkgs' pkgs;
|
||||||
|
pkgsEnv = attrValues pkgsAsAttrs;
|
||||||
|
pkgsStr = concatStringsSep "" (map
|
||||||
|
(pname: " -p ${pname}")
|
||||||
|
(attrNames pkgsAsAttrs)
|
||||||
|
);
|
||||||
|
in stdenv.mkDerivation ({
|
||||||
|
version = "0.1.0"; # default version
|
||||||
|
patchPhase = ''
|
||||||
|
substituteInPlace ${srcPath} \
|
||||||
|
--replace '#!/usr/bin/env nix-shell' '#!${pkgs'.bash}/bin/bash' \
|
||||||
|
--replace \
|
||||||
|
'#!nix-shell -i bash -p ${pkgsStr}' \
|
||||||
|
'# nix deps evaluated statically'
|
||||||
|
'';
|
||||||
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
mv ${srcPath} $out/bin/${srcPath}
|
||||||
|
|
||||||
|
# ensure that all nix-shell references were substituted
|
||||||
|
! grep nix-shell $out/bin/${srcPath}
|
||||||
|
|
||||||
|
# add runtime dependencies to PATH
|
||||||
|
wrapProgram $out/bin/${srcPath} \
|
||||||
|
--suffix PATH : ${lib.makeBinPath pkgsEnv }
|
||||||
|
'';
|
||||||
|
} // (removeAttrs attrs [ "pkgs" "pyPkgs" "srcPath" ])
|
||||||
|
);
|
||||||
|
|
||||||
# transform a file which uses `#!/usr/bin/env nix-shell` shebang with a `python3` interpreter
|
# transform a file which uses `#!/usr/bin/env nix-shell` shebang with a `python3` interpreter
|
||||||
# into a derivation that can be built statically.
|
# into a derivation that can be built statically.
|
||||||
#
|
#
|
||||||
|
@ -21,16 +63,6 @@ in {
|
||||||
# for pyPkgs, names are assumed to be relative to `"ps"` if specified in list form.
|
# for pyPkgs, names are assumed to be relative to `"ps"` if specified in list form.
|
||||||
mkPython3Bin = { pname, pkgs ? {}, pyPkgs ? {}, srcPath ? pname, ... }@attrs:
|
mkPython3Bin = { pname, pkgs ? {}, pyPkgs ? {}, srcPath ? pname, ... }@attrs:
|
||||||
let
|
let
|
||||||
# create an attrset of
|
|
||||||
# <name> = expected string in the nix-shell invocation
|
|
||||||
# <value> = package to provide
|
|
||||||
pkgsToAttrs = prefix: pkgSet: expr: ({
|
|
||||||
"lambda" = expr: pkgsToAttrs prefix pkgSet (expr pkgSet);
|
|
||||||
"list" = expr: foldl' (acc: pname: acc // {
|
|
||||||
"${prefix + pname}" = pkgSet."${pname}";
|
|
||||||
}) {} expr;
|
|
||||||
"set" = expr: expr;
|
|
||||||
})."${typeOf expr}" expr;
|
|
||||||
pyEnv = python3.withPackages (ps: attrValues (
|
pyEnv = python3.withPackages (ps: attrValues (
|
||||||
pkgsToAttrs "ps." ps pyPkgs
|
pkgsToAttrs "ps." ps pyPkgs
|
||||||
));
|
));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user