Xonsh glow-ups
Move xonsh header/footer to separate files Add gregpy as the default Python version used in xonsh Add Nix profile to PATH in xonsh ahead of tmux path mangling to allow python3 with modules to be discovered
This commit is contained in:
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
name: { pkgs, lib, gui, ...}:
|
name: { pkgs, lib, gui, config, ...}:
|
||||||
|
|
||||||
let
|
let
|
||||||
guiImports = if gui then
|
guiImports = if gui then
|
||||||
@@ -21,11 +21,11 @@ in {
|
|||||||
programs.tmux = {
|
programs.tmux = {
|
||||||
enable = true;
|
enable = true;
|
||||||
keyMode = "vi";
|
keyMode = "vi";
|
||||||
shell = "${pkgs.xonsh}/bin/xonsh";
|
shell = "~/.nix-profile/bin/xonsh";
|
||||||
terminal = "xterm-256color";
|
terminal = "xterm-256color";
|
||||||
customPaneNavigationAndResize = true;
|
customPaneNavigationAndResize = true;
|
||||||
extraConfig = (lib.strings.concatStringsSep "\n" [
|
extraConfig = (lib.strings.concatStringsSep "\n" [
|
||||||
"set-option -g default-command ${pkgs.xonsh}/bin/xonsh"
|
"set-option -g default-command ~/.nix-profile/bin/xonsh"
|
||||||
"bind P paste-buffer"
|
"bind P paste-buffer"
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-93
@@ -58,98 +58,7 @@
|
|||||||
vssh = "vagrant ssh";
|
vssh = "vagrant ssh";
|
||||||
};
|
};
|
||||||
|
|
||||||
configHeader = ''
|
configHeader = builtins.readFile ./xonsh_header.xsh;
|
||||||
if '__NIX_DARWIN_SET_ENVIRONMENT_DONE' not in ''${...} or not $__NIX_DARWIN_SET_ENVIRONMENT_DONE:
|
configFooter = builtins.readFile ./xonsh_footer.xsh;
|
||||||
source-bash /etc/bashrc
|
|
||||||
|
|
||||||
# set -e == $RAISE_SUBPROC_ERROR = True
|
|
||||||
# set -x == trace on; $XONSH_TRACE_SUBPROC = True
|
|
||||||
# $? == _.rtn
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
xontrib load direnv
|
|
||||||
|
|
||||||
$PATH.append("${config.home.homeDirectory}/src/bin")
|
|
||||||
'';
|
|
||||||
|
|
||||||
#$PKG_CONFIG_PATH = '/usr/local/lib/pkgconfig'
|
|
||||||
#$JAVA_HOME = '/etc/alternatives/java_sdk'
|
|
||||||
configFooter = ''
|
|
||||||
def _rebuild(args):
|
|
||||||
import os
|
|
||||||
system = os.uname()
|
|
||||||
if system.sysname == 'Darwin':
|
|
||||||
darwin-rebuild --flake ~/.config/nix switch
|
|
||||||
else:
|
|
||||||
sudo nixos-rebuild switch
|
|
||||||
|
|
||||||
def _yaml2json(args, stdin=None, stdout=None):
|
|
||||||
import sys, yaml, json
|
|
||||||
from yaml import CLoader
|
|
||||||
json.dump(yaml.load(stdin, Loader=CLoader), stdout, indent=4)
|
|
||||||
|
|
||||||
def _py2env(args):
|
|
||||||
vox new @(args[0]) -p /usr/bin/python2
|
|
||||||
|
|
||||||
def _py3env(args):
|
|
||||||
vox new @(args[0])
|
|
||||||
|
|
||||||
def _rundock(args):
|
|
||||||
if os.path.exists('/usr/bin/podman'):
|
|
||||||
e = 'podman'
|
|
||||||
else:
|
|
||||||
e = 'docker'
|
|
||||||
@(e) exec -ti @(args[0]) /bin/bash
|
|
||||||
|
|
||||||
def _pip_extras(args):
|
|
||||||
import importlib_metadata
|
|
||||||
print(importlib_metadata.metadata(args[0]).get_all('Provides-Extra'))
|
|
||||||
|
|
||||||
# Container stuff
|
|
||||||
def _newdock(args):
|
|
||||||
if os.path.exists('/usr/bin/podman'):
|
|
||||||
e = 'podman'
|
|
||||||
else:
|
|
||||||
e = 'docker'
|
|
||||||
@(e) run -P --privileged=true -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v @(os.getcwd()):/dmnt -v /etc/pki:/etc/pki:ro -d --name @(args[1]) @(args[0]) /sbin/init
|
|
||||||
rundock @(args[1])
|
|
||||||
|
|
||||||
def _unknown_host(args):
|
|
||||||
sed -i -e @(args[0])d ~/.ssh/known_hosts
|
|
||||||
|
|
||||||
def _bake(args):
|
|
||||||
from pathlib import Path
|
|
||||||
templates = Path("~/.copier-templates/").expanduser()
|
|
||||||
if not templates.exists():
|
|
||||||
git clone src:greg/copier-templates.git ~/.copier-templates
|
|
||||||
copier copy @(str(templates / args[0])) .
|
|
||||||
|
|
||||||
aliases['bake'] = _bake
|
|
||||||
aliases['rebuild'] = _rebuild
|
|
||||||
aliases['yaml2json'] = _yaml2json
|
|
||||||
aliases['py2env'] = _py2env
|
|
||||||
aliases['py3env'] = _py3env
|
|
||||||
aliases['rundock'] = _rundock
|
|
||||||
aliases['newdock'] = _newdock
|
|
||||||
aliases['unknown_host'] = _unknown_host
|
|
||||||
aliases['pip_extras'] = _pip_extras
|
|
||||||
###
|
|
||||||
#
|
|
||||||
# Other random nice-to-have things
|
|
||||||
#
|
|
||||||
###
|
|
||||||
|
|
||||||
# Does virtualenv support
|
|
||||||
xontrib load vox
|
|
||||||
# Faster coreutils
|
|
||||||
xontrib load coreutils
|
|
||||||
|
|
||||||
# Allows identifying JSON as if it was Python by adding some new builtins to the language
|
|
||||||
import builtins
|
|
||||||
builtins.true = True
|
|
||||||
builtins.false = False
|
|
||||||
builtins.null = None
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
# vim: set ft=python :
|
||||||
|
|
||||||
|
#$PKG_CONFIG_PATH = '/usr/local/lib/pkgconfig'
|
||||||
|
#$JAVA_HOME = '/etc/alternatives/java_sdk'
|
||||||
|
def _rebuild(args):
|
||||||
|
import os
|
||||||
|
system = os.uname()
|
||||||
|
if system.sysname == 'Darwin':
|
||||||
|
darwin-rebuild --flake ~/.config/nix switch
|
||||||
|
else:
|
||||||
|
sudo nixos-rebuild switch
|
||||||
|
|
||||||
|
def _yaml2json(args, stdin=None, stdout=None):
|
||||||
|
import sys, yaml, json
|
||||||
|
from yaml import CLoader
|
||||||
|
json.dump(yaml.load(stdin, Loader=CLoader), stdout, indent=4)
|
||||||
|
|
||||||
|
def _py2env(args):
|
||||||
|
vox new @(args[0]) -p /usr/bin/python2
|
||||||
|
|
||||||
|
def _py3env(args):
|
||||||
|
vox new @(args[0])
|
||||||
|
|
||||||
|
def _rundock(args):
|
||||||
|
if os.path.exists('/usr/bin/podman'):
|
||||||
|
e = 'podman'
|
||||||
|
else:
|
||||||
|
e = 'docker'
|
||||||
|
@(e) exec -ti @(args[0]) /bin/bash
|
||||||
|
|
||||||
|
def _pip_extras(args):
|
||||||
|
import importlib_metadata
|
||||||
|
print(importlib_metadata.metadata(args[0]).get_all('Provides-Extra'))
|
||||||
|
|
||||||
|
# Container stuff
|
||||||
|
def _newdock(args):
|
||||||
|
if os.path.exists('/usr/bin/podman'):
|
||||||
|
e = 'podman'
|
||||||
|
else:
|
||||||
|
e = 'docker'
|
||||||
|
@(e) run -P --privileged=true -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v @(os.getcwd()):/dmnt -v /etc/pki:/etc/pki:ro -d --name @(args[1]) @(args[0]) /sbin/init
|
||||||
|
rundock @(args[1])
|
||||||
|
|
||||||
|
def _unknown_host(args):
|
||||||
|
sed -i -e @(args[0])d ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
def _bake(args):
|
||||||
|
from pathlib import Path
|
||||||
|
templates = Path("~/.copier-templates/").expanduser()
|
||||||
|
if not templates.exists():
|
||||||
|
git clone src:greg/copier-templates.git ~/.copier-templates
|
||||||
|
copier copy @(str(templates / args[0])) .
|
||||||
|
|
||||||
|
aliases['bake'] = _bake
|
||||||
|
aliases['rebuild'] = _rebuild
|
||||||
|
aliases['yaml2json'] = _yaml2json
|
||||||
|
aliases['py2env'] = _py2env
|
||||||
|
aliases['py3env'] = _py3env
|
||||||
|
aliases['rundock'] = _rundock
|
||||||
|
aliases['newdock'] = _newdock
|
||||||
|
aliases['unknown_host'] = _unknown_host
|
||||||
|
aliases['pip_extras'] = _pip_extras
|
||||||
|
###
|
||||||
|
#
|
||||||
|
# Other random nice-to-have things
|
||||||
|
#
|
||||||
|
###
|
||||||
|
|
||||||
|
# Does virtualenv support
|
||||||
|
xontrib load vox
|
||||||
|
# Faster coreutils
|
||||||
|
xontrib load coreutils
|
||||||
|
|
||||||
|
# Allows identifying JSON as if it was Python by adding some new builtins to the language
|
||||||
|
import builtins
|
||||||
|
builtins.true = True
|
||||||
|
builtins.false = False
|
||||||
|
builtins.null = None
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# vim: set ft=python:
|
||||||
|
if '__NIX_DARWIN_SET_ENVIRONMENT_DONE' not in ${...} or not $__NIX_DARWIN_SET_ENVIRONMENT_DONE:
|
||||||
|
source-bash /etc/bashrc
|
||||||
|
|
||||||
|
# set -e == $RAISE_SUBPROC_ERROR = True
|
||||||
|
# set -x == trace on; $XONSH_TRACE_SUBPROC = True
|
||||||
|
# $? == _.rtn
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
xontrib load direnv
|
||||||
|
|
||||||
|
# Insert to the front, because when we spawn xonsh in tmux we have raw python3
|
||||||
|
# paths added before these. That ends up screwing with finding the python3 version
|
||||||
|
# with all of our dependencies that we want
|
||||||
|
$PATH.insert(0, "${config.home.homeDirectory}/.nix-profile/bin")
|
||||||
|
$PATH.insert(0, "${config.home.homeDirectory}/src/bin")
|
||||||
@@ -56,6 +56,7 @@ in rec {
|
|||||||
};
|
};
|
||||||
|
|
||||||
xonsh = super.xonsh.overridePythonAttrs (old: rec{
|
xonsh = super.xonsh.overridePythonAttrs (old: rec{
|
||||||
|
python3 = self.gregpy;
|
||||||
propagatedBuildInputs = old.propagatedBuildInputs ++ [ my-py-addons.xonsh-direnv ];
|
propagatedBuildInputs = old.propagatedBuildInputs ++ [ my-py-addons.xonsh-direnv ];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user