From fd0f029e99dc7842d872a509ce90197b8b319346 Mon Sep 17 00:00:00 2001 From: Benson Chu Date: Fri, 26 Jan 2024 08:07:20 -0600 Subject: [PATCH] Let there be light! Honestly, you should be ashamed that this hasn't been source controlled sooner. Tsk tsk tsk. --- .gitignore | 1 + Makefile | 21 +++ configuration.nix | 175 +++++++++++++++++++++++++ flake.lock | 66 ++++++++++ flake.nix | 35 +++++ hardware-configuration.nix | 53 ++++++++ home.nix | 246 +++++++++++++++++++++++++++++++++++ nvim/init.lua | 94 +++++++++++++ nvim/lua/lsp.lua | 62 +++++++++ nvim/lua/telescope.lua | 62 +++++++++ scripts/git-remote-log | 10 ++ scripts/git-safe-pull | 2 + scripts/git-snapshot | 2 + scripts/git-switch-to-branch | 17 +++ scripts/terraform | 65 +++++++++ scripts/tfenv | 113 ++++++++++++++++ tmux/tmux.conf | 55 ++++++++ wezterm/wezterm.lua | 8 ++ 18 files changed, 1087 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 configuration.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 hardware-configuration.nix create mode 100644 home.nix create mode 100755 nvim/init.lua create mode 100755 nvim/lua/lsp.lua create mode 100755 nvim/lua/telescope.lua create mode 100755 scripts/git-remote-log create mode 100755 scripts/git-safe-pull create mode 100755 scripts/git-snapshot create mode 100755 scripts/git-switch-to-branch create mode 100755 scripts/terraform create mode 100755 scripts/tfenv create mode 100644 tmux/tmux.conf create mode 100644 wezterm/wezterm.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2f5dd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7fbb421 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +all: build + +.PHONY: +build: + NIXPKGS_ALLOW_UNFREE=1 home-manager build --flake .#dwave --impure + +.PHONY: +update: + NIXPKGS_ALLOW_UNFREE=1 nix flake update . + +.PHONY: +switch: update build + NIXPKGS_ALLOW_UNFREE=1 home-manager switch --flake .#dwave --impure -b backup + +.PHONY: +install: + nix run home-manager/release-23.05 -- init --switch + +.PHONY: +clean: + sudo rm -rf result diff --git a/configuration.nix b/configuration.nix new file mode 100644 index 0000000..23e13c0 --- /dev/null +++ b/configuration.nix @@ -0,0 +1,175 @@ +{ config, pkgs, ... }: + +{ + imports = [ ./hardware-configuration.nix ]; + + networking.hostId = "7be305c3"; + networking.hostName = "sandy"; + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + networking.networkmanager.enable = true; + time.timeZone = "America/Chicago"; + + i18n.defaultLocale = "en_US.UTF-8"; + i18n.extraLocaleSettings = { + LC_ADDRESS = "en_US.UTF-8"; + LC_IDENTIFICATION = "en_US.UTF-8"; + LC_MEASUREMENT = "en_US.UTF-8"; + LC_MONETARY = "en_US.UTF-8"; + LC_NAME = "en_US.UTF-8"; + LC_NUMERIC = "en_US.UTF-8"; + LC_PAPER = "en_US.UTF-8"; + LC_TELEPHONE = "en_US.UTF-8"; + LC_TIME = "en_US.UTF-8"; + }; + + nixpkgs.config.allowUnfree = true; + + nix = { + package = pkgs.nixFlakes; + extraOptions = '' + experimental-features = nix-command flakes + ''; + }; + + services = { + openssh.enable = true; + tailscale.enable = true; + zfs.autoSnapshot.enable = true; + pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + }; + + hardware.bolt.enable = true; + + xserver = { + enable = true; + displayManager.lightdm.enable = true; + desktopManager.plasma5.enable = true; + displayManager.defaultSession = "plasmawayland"; + displayManager.autoLogin.enable = true; + displayManager.autoLogin.user = "hodgson"; + layout = "us"; + xkbVariant = ""; + }; + + emacs = { + enable = true; + install = true; + startWithGraphical = true; + }; + + nscd.enable = true; + printing.enable = true; + }; + + programs.zsh.enable = true; + services.avahi = { + enable = true; + nssmdns = true; + openFirewall = true; + publish = { + enable = true; + userServices = true; + }; + }; + services.printing = { + listenAddresses = [ "*:631" ]; + allowFrom = [ "all" ]; + browsing = true; + defaultShared = true; + openFirewall = true; + drivers = [ pkgs.epson-escpr2 pkgs.epson-escpr pkgs.epson-201106w pkgs.gutenprint ]; + }; + sound.enable = true; + hardware.pulseaudio.enable = false; + hardware.printers = { + + }; + + security = { + rtkit.enable = true; + sudo.wheelNeedsPassword = false; + }; + + users.users.nshields = { + isNormalUser = true; + shell = pkgs.zsh; + description = "Nikolai Shields"; + extraGroups = [ "lp" "docker" "networkmanager" "wheel" "podman" ]; + openssh.authorizedKeys.keys = [ + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCpQBfim54pBdMAHJyYrrOpgma5EEE0GxVs92ax+WzJNIoXsuaQUVxQ8adzO7lIxwIrYQKt8uciKmsUJWRMSEKsmo6fgFUD767+d68+oz/IJitUnYHsPYfo0vsQGsiGkGi+goZ9UoLnmmOkbrGcasKrVqyM0zyd9X2cWa2CYnVU3BTa0r6+2cMBnUVI5ZigdaNm9jDiPJMMCYB60YI8A3bGZr6iNvfUSJ9p3ZTUshGzLO7ubJEZdUaa1YVOyZhZNz/u3eiBN9I+F49pV8EOazAFS5XZpkH8qxxl1fKKhNMtpYxx4UolesvfCf19qxf8ElNL2x70GPxhZApZ+IW0Ia2FwGmBYJq82Rd44fUHs+qK81a97auvj+fHCf+7wVLIoKTjg3sbOnVCCOe9/tYbzy/W+Bxbp1mCkvvfCirGX+P8VovbTGliwBAFwFBTNXqxlB363Fu9hmJxVUae1llMba7/FDcydgRsDSw4sNm/1lvyBrd4Fkh5CHfZFh3GGgVBpfXarYovq4TdmyuDEAqOVXJSiBUXhhhb3K40hJfNirgyO4+4C8S2VlpyWNMGGr5vDUzOKK8f1iEWiwItTg+vMTjqikuEaug+V4ZyaJiCI/p9M27+EC6K3VGLxhY4GyyMfzxbaq+08/2fmBv38izF0q7J1xJT0wvAj+bC6caZdYzIAw==" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMrs3AFRgL4YfA7aMAD7X3O9kihcSCJKY8GiyWYV6Jwx" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMyMRFu9m1ZSBqq/bAh4Vi2XDhPBkrCnYNddDizTu7Ob" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA8O6W8B0w4JdCl+1AoHEQ861gVPkPxH0FWU1tM3JVxb" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE0byzjdB7Um+ODCLNUrupMtAc/pHlznhq38y/gUPKIq" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOjlyVh1/GW3KTdGnzSDP6oii13NLIk61v6FFKuRcvz/" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINX5/yQ/mXI/qqWHWd0+lNt6rBnhDA9p5YgMBmfp3Xtk" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKtQOHXIfltnEVMxgHlxgUNB/o6Bey6vdMWtwSfo+U4q" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG90xfsjQSCH/nKyXlBujpJshZHb9yWzqDH8fLKKl9T2" + ]; + }; + + users.users.benson = { + isNormalUser = true; + shell = pkgs.zsh; + description = "Benson Chu"; + extraGroups = [ "wheel" ]; + openssh.authorizedKeys.keys = [ + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDvIHZGAD3sLB8SKxXCaJDyuSceX3lMjKKUL2cvciPSPNUXnM3hgtWrL0c4xsWw9tF2NPiANtVXjrFMoE9+j875XbbBXkpTr/HXP2+3Zjo7SgZUW2YNUbY5oPkPc5/m4BAYUGrycQNOmCvEm9hHEdMob3LnmPzImA+GHxYisL0Hi1qRDj5gjLooMOuJdFl22BddxBQk0GsSHnHpSH7Y9OMzmA2oxs7yUaYWP9aE4Ksh7HqDVavHKZDJIjujx7KkJG2a9aAw++tau81O7fJhN5aLmw8OenxNNcyXK94La9z8s7yp2G5rVTnJj6dbCklSeFHO8Oi5D7IdDRK668N9yWL5 benson@ArchLinuvo" + ]; + }; + + users.users.hodgson = { + isNormalUser = true; + shell = pkgs.zsh; + description = "Peter Hodgson"; + extraGroups = [ "lp" "wheel" ]; + openssh.authorizedKeys.keys = [ + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCpQBfim54pBdMAHJyYrrOpgma5EEE0GxVs92ax+WzJNIoXsuaQUVxQ8adzO7lIxwIrYQKt8uciKmsUJWRMSEKsmo6fgFUD767+d68+oz/IJitUnYHsPYfo0vsQGsiGkGi+goZ9UoLnmmOkbrGcasKrVqyM0zyd9X2cWa2CYnVU3BTa0r6+2cMBnUVI5ZigdaNm9jDiPJMMCYB60YI8A3bGZr6iNvfUSJ9p3ZTUshGzLO7ubJEZdUaa1YVOyZhZNz/u3eiBN9I+F49pV8EOazAFS5XZpkH8qxxl1fKKhNMtpYxx4UolesvfCf19qxf8ElNL2x70GPxhZApZ+IW0Ia2FwGmBYJq82Rd44fUHs+qK81a97auvj+fHCf+7wVLIoKTjg3sbOnVCCOe9/tYbzy/W+Bxbp1mCkvvfCirGX+P8VovbTGliwBAFwFBTNXqxlB363Fu9hmJxVUae1llMba7/FDcydgRsDSw4sNm/1lvyBrd4Fkh5CHfZFh3GGgVBpfXarYovq4TdmyuDEAqOVXJSiBUXhhhb3K40hJfNirgyO4+4C8S2VlpyWNMGGr5vDUzOKK8f1iEWiwItTg+vMTjqikuEaug+V4ZyaJiCI/p9M27+EC6K3VGLxhY4GyyMfzxbaq+08/2fmBv38izF0q7J1xJT0wvAj+bC6caZdYzIAw==" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMrs3AFRgL4YfA7aMAD7X3O9kihcSCJKY8GiyWYV6Jwx" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMyMRFu9m1ZSBqq/bAh4Vi2XDhPBkrCnYNddDizTu7Ob" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA8O6W8B0w4JdCl+1AoHEQ861gVPkPxH0FWU1tM3JVxb" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE0byzjdB7Um+ODCLNUrupMtAc/pHlznhq38y/gUPKIq" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOjlyVh1/GW3KTdGnzSDP6oii13NLIk61v6FFKuRcvz/" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINX5/yQ/mXI/qqWHWd0+lNt6rBnhDA9p5YgMBmfp3Xtk" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKtQOHXIfltnEVMxgHlxgUNB/o6Bey6vdMWtwSfo+U4q" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG90xfsjQSCH/nKyXlBujpJshZHb9yWzqDH8fLKKl9T2" + ]; + + }; + + environment.systemPackages = with pkgs; [ + gnome.gnome-tweaks + gnome.networkmanager-openconnect + google-chrome + nss + htop + sssd + nsss + vim + git + curl + wget + wl-clipboard + unscd + glibc + glib + openconnect + emacs + ispell + tmux + libsForQt5.plasma-thunderbolt + nmap + ]; + + networking.firewall.allowedTCPPorts = [ 22 ]; + networking.firewall.allowedUDPPorts = [ ]; + networking.firewall.enable = true; + + system.stateVersion = "23.05"; # Did you read the comment? +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ec6ce50 --- /dev/null +++ b/flake.lock @@ -0,0 +1,66 @@ +{ + "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1700814205, + "narHash": "sha256-lWqDPKHRbQfi+zNIivf031BUeyciVOtwCwTjyrhDB5g=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "aeb2232d7a32530d3448318790534d196bf9427a", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-23.11", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1701389149, + "narHash": "sha256-rU1suTIEd5DGCaAXKW6yHoCfR1mnYjOXQFOaH7M23js=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5de0b32be6e85dc1a9404c75131316e4ffbc634c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "nixpkgs": "nixpkgs", + "unstable": "unstable" + } + }, + "unstable": { + "locked": { + "lastModified": 1701253981, + "narHash": "sha256-ztaDIyZ7HrTAfEEUt9AtTDNoCYxUdSd6NrRHaYOIxtk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e92039b55bcd58469325ded85d4f58dd5a4eaf58", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..32ee4d3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,35 @@ +{ + description = "NixOS configuration"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; + unstable.url = "github:nixos/nixpkgs/nixos-unstable"; + home-manager.url = "github:nix-community/home-manager/release-23.11"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = inputs@{ nixpkgs, home-manager, unstable, ... }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + unstablePkgs = unstable.legacyPackages.${system}; + in { + nixosConfigurations = { + sandy = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + home-manager.nixosModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.nshields = import ./home.nix; + home-manager.extraSpecialArgs = { + inherit unstablePkgs; + }; + } + ]; + }; + }; + }; +} diff --git a/hardware-configuration.nix b/hardware-configuration.nix new file mode 100644 index 0000000..cdbad55 --- /dev/null +++ b/hardware-configuration.nix @@ -0,0 +1,53 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "xhci_pci" "thunderbolt" "nvme" "usb_storage" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "rpool/root/nixos"; + fsType = "zfs"; + }; + + fileSystems."/home" = + { device = "rpool/home"; + fsType = "zfs"; + }; + + fileSystems."/home/hodgson" = + { device = "rpool/home/hodgson"; + fsType = "zfs"; + }; + + fileSystems."/home/nikolai" = + { device = "rpool/home/nikolai"; + fsType = "zfs"; + }; + + fileSystems."/boot" = + { device = "/dev/disk/by-uuid/EC2B-C09B"; + fsType = "vfat"; + }; + + swapDevices = [ ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.wlp170s0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/home.nix b/home.nix new file mode 100644 index 0000000..960b100 --- /dev/null +++ b/home.nix @@ -0,0 +1,246 @@ +{ config, pkgs, unstablePkgs, ... }: { + targets.genericLinux.enable = true; + home = { + stateVersion = "23.05"; + file = { + ".local/bin" = { source = ./scripts; }; + }; + }; + + xdg.userDirs = { + enable = true; + createDirectories = true; + extraConfig = { + XDG_SRC_DIR = "${config.home.homeDirectory}/Code"; + XDG_SCRIPTS_DIR = "${config.home.homeDirectory}/.local/bin"; + }; + }; + + xdg.configFile = { + "nvim/lua" = { + enable = true; + recursive = true; + source = ./nvim/lua; + }; + + "wezterm/" = { + enable = true; + recursive = true; + source = ./wezterm; + }; + }; + + xdg.dataFile = { + ".local" = { + enable = true; + recursive = true; + source = ./scripts; + }; + }; + + fonts.fontconfig.enable = true; + + home.packages = with pkgs; [ + cilium-cli + go + packer + podman + podman-compose + ansible + entr + file + gnumake + gum + htop + jq + k9s + krew + kubectl + kubernetes-helm + ovftool + nixfmt + ranger + ripgrep + shellcheck + shfmt + sops + sysz + tealdeer + tmux + vault + whois + zoom-us + slack + unstablePkgs.awscli2 + unstablePkgs.clusterctl + unstablePkgs.fira-code-nerdfont + ]; + + programs = { + home-manager.enable = true; + bat.enable = true; + + ssh = { forwardAgent = true; }; + + direnv = { + enable = true; + enableBashIntegration = true; + enableZshIntegration = true; + }; + + fzf = { + enable = true; + enableZshIntegration = true; + }; + + bash = { + enable = true; + sessionVariables = { + EDITOR = "nvim"; + VAULT_ADDR = "https://it-vault.dwavesys.local"; + PATH = "$PATH:$HOME/.krew/bin:$HOME/.local/bin"; + }; + }; + + zsh = { + enable = true; + enableVteIntegration = true; + completionInit = "autoload -U compinit && compinit"; + autocd = true; + enableAutosuggestions = true; + enableCompletion = true; + shellAliases = { + la = "ls -la"; + ip = "ip --color=auto"; + k = "kubectl"; + tf = "terraform"; + }; + + sessionVariables = { + EDITOR = "nvim"; + PATH = "$PATH:$HOME/.tfenv/bin:$HOME/.krew/bin:$HOME/.local/bin:/var/lib/flatpak/exports/share:$HOME/.local/share/flatpak/exports/share"; + }; + + oh-my-zsh = { + enable = true; + theme = "awesomepanda"; + }; + + dirHashes = { + Code = "$HOME/Code"; + work = "$HOME/Code/git.dwavesys.local"; + #nix = "$HOME/Code/github.com/${githubUser}/nixos-config"; + dl = "$HOME/Downloads"; + }; + + }; + + # TODO: auto-install tpm and run plugin install on first open + tmux = { + enable = true; + extraConfig = builtins.readFile tmux/tmux.conf; + }; + + neovim = { + enable = true; + vimAlias = true; + viAlias = true; + withPython3 = true; + extraPackages = with pkgs; [ + git + gopls + nodePackages.bash-language-server + ripgrep + shfmt + terraform-ls + ]; + + plugins = with pkgs.vimPlugins; [ + nvim-treesitter + nvim-treesitter-parsers.nix + nvim-treesitter-parsers.go + nvim-treesitter-parsers.hcl + nvim-treesitter-parsers.bash + nvim-treesitter-parsers.yaml + nvim-treesitter-parsers.terraform + nvim-treesitter-parsers.lua + nvim-treesitter-parsers.json + vimwiki + luasnip + auto-pairs + auto-save-nvim + neoformat + neomake + nerdcommenter + nvim-lspconfig + papercolor-theme + catppuccin-nvim + plenary-nvim + popup-nvim + project-nvim + nvim-cmp + cmp-nvim-lsp + telescope-file-browser-nvim + telescope-fzy-native-nvim + telescope-nvim + undotree + vim-fugitive + vim-nix + telescope-project-nvim + ]; + + extraLuaConfig = builtins.readFile nvim/init.lua; + }; + + wezterm = { + enable = true; # TODO: set to 'graphical' when wezterm is patched for wayland + package = unstablePkgs.wezterm; + extraConfig = builtins.readFile wezterm/wezterm.lua; + }; + + chromium = { + enable = true; + package = pkgs.brave; + extensions = [ + { id = "dbepggeogbaibhgnhhndojpepiihcmeb"; } + { id = "bfogiafebfohielmmehodmfbbebbbpei"; } + { id = "nngceckbapebfimnlniiiahkandclblb"; } + ]; + }; + + git = { + enable = true; + aliases = { + co = "checkout"; + c = "commit"; + s = "status"; + ss = "snapshot"; + sp = "safe-pull"; + rl = "remote-log"; + sb = "switch-to-branch"; + }; + + userName = "Nikolai Shields"; + userEmail = "nshields@dwavesys.com"; + signing = { + key = "~/.ssh/id_ed25519"; + signByDefault = true; + }; + + extraConfig = { + core = { + editor = "nvim"; + pager = "bat"; + }; + + gpg = { + format = "ssh"; + ssh = { allowedSignersFile = "~/.config/git/allowed_signers"; }; + }; + + init = { defaultBranch = "main"; }; + }; + }; + }; +} + diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100755 index 0000000..ea74c90 --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,94 @@ +require("telescope") +require("lsp") +vim.cmd([[ +filetype plugin indent on " allow auto-indenting depending on file type +filetype plugin on +syntax on " syntax highlighting +set autoindent " indent a new line the same amount as the line just typed +set autochdir +set wrap +set encoding=UTF-8 +set cmdheight=1 " Give more space for displaying messages. +set colorcolumn=80 +set cursorline " highlight current cursorline +set expandtab +set guicursor= +set hidden +set hlsearch " highlight search +set ignorecase " case insensitive +set incsearch +set incsearch " incremental search +set isfname+=@-@ +set mouse=a " enable mouse click +set mouse=v " middle-click paste with +set nobackup +set nocompatible " disable compatibility to old-time vi +set noerrorbells +set noswapfile +set nowrap +set nu +set scrolloff=8 +set shiftwidth=4 +set shortmess+=c " Don't pass messages to |ins-completion-menu|. +set showmatch " show matching +set signcolumn=yes +set smartindent +set tabstop=4 +set softtabstop=4 +set termguicolors +set ttyfast " Speed up scrolling in Vim +set undodir=~/.vim/undodir +set undofile +set updatetime=50 +set wildmode=longest,list " get bash-like tab completions +set grepprg=rg\ --vimgrep\ --smart-case\ --follow + +" Colors +set termguicolors +set background=dark +colorscheme catppuccin-mocha + +" Navigation +let mapleader = " " + +nnoremap j +nnoremap k +nnoremap h +nnoremap l + +" Quicker quits +nnoremap q + +" Open new split panes to right and bottom, which feels more natural +set splitbelow +set splitright + +" Quick directory change +nnoremap cd :cd %:p:h:pwd + +nnoremap wq :w:bd + +" Run commands that require an interactive shell +nnoremap r :terminal + +" Switch between the last two files +nnoremap + +" Git +nnoremap git :Git + +" Telescope +nnoremap fs :lua require('telescope.builtin').grep_string({ search = vim.fn.input("Grep For > ")}) +nnoremap :lua require('telescope.builtin').git_files() +nnoremap ff :lua require('telescope.builtin').find_files() +nnoremap fb :Telescope file_browser +nnoremap fb :Telescope file_browser +noremap fp :Telescope project +nnoremap fw :lua require('telescope.builtin').grep_string { search = vim.fn.expand("") } +nnoremap bf :lua require('telescope.builtin').buffers() +nnoremap nix :lua require('telescope').search_nixos_config() +nnoremap src :lua require('telescope').search_src() + +" Undotree +nnoremap pu :UndotreeToggle +]]) diff --git a/nvim/lua/lsp.lua b/nvim/lua/lsp.lua new file mode 100755 index 0000000..138fd2c --- /dev/null +++ b/nvim/lua/lsp.lua @@ -0,0 +1,62 @@ +require'lspconfig'.bashls.setup{} +require'lspconfig'.gopls.setup{} +require'lspconfig'.terraformls.setup{} + +-- Add additional capabilities supported by nvim-cmp +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) + +local lspconfig = require('lspconfig') + +-- Enable some language servers with the additional completion capabilities offered by nvim-cmp +local servers = { 'gopls', 'bashls', 'terraformls' } +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + -- on_attach = my_custom_on_attach, + capabilities = capabilities, + } +end + +-- luasnip setup +local luasnip = require 'luasnip' + +-- nvim-cmp setup +local cmp = require 'cmp' +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }), + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, +} diff --git a/nvim/lua/telescope.lua b/nvim/lua/telescope.lua new file mode 100755 index 0000000..e4cdf19 --- /dev/null +++ b/nvim/lua/telescope.lua @@ -0,0 +1,62 @@ +local pickers = require("telescope.pickers") +local finders = require("telescope.finders") +local previewers = require("telescope.previewers") +local action_state = require("telescope.actions.state") +local conf = require("telescope.config").values +local actions = require("telescope.actions") + +require("telescope").setup({ + defaults = { + file_sorter = require("telescope.sorters").get_fzy_sorter, + prompt_prefix = " >", + color_devicons = true, + file_previewer = require("telescope.previewers").vim_buffer_cat.new, + grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, + qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, + + mappings = { + i = { + [""] = false, + [""] = actions.send_to_qflist, + }, + }, + }, + pickers = { + file_browser = { + hidden = true, + } + }, + extensions = { + fzy_native = { + override_generic_sorter = false, + override_file_sorter = true, + }, + file_browser = { + theme = "ivy", + }, + project = { + base_dirs = { + {'$HOME/Code/git.dwavesys.local', max_depth = 1}, + {'$HOME/Code/github.com', max_depth = 2}, + hidden_files = true, + theme = "dropdown", + search_by = "title", + } + }, +} +}) + +require("telescope").load_extension("fzy_native") +require("telescope").load_extension("file_browser") +require("telescope").load_extension("project") + +M.search_nixos_config = function() + require("telescope.builtin").find_files({ + prompt_title = "< nixos config >", + cwd = "$HOME/.config/home-manager", + hidden = false, + }) +end +return M + + diff --git a/scripts/git-remote-log b/scripts/git-remote-log new file mode 100755 index 0000000..40ae00f --- /dev/null +++ b/scripts/git-remote-log @@ -0,0 +1,10 @@ +#!/usr/bin/env sh +git fetch +remoteBranch=$(git symbolic-ref --short -q HEAD) + +if [ -n "$1" ] +then + remoteBranch=$1 +fi +echo "Showing logs between $remoteBranch origin/$remoteBranch" +git log $remoteBranch..origin/$remoteBranch --oneline diff --git a/scripts/git-safe-pull b/scripts/git-safe-pull new file mode 100755 index 0000000..03031ae --- /dev/null +++ b/scripts/git-safe-pull @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +git snapshot && git restore . && git fetch --all && git pull && git stash pop diff --git a/scripts/git-snapshot b/scripts/git-snapshot new file mode 100755 index 0000000..034c0a1 --- /dev/null +++ b/scripts/git-snapshot @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +git stash && git stash apply diff --git a/scripts/git-switch-to-branch b/scripts/git-switch-to-branch new file mode 100755 index 0000000..80cec96 --- /dev/null +++ b/scripts/git-switch-to-branch @@ -0,0 +1,17 @@ +#!/usr/bin/env sh +BRANCH=$1 + +if [ -n "$BRANCH" ] +then + if [ $(git branch -l) | grep $BRANCH] + git stash -u + git checkout -b "$BRANCH" + git stash pop + else + git stash -u + git switch -c "$BRANCH" + git stash pop + fi +else + echo "Error: Branch name not specified" +fi diff --git a/scripts/terraform b/scripts/terraform new file mode 100755 index 0000000..cec01d2 --- /dev/null +++ b/scripts/terraform @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +set -uo pipefail; + +#################################### +# Ensure we can execute standalone # +#################################### + +function early_death() { + echo "[FATAL] ${0}: ${1}" >&2; + exit 1; +}; + +if [ -z "${TFENV_ROOT:-""}" ]; then + # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac + readlink_f() { + local target_file="${1}"; + local file_name; + + while [ "${target_file}" != "" ]; do + cd "${target_file%/*}" || early_death "Failed to 'cd \$(${target_file%/*})' while trying to determine TFENV_ROOT"; + file_name="${target_file##*/}" || early_death "Failed to '\"${target_file##*/}\"' while trying to determine TFENV_ROOT"; + target_file="$(readlink "${file_name}")"; + done; + + echo "$(pwd -P)/${file_name}"; + }; + TFENV_SHIM=$(readlink_f "${0}") + TFENV_ROOT="${TFENV_SHIM%/*/*}"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to determine TFENV_ROOT"; +else + TFENV_ROOT="${TFENV_ROOT%/}"; +fi; +export TFENV_ROOT; + +if [ -n "${TFENV_HELPERS:-""}" ]; then + log 'debug' 'TFENV_HELPERS is set, not sourcing helpers again'; +else + [ "${TFENV_DEBUG:-0}" -gt 0 ] && >&2 echo "[DEBUG] Sourcing helpers from ${TFENV_ROOT}/lib/helpers.sh"; + if source "${TFENV_ROOT}/lib/helpers.sh"; then + log 'debug' 'Helpers sourced successfully'; + else + early_death "Failed to source helpers from ${TFENV_ROOT}/lib/helpers.sh"; + fi; +fi; + +# Ensure libexec and bin are in $PATH +for dir in libexec bin; do + case ":${PATH}:" in + *:${TFENV_ROOT}/${dir}:*) log 'debug' "\$PATH already contains '${TFENV_ROOT}/${dir}', not adding it again";; + *) + log 'debug' "\$PATH does not contain '${TFENV_ROOT}/${dir}', prepending and exporting it now"; + export PATH="${TFENV_ROOT}/${dir}:${PATH}"; + ;; + esac; +done; + +##################### +# Begin Script Body # +##################### + +log 'debug' "program=\"${0##*/}\""; + +declare tfenv_path="${TFENV_ROOT}/bin/tfenv"; + +tfenv-exec "$@"; diff --git a/scripts/tfenv b/scripts/tfenv new file mode 100755 index 0000000..28c24a1 --- /dev/null +++ b/scripts/tfenv @@ -0,0 +1,113 @@ +#!/usr/bin/env bash +set -uo pipefail; + +#################################### +# Ensure we can execute standalone # +#################################### + +function early_death() { + echo "[FATAL] ${0}: ${1}" >&2; + exit 1; +}; + +if [ -z "${TFENV_ROOT:-""}" ]; then + # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac + readlink_f() { + local target_file="${1}"; + local file_name; + + while [ "${target_file}" != "" ]; do + cd "${target_file%/*}" || early_death "Failed to 'cd \$(${target_file%/*})' while trying to determine TFENV_ROOT"; + file_name="${target_file##*/}" || early_death "Failed to '\"${target_file##*/}\"' while trying to determine TFENV_ROOT"; + target_file="$(readlink "${file_name}")"; + done; + + echo "$(pwd -P)/${file_name}"; + }; + TFENV_SHIM=$(readlink_f "${0}") + TFENV_ROOT="${TFENV_SHIM%/*/*}"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to determine TFENV_ROOT"; + +else + TFENV_ROOT="${TFENV_ROOT%/}"; +fi; +export TFENV_ROOT; + +if [ -n "${TFENV_HELPERS:-""}" ]; then + log 'debug' 'TFENV_HELPERS is set, not sourcing helpers again'; +else + [ "${TFENV_DEBUG:-0}" -gt 0 ] && >&2 echo "[DEBUG] Sourcing helpers from ${TFENV_ROOT}/lib/helpers.sh"; + if source "${TFENV_ROOT}/lib/helpers.sh"; then + log 'debug' 'Helpers sourced successfully'; + else + early_death "Failed to source helpers from ${TFENV_ROOT}/lib/helpers.sh"; + fi; +fi; + +# Ensure libexec and bin are in $PATH +for dir in libexec bin; do + case ":${PATH}:" in + *:${TFENV_ROOT}/${dir}:*) log 'debug' "\$PATH already contains '${TFENV_ROOT}/${dir}', not adding it again";; + *) + log 'debug' "\$PATH does not contain '${TFENV_ROOT}/${dir}', prepending and exporting it now"; + export PATH="${TFENV_ROOT}/${dir}:${PATH}"; + ;; + esac; +done; + +##################### +# Begin Script Body # +##################### + +declare arg="${1:-""}"; + +log 'debug' "Setting TFENV_DIR to ${PWD}"; +export TFENV_DIR="${PWD}"; + +abort() { + log 'debug' 'Aborting...'; + { + if [ "${#}" -eq 0 ]; then + cat -; + else + echo "tfenv: ${*}"; + fi; + } >&2; +}; + +log 'debug' "tfenv argument is: ${arg}"; + +case "${arg}" in + "") + log 'debug' 'No argument provided, dumping version and help and aborting'; + { + tfenv---version; + tfenv-help; + } | abort && exit 1; +exit 1; + ;; + -v | --version ) + log 'debug' 'tfenv version requested...'; + exec tfenv---version; + ;; + -h | --help ) + log 'debug' 'tfenv help requested...'; + exec tfenv-help; + ;; + *) + log 'debug' "Long argument provided: ${arg}"; + command_path="$(command -v "tfenv-${arg}" || true)"; + log 'debug' "Resulting command-path: ${command_path}"; + if [ -z "${command_path}" ]; then + { + echo "No such command '${arg}'"; + tfenv-help; + } | abort && exit 1; + fi; + shift 1; + log 'debug' "Exec: \"${command_path}\" \"$*\""; + exec "${command_path}" "$@"; + ;; +esac; + +log 'error' 'This line should not be reachable. Something catastrophic has occurred'; diff --git a/tmux/tmux.conf b/tmux/tmux.conf new file mode 100644 index 0000000..3b57379 --- /dev/null +++ b/tmux/tmux.conf @@ -0,0 +1,55 @@ +set-option -sa terminal-overrides ",xterm*:Tc" +set -g mouse on + +unbind C-b +set -g prefix C-Space +bind C-Space send-prefix + +# Vim style pane selection +bind h select-pane -L +bind j select-pane -D +bind k select-pane -U +bind l select-pane -R + +# Start windows and panes at 1, not 0 +set -g base-index 1 +set -g pane-base-index 1 +set-window-option -g pane-base-index 1 +set-option -g renumber-windows on + +# Use Alt-arrow keys without prefix key to switch panes +bind -n M-Left select-pane -L +bind -n M-Right select-pane -R +bind -n M-Up select-pane -U +bind -n M-Down select-pane -D + +# Shift arrow to switch windows +bind -n S-Left previous-window +bind -n S-Right next-window + +# Shift Alt vim keys to switch windows +bind -n M-H previous-window +bind -n M-L next-window + +set -g @catppuccin_flavour 'mocha' + +# set vi-mode +set-window-option -g mode-keys vi +# keybindings +set -g set-clipboard on +bind-key -T copy-mode-vi v send-keys -X begin-selection +bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle +bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel + +bind '"' split-window -v -c "#{pane_current_path}" +bind % split-window -h -c "#{pane_current_path}" + +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-sensible' +set -g @plugin 'christoomey/vim-tmux-navigator' +set -g @plugin 'dreamsofcode-io/catppuccin-tmux' +set -g @plugin 'tmux-plugins/tmux-yank' + +run '~/.tmux/plugins/tpm/tpm' + + diff --git a/wezterm/wezterm.lua b/wezterm/wezterm.lua new file mode 100644 index 0000000..c6e842a --- /dev/null +++ b/wezterm/wezterm.lua @@ -0,0 +1,8 @@ +local wezterm = require 'wezterm' +local config = {} + +config.enable_wayland = true +font = wezterm.font 'FiraCode Nerd Font' +config.hide_tab_bar_if_only_one_tab = true + +return config