switch to xonsh
and add virtual machine configurations
This commit is contained in:
parent
29a30637ca
commit
3c0916835a
10 changed files with 238 additions and 44 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
||||||
hosts/configuration.nix
|
hosts/configuration.nix
|
||||||
__pycache__
|
__pycache__
|
||||||
|
*.qcow2
|
||||||
|
result
|
||||||
|
|
94
config/xonsh/aliases.py
Normal file
94
config/xonsh/aliases.py
Normal 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)
|
|
@ -54,6 +54,7 @@
|
||||||
./nixos/pkg.nix
|
./nixos/pkg.nix
|
||||||
./nixos/shell.nix
|
./nixos/shell.nix
|
||||||
./nixos/sudo.nix
|
./nixos/sudo.nix
|
||||||
|
./nixos/symlinks.nix
|
||||||
./nixos/tailscale.nix
|
./nixos/tailscale.nix
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -107,6 +107,7 @@
|
||||||
# Misc - Language Support
|
# Misc - Language Support
|
||||||
jnoortheen.nix-ide
|
jnoortheen.nix-ide
|
||||||
tamasfe.even-better-toml
|
tamasfe.even-better-toml
|
||||||
|
jnoortheen.xonsh
|
||||||
matthewpi.caddyfile-support
|
matthewpi.caddyfile-support
|
||||||
editorconfig.editorconfig
|
editorconfig.editorconfig
|
||||||
prisma.prisma
|
prisma.prisma
|
||||||
|
@ -321,6 +322,7 @@
|
||||||
".env" = "properties";
|
".env" = "properties";
|
||||||
"*.ini" = "paradox";
|
"*.ini" = "paradox";
|
||||||
"*.kt" = "kotlin";
|
"*.kt" = "kotlin";
|
||||||
|
"**/xonsh/*.py" = "xonsh";
|
||||||
};
|
};
|
||||||
"editor.semanticHighlighting.enabled" = true;
|
"editor.semanticHighlighting.enabled" = true;
|
||||||
"[css]" = { "editor.defaultFormatter" = "vscode.css-language-features"; };
|
"[css]" = { "editor.defaultFormatter" = "vscode.css-language-features"; };
|
||||||
|
@ -343,7 +345,7 @@
|
||||||
"python.analysis.inlayHints.functionReturnTypes" = true;
|
"python.analysis.inlayHints.functionReturnTypes" = true;
|
||||||
"explorer.confirmDragAndDrop" = false;
|
"explorer.confirmDragAndDrop" = false;
|
||||||
"editor.unicodeHighlight.allowedLocales" = { ru = true; };
|
"editor.unicodeHighlight.allowedLocales" = { ru = true; };
|
||||||
"terminal.integrated.defaultProfile.linux" = "zsh";
|
"terminal.integrated.defaultProfile.linux" = "xonsh";
|
||||||
"explorer.confirmPasteNative" = false;
|
"explorer.confirmPasteNative" = false;
|
||||||
"editor.renderWhitespace" = "none";
|
"editor.renderWhitespace" = "none";
|
||||||
"explorer.fileNesting.patterns" = {
|
"explorer.fileNesting.patterns" = {
|
||||||
|
|
23
hosts/virtual-machines/gnome/default.nix
Normal file
23
hosts/virtual-machines/gnome/default.nix
Normal 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);
|
||||||
|
}
|
7
hosts/virtual-machines/nixpkgs/default.nix
Normal file
7
hosts/virtual-machines/nixpkgs/default.nix
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{ pkgs, ... }: {
|
||||||
|
imports = [
|
||||||
|
../template.nix
|
||||||
|
../../../nixos/shell.nix
|
||||||
|
];
|
||||||
|
environment.systemPackages = with pkgs; [ fastfetch ];
|
||||||
|
}
|
25
hosts/virtual-machines/template.nix
Normal file
25
hosts/virtual-machines/template.nix
Normal 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";
|
||||||
|
}
|
|
@ -45,11 +45,12 @@ let
|
||||||
fontforge
|
fontforge
|
||||||
packwiz
|
packwiz
|
||||||
xclip
|
xclip
|
||||||
|
starship
|
||||||
|
|
||||||
# for scripts
|
# for xonsh
|
||||||
python312
|
python311
|
||||||
python312Packages.requests
|
python311Packages.pip
|
||||||
python312Packages.pyperclip
|
python311Packages.python-lsp-server
|
||||||
];
|
];
|
||||||
flakePackages = with inputs; [ compose2nix.packages.${system}.default ];
|
flakePackages = with inputs; [ compose2nix.packages.${system}.default ];
|
||||||
in {
|
in {
|
||||||
|
|
112
nixos/shell.nix
Executable file → Normal file
112
nixos/shell.nix
Executable file → Normal 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
|
# starship - a customizable prompt for any shell
|
||||||
programs.starship = {
|
programs.starship = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
@ -57,52 +62,81 @@
|
||||||
add_newline = false;
|
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;
|
enable = true;
|
||||||
shellInit = ''
|
config = ''
|
||||||
export PATH="$PATH:$HOME/bin:$HOME/.local/bin:$HOME/go/bin"
|
$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";
|
# src = pkgs.fetchFromGitHub {
|
||||||
in {
|
# owner = "eugenesvk";
|
||||||
ff = "fastfetch";
|
# repo = name;
|
||||||
neofetch = "fastfetch";
|
# rev = version;
|
||||||
nf = "fastfetch";
|
# sha256 = "XxSxjyCg7PeX1v3e2KKicvAPmNeq+qVqbW4fXTwAiic=";
|
||||||
|
# };
|
||||||
|
|
||||||
lg = "lazygit";
|
# meta = {
|
||||||
lad = "lazydocker";
|
# 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";
|
src = pkgs.fetchFromGitHub {
|
||||||
paste = "wl-paste";
|
owner = "74th";
|
||||||
cat = "bat";
|
repo = name;
|
||||||
|
rev = version;
|
||||||
|
sha256 = "huBJ7WknVCk+WgZaXHlL+Y1sqsn6TYqMP29/fsUPSyU=";
|
||||||
|
};
|
||||||
|
|
||||||
l = "eza -lhg ${ezaArgs}";
|
meta = {
|
||||||
la = "eza -lAh ${ezaArgs}";
|
homepage = "https://github.com/74th/xonsh-direnv";
|
||||||
ll = "eza -lhg ${ezaArgs}";
|
description = "xonsh extension for using direnv";
|
||||||
ls = "eza ${ezaArgs}";
|
license = pkgs.lib.licenses.mit;
|
||||||
lsa = "eza -lah ${ezaArgs}";
|
maintainers = [ "cswimr" ];
|
||||||
tree = "eza --tree --git-ignore ${ezaArgs}";
|
};
|
||||||
git = "hub";
|
})
|
||||||
|
(ps.buildPythonPackage rec {
|
||||||
|
name = "xontrib-sh";
|
||||||
|
version = "0.3.1";
|
||||||
|
|
||||||
create-devenv = "nix flake init --template github:cachix/devenv && direnv allow";
|
src = pkgs.fetchFromGitHub {
|
||||||
develop = "nix develop --no-pure-eval";
|
owner = "anki-code";
|
||||||
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 --";
|
repo = name;
|
||||||
nixrc = "$EDITOR /etc/nixos";
|
rev = version;
|
||||||
delete-vscode-settings-backup = "rm -rf ~/.config/Code/User/settings.json.bak";
|
sha256 = "KL/AxcsvjxqxvjDlf1axitgME3T+iyuW6OFb1foRzN8=";
|
||||||
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";
|
|
||||||
|
|
||||||
taildrop = "tailscale file";
|
meta = {
|
||||||
|
homepage = "https://github.com/anki-code/xontrib-sh";
|
||||||
forgejo-runner = "act_runner";
|
description =
|
||||||
runactions =
|
"Paste and run commands from bash, zsh, fish, tcsh in xonsh shell.";
|
||||||
"act_runner exec --default-actions-url=https://www.coastalcommits.com --gitea-instance=https://www.coastalcommits.com";
|
license = pkgs.lib.licenses.mit;
|
||||||
|
maintainers = [ "cswimr" ];
|
||||||
c = "clear";
|
};
|
||||||
# alias sudo to itself so user aliases can be sudoed
|
})
|
||||||
sudo = "sudo ";
|
];
|
||||||
s = "sudo ";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
5
nixos/symlinks.nix
Normal file
5
nixos/symlinks.nix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
environment.etc = {
|
||||||
|
"xonsh/rc.d".source = ../config/xonsh;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue