sane-scripts: include the python scripts

This commit is contained in:
Colin 2023-03-22 21:21:00 +00:00
parent adf72fc9d4
commit 2a148c1543
6 changed files with 152 additions and 108 deletions

View File

@ -3,6 +3,7 @@
let
sane = rec {
#### my own, non-upstreamable packages:
static-nix-shell = callPackages ../pkgs/static-nix-shell { };
sane-scripts = callPackage ../pkgs/sane-scripts { };
feeds = recurseIntoAttrs (callPackage ../pkgs/feeds { });
tow-boot-pinephone = callPackage ../pkgs/tow-boot-pinephone { };

View File

@ -1,7 +1,7 @@
{ lib
, callPackage
, python3
, stdenv
, static-nix-shell
, writeShellScript
}:
@ -21,21 +21,11 @@ let
feed-pkgs;
in rec { # TODO: make this a scope
inherit feed-pkgs;
update = stdenv.mkDerivation {
update = static-nix-shell.mkPython3Bin {
pname = "update";
version = "0.1.0";
src = ./.;
patchPhase =
let
pyEnv = python3.withPackages (ps: [ ps.feedsearch-crawler ]);
in ''
substituteInPlace ./update.py \
--replace "#!/usr/bin/env nix-shell" "#!${pyEnv.interpreter}"
'';
installPhase = ''
mkdir -p $out/bin
mv update.py $out/bin/update.py
'';
pyPkgs = [ "feedsearch-crawler" ];
srcPath = "update.py";
};
init-feed = writeShellScript
"init-feed"

View File

@ -1,12 +1,15 @@
{ lib
, pkgs
, resholve
, static-nix-shell
, symlinkJoin
}:
# resholve documentation:
# - nix: https://github.com/nixos/nixpkgs/blob/master/pkgs/development/misc/resholve/README.md
# - generic: https://github.com/abathur/resholve
resholve.mkDerivation {
let
shell-scripts = resholve.mkDerivation {
# resholve documentation:
# - nix: https://github.com/nixos/nixpkgs/blob/master/pkgs/development/misc/resholve/README.md
# - generic: https://github.com/abathur/resholve
pname = "sane-scripts";
version = "0.1.0";
@ -91,8 +94,7 @@ resholve.mkDerivation {
};
patchPhase = ''
# remove python scripts
# TODO: figure out how to make resholve process only shell scripts
# remove python scripts (we package them further below)
rm sane-bt-search
rm sane-date-math
rm sane-reclaim-boot-space
@ -102,7 +104,26 @@ resholve.mkDerivation {
mkdir -p $out/bin
cp -R * $out/bin/
'';
};
bt-search = static-nix-shell.mkPython3Bin {
pname = "sane-bt-search";
src = ./src;
pyPkgs = [ "natsort" "requests" ];
};
date-math = static-nix-shell.mkPython3Bin {
pname = "sane-date-math";
src = ./src;
};
reclaim-boot-space = static-nix-shell.mkPython3Bin {
pname = "sane-reclaim-boot-space";
src = ./src;
};
in
symlinkJoin {
name = "sane-scripts";
paths = [ shell-scripts bt-search date-math reclaim-boot-space ];
meta = {
description = "collection of scripts associated with uninsane systems";
homepage = "https://git.uninsane.org";

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p "python3.withPackages (ps: [ ])"
# i just went overboard playing around with parsers, is all.
# use this like `./sane-date-math 'today - 5d'`

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p "python3.withPackages (ps: [ ])"
import os
import os.path

View File

@ -0,0 +1,30 @@
{ stdenv
, python3
}:
{
# transform a file which uses `#!/usr/bin/env nix-shell` shebang with a `python3` interpreter
# into a derivation that can be built statically
mkPython3Bin = { pname, pyPkgs ? [], srcPath ? pname, ... }@attrs: stdenv.mkDerivation (
let
evalPyPkgs = ps: builtins.map (name: ps."${name}") pyPkgs;
pyEnv = python3.withPackages evalPyPkgs;
pyPkgsStr = builtins.concatStringsSep " " (builtins.map (p: "ps.${p}") pyPkgs);
in {
version = "0.1.0"; # default version
patchPhase = ''
substituteInPlace ${srcPath} \
--replace '#!/usr/bin/env nix-shell' '#!${pyEnv.interpreter}' \
--replace \
'#!nix-shell -i python3 -p "python3.withPackages (ps: [ ${pyPkgsStr} ])"' \
'# nix deps evaluated statically'
'';
installPhase = ''
mkdir -p $out/bin
mv ${srcPath} $out/bin/${srcPath}
# ensure that all nix-shell references were substituted
! grep nix-shell $out/bin/${srcPath}
'';
} // attrs
);
}