switch to xonsh and add virtual machine configurations

This commit is contained in:
Seaswimmer 2024-11-27 11:58:05 -05:00
parent 29a30637ca
commit 3c0916835a
Signed by: cswimr
GPG key ID: 0EC431A8DA8F8087
10 changed files with 238 additions and 44 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
hosts/configuration.nix
__pycache__
*.qcow2
result

94
config/xonsh/aliases.py Normal file
View file

@ -0,0 +1,94 @@
from pathlib import Path
import subprocess
def run(cmd: list[str]) -> subprocess.CompletedProcess:
print(f"* {' '.join(cmd)}")
return subprocess.run(cmd, check=True)
@aliases.register
@aliases.return_command
def _sudo(args):
return ["sudo", "--", *aliases.eval_alias(args)]
@aliases.register
def _vm(args):
if not args:
args = ["nixpkgs"]
vm_name = args.pop(0)
build_vm_args = args
if vm_name == "nixpkgs":
build_vm_args.extend(["-I", "nixpkgs=/bulk/home/cswimr/Projects/nixpkgs"])
vm_path = Path(f"/etc/nixos/hosts/virtual-machines/{vm_name}")
if vm_path.exists():
print(f"Building virtual machine {vm_name}")
run(["nixos-rebuild", "build-vm", "-I", "nixos-config=./default.nix", *build_vm_args, "--no-flake"], cwd=vm_path)
print(f"Running virtual vachine {vm_name}")
run([str(vm_path / "result" / "bin" / "run-nixos-vm")], cwd=vm_path)
print(f"Virtual machine {vm_name} has stopped.")
else:
raise FileNotFoundError(f"Virtual machine {vm_name} does not exist.")
@aliases.register
@aliases.return_command
def _edit(args):
if not args:
args = ["."]
if "$SSH_CONNECTION":
return ["$EDITOR", *args]
return ["$VISUAL", *args]
alias_dictionary = {
"ff": "fastfetch",
"neofetch": "fastfetch",
"nf": "fastfetch",
"lg": "lazygit",
"lad": "lazydocker",
"clip": "wl-copy",
"paste": "wl-paste",
"cat": "bat",
"git": "hub",
"l": "eza -lhg --time-style=long-iso --icons=auto",
"la": "eza -lAh --time-style=long-iso --icons=auto",
"ll": "eza -lhg --time-style=long-iso --icons=auto",
"ls": "eza --time-style=long-iso --icons=auto",
"lsa": "eza -lah --time-style=long-iso --icons=auto",
"tree": "eza --tree --git-ignore --time-style=long-iso --icons=auto",
"create-devenv": "nix flake init --template github:cachix/devenv and direnv allow",
"dev": "nix develop --no-pure-eval",
"nixpkgs-update": "nix run --option extra-substituters 'https://nix-community.cachix.org/' --option extra-trusted-public-keys 'nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=' github:ryantm/nixpkgs-update --",
"nixrc": "edit /etc/nixos",
"upd": '''sudo nixos-generate-config --dir /etc/nixos/hosts and \
sudo rm /etc/nixos/hosts/configuration.nix and \
sudo mv /etc/nixos/hosts/hardware-configuration.nix /etc/nixos/hosts/@($HOSTNAME).nix \
and git -C /etc/nixos --git-dir=/etc/nixos/.git add /etc/nixos/hosts/@($HOSTNAME).nix and \
rm -rf ~/.config/Code/User/settings.json.bak and \
sudo nixos-rebuild switch --flake /etc/nixos --impure @($args)''', #TODO: Remove --impure once the Starship module is merged - see ../../nixos/shell.nix for more information
"taildrop": "tailscale file",
"forgejo-runner": "act_runner",
"runactions": "act_runner exec --default-actions-url=https://www.coastalcommits.com --gitea-instance=https://www.coastalcommits.com",
"e": "edit",
"c": "clear",
"s": "sudo",
}
# Create aliases for scripts with the .py extension stripped
script_path = Path("/etc/nixos/scripts")
if script_path.exists():
for script in script_path.glob("*.py"):
if script.name == "__init__.py":
continue
script_name = script.name.strip(".py")
aliases.update({script_name: [str(script)]})
aliases.update(alias_dictionary)

View file

@ -54,6 +54,7 @@
./nixos/pkg.nix
./nixos/shell.nix
./nixos/sudo.nix
./nixos/symlinks.nix
./nixos/tailscale.nix
{

View file

@ -107,6 +107,7 @@
# Misc - Language Support
jnoortheen.nix-ide
tamasfe.even-better-toml
jnoortheen.xonsh
matthewpi.caddyfile-support
editorconfig.editorconfig
prisma.prisma
@ -321,6 +322,7 @@
".env" = "properties";
"*.ini" = "paradox";
"*.kt" = "kotlin";
"**/xonsh/*.py" = "xonsh";
};
"editor.semanticHighlighting.enabled" = true;
"[css]" = { "editor.defaultFormatter" = "vscode.css-language-features"; };
@ -343,7 +345,7 @@
"python.analysis.inlayHints.functionReturnTypes" = true;
"explorer.confirmDragAndDrop" = false;
"editor.unicodeHighlight.allowedLocales" = { ru = true; };
"terminal.integrated.defaultProfile.linux" = "zsh";
"terminal.integrated.defaultProfile.linux" = "xonsh";
"explorer.confirmPasteNative" = false;
"editor.renderWhitespace" = "none";
"explorer.fileNesting.patterns" = {

View file

@ -0,0 +1,23 @@
{ pkgs, lib, ... }:
let
gnomeExtensions = with pkgs.gnomeExtensions; [ totp ];
packages = with pkgs; [ fastfetch ];
in {
imports = [
../template.nix
#../../../nixos/shell.nix
];
services.xserver = {
enable = true;
displayManager.gdm.enable = true;
desktopManager.gnome.enable = true;
};
virtualisation.vmVariant.virtualisation = {
memorySize = 8192;
cores = 6;
};
environment.systemPackages = lib.lists.unique (packages ++ gnomeExtensions);
}

View file

@ -0,0 +1,7 @@
{ pkgs, ... }: {
imports = [
../template.nix
../../../nixos/shell.nix
];
environment.systemPackages = with pkgs; [ fastfetch ];
}

View file

@ -0,0 +1,25 @@
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page, on
# https://search.nixos.org/options and in the NixOS manual (`nixos-help`).
{
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
networking.hostName = "nixos";
networking.networkmanager.enable = true;
time.timeZone = "America/New_York";
users.users.cswimr = {
isNormalUser = true;
extraGroups = [ "wheel" ];
group = "cswimr";
initialPassword = "cswimr";
};
users.groups.cswimr = { };
services.qemuGuest.enable = true;
system.stateVersion = "24.11";
}

View file

@ -45,11 +45,12 @@ let
fontforge
packwiz
xclip
starship
# for scripts
python312
python312Packages.requests
python312Packages.pyperclip
# for xonsh
python311
python311Packages.pip
python311Packages.python-lsp-server
];
flakePackages = with inputs; [ compose2nix.packages.${system}.default ];
in {

112
nixos/shell.nix Executable file → Normal file
View file

@ -1,4 +1,9 @@
{ pkgs, ... }: {
{ config, pkgs, ... }: {
#TODO: Submit a PR to nixpkgs to add xonsh support to the Starship module
# After that, we can remove this import and the disabledModules line
disabledModules = [ "programs/starship.nix" ];
imports = [ /bulk/home/cswimr/Projects/nixpkgs/nixos/modules/programs/starship.nix ];
# starship - a customizable prompt for any shell
programs.starship = {
enable = true;
@ -57,52 +62,81 @@
add_newline = false;
};
};
users.defaultUserShell = pkgs.fish;
programs.fish = {
# enable bash completions
# even though we don't use bash as our shell, xonsh uses bash completion scripts
programs.bash.completion.enable = true;
users.defaultUserShell = pkgs.xonsh;
programs.xonsh = let bashcfg = config.programs.bash;
in {
enable = true;
shellInit = ''
export PATH="$PATH:$HOME/bin:$HOME/.local/bin:$HOME/go/bin"
config = ''
$BASH_COMPLETIONS = ('${bashcfg.completion.package}/etc/profile.d/bash_completion.sh')
#execx($(starship init xonsh))
#xontrib load cd
xontrib load direnv
xontrib load sh
'';
package = pkgs.xonsh.override {
extraPackages = ps: [
# (ps.buildPythonPackage rec {
# name = "xontrib-cd";
# version = "0.3.1";
shellAliases = let ezaArgs = "--time-style='+%Y-%m-%d %H:%M' --icons=auto";
in {
ff = "fastfetch";
neofetch = "fastfetch";
nf = "fastfetch";
# src = pkgs.fetchFromGitHub {
# owner = "eugenesvk";
# repo = name;
# rev = version;
# sha256 = "XxSxjyCg7PeX1v3e2KKicvAPmNeq+qVqbW4fXTwAiic=";
# };
lg = "lazygit";
lad = "lazydocker";
# meta = {
# homepage = "https://github.com/eugenesvk/xontrib-cd";
# description =
# "`cd` to any path without escaping in xonsh shell: `cd ~/[te] st`";
# license = pkgs.lib.licenses.mit;
# maintainers = [ "cswimr" ];
# };
# })
(ps.buildPythonPackage rec {
name = "xonsh-direnv";
version = "1.6.5";
clip = "wl-copy";
paste = "wl-paste";
cat = "bat";
src = pkgs.fetchFromGitHub {
owner = "74th";
repo = name;
rev = version;
sha256 = "huBJ7WknVCk+WgZaXHlL+Y1sqsn6TYqMP29/fsUPSyU=";
};
l = "eza -lhg ${ezaArgs}";
la = "eza -lAh ${ezaArgs}";
ll = "eza -lhg ${ezaArgs}";
ls = "eza ${ezaArgs}";
lsa = "eza -lah ${ezaArgs}";
tree = "eza --tree --git-ignore ${ezaArgs}";
git = "hub";
meta = {
homepage = "https://github.com/74th/xonsh-direnv";
description = "xonsh extension for using direnv";
license = pkgs.lib.licenses.mit;
maintainers = [ "cswimr" ];
};
})
(ps.buildPythonPackage rec {
name = "xontrib-sh";
version = "0.3.1";
create-devenv = "nix flake init --template github:cachix/devenv && direnv allow";
develop = "nix develop --no-pure-eval";
nixpkgs-update = "nix run --option extra-substituters 'https://nix-community.cachix.org/' --option extra-trusted-public-keys 'nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=' github:ryantm/nixpkgs-update --";
nixrc = "$EDITOR /etc/nixos";
delete-vscode-settings-backup = "rm -rf ~/.config/Code/User/settings.json.bak";
upd =
"sudo nixos-generate-config --dir /etc/nixos/hosts && sudo rm /etc/nixos/hosts/configuration.nix && sudo mv /etc/nixos/hosts/hardware-configuration.nix /etc/nixos/hosts/$(hostname).nix && git -C /etc/nixos --git-dir=/etc/nixos/.git add /etc/nixos/hosts/$(hostname).nix && delete-vscode-settings-backup && sudo nixos-rebuild switch --flake /etc/nixos";
src = pkgs.fetchFromGitHub {
owner = "anki-code";
repo = name;
rev = version;
sha256 = "KL/AxcsvjxqxvjDlf1axitgME3T+iyuW6OFb1foRzN8=";
};
taildrop = "tailscale file";
forgejo-runner = "act_runner";
runactions =
"act_runner exec --default-actions-url=https://www.coastalcommits.com --gitea-instance=https://www.coastalcommits.com";
c = "clear";
# alias sudo to itself so user aliases can be sudoed
sudo = "sudo ";
s = "sudo ";
meta = {
homepage = "https://github.com/anki-code/xontrib-sh";
description =
"Paste and run commands from bash, zsh, fish, tcsh in xonsh shell.";
license = pkgs.lib.licenses.mit;
maintainers = [ "cswimr" ];
};
})
];
};
};
}

5
nixos/symlinks.nix Normal file
View file

@ -0,0 +1,5 @@
{
environment.etc = {
"xonsh/rc.d".source = ../config/xonsh;
};
}