From 6353ac188eb3db4325fc1e553c1ddcc9033ca317 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Mon, 25 Jul 2022 23:15:26 -0400 Subject: [PATCH] reorganize files --- {modules/system => apps}/installer.nix | 0 flake.nix | 4 +--- hosts/common.nix | 17 +++++++++------ hosts/desktop/default.nix | 3 ++- hosts/macbook/default.nix | 1 + hosts/wsl/default.nix | 8 +++---- modules/colorscheme/gruvbox/default.nix | 16 +------------- modules/colorscheme/gruvbox/neovim.lua | 13 ++++++++++++ modules/darwin/default.nix | 3 --- modules/darwin/utilities.nix | 5 +++++ modules/editor/default.nix | 5 ----- modules/hardware/monitors.nix | 2 +- modules/{editor => }/neovim/default.nix | 2 +- modules/{editor => }/neovim/init.lua | 0 modules/{editor => }/neovim/lua/keybinds.lua | 0 .../neovim/lua/packer/completion.lua | 0 .../{editor => }/neovim/lua/packer/lsp.lua | 0 .../{editor => }/neovim/lua/packer/misc.lua | 0 .../{editor => }/neovim/lua/packer/speed.lua | 0 .../{editor => }/neovim/lua/packer/syntax.lua | 0 .../neovim/lua/packer/telescope.lua | 0 .../neovim/lua/packer/toggleterm.lua | 0 .../neovim/lua/packer/visuals.lua | 0 .../{editor => }/neovim/lua/packer_init.lua | 0 modules/{editor => }/neovim/lua/settings.lua | 0 modules/nixos/default.nix | 9 ++++++++ modules/{system => nixos}/doas.nix | 0 modules/{system => nixos}/timezone.nix | 0 modules/{system => nixos}/user.nix | 0 modules/{editor => repositories}/dotfiles.nix | 3 +++ modules/{editor => repositories}/notes.nix | 0 .../ocr => modules/shell/bash/scripts/ocr.sh | 21 +++++-------------- modules/shell/nixpkgs.nix | 3 +-- modules/system/default.nix | 10 --------- modules/wsl/default.nix | 4 +++- 35 files changed, 61 insertions(+), 68 deletions(-) rename {modules/system => apps}/installer.nix (100%) create mode 100644 modules/colorscheme/gruvbox/neovim.lua delete mode 100644 modules/editor/default.nix rename modules/{editor => }/neovim/default.nix (93%) rename modules/{editor => }/neovim/init.lua (100%) rename modules/{editor => }/neovim/lua/keybinds.lua (100%) rename modules/{editor => }/neovim/lua/packer/completion.lua (100%) rename modules/{editor => }/neovim/lua/packer/lsp.lua (100%) rename modules/{editor => }/neovim/lua/packer/misc.lua (100%) rename modules/{editor => }/neovim/lua/packer/speed.lua (100%) rename modules/{editor => }/neovim/lua/packer/syntax.lua (100%) rename modules/{editor => }/neovim/lua/packer/telescope.lua (100%) rename modules/{editor => }/neovim/lua/packer/toggleterm.lua (100%) rename modules/{editor => }/neovim/lua/packer/visuals.lua (100%) rename modules/{editor => }/neovim/lua/packer_init.lua (100%) rename modules/{editor => }/neovim/lua/settings.lua (100%) create mode 100644 modules/nixos/default.nix rename modules/{system => nixos}/doas.nix (100%) rename modules/{system => nixos}/timezone.nix (100%) rename modules/{system => nixos}/user.nix (100%) rename modules/{editor => repositories}/dotfiles.nix (82%) rename modules/{editor => repositories}/notes.nix (100%) rename legacy/bin/ocr => modules/shell/bash/scripts/ocr.sh (71%) delete mode 100644 modules/system/default.nix diff --git a/modules/system/installer.nix b/apps/installer.nix similarity index 100% rename from modules/system/installer.nix rename to apps/installer.nix diff --git a/flake.nix b/flake.nix index ae44418..db2d00c 100644 --- a/flake.nix +++ b/flake.nix @@ -72,9 +72,7 @@ # Format and install from nothing apps = forAllSystems (system: let pkgs = import nixpkgs { inherit system; }; - in { - installer = import ./modules/system/installer.nix { inherit pkgs; }; - }); + in { installer = import ./apps/installer.nix { inherit pkgs; }; }); # Used to run commands and edit files in this repo devShells = forAllSystems (system: diff --git a/hosts/common.nix b/hosts/common.nix index 72a04ec..cac4e48 100644 --- a/hosts/common.nix +++ b/hosts/common.nix @@ -1,6 +1,11 @@ { config, lib, pkgs, ... }: { - imports = [ ../modules/shell ../modules/editor ../modules/mail/himalaya.nix ]; + imports = [ + ../modules/shell + ../modules/neovim + ../modules/repositories/notes.nix + ../modules/repositories/dotfiles.nix + ]; options = with lib; { user = mkOption { @@ -50,7 +55,8 @@ }; }; - config = { + config = let stateVersion = "22.11"; + in { # Enable features in Nix commands nix.extraOptions = "experimental-features = nix-command flakes"; @@ -69,10 +75,9 @@ nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) config.unfreePackages; - # Set a variable for dotfiles repo, not necessary but convenient - home-manager.users.${config.user} = { - home.sessionVariables = { DOTS = config.dotfilesPath; }; - }; + # Pin a state version to prevent warnings + home-manager.users.${config.user}.home.stateVersion = stateVersion; + home-manager.users.root.home.stateVersion = stateVersion; }; diff --git a/hosts/desktop/default.nix b/hosts/desktop/default.nix index 1c009c6..551211d 100644 --- a/hosts/desktop/default.nix +++ b/hosts/desktop/default.nix @@ -27,10 +27,11 @@ nixpkgs.lib.nixosSystem { ./hardware-configuration.nix ../common.nix ../../modules/hardware - ../../modules/system + ../../modules/nixos ../../modules/graphical ../../modules/gaming ../../modules/applications + ../../modules/mail/himalaya.nix ../../modules/services/keybase.nix ../../modules/services/gnupg.nix ../../modules/services/mullvad.nix diff --git a/hosts/macbook/default.nix b/hosts/macbook/default.nix index ac7eb37..4de8852 100644 --- a/hosts/macbook/default.nix +++ b/hosts/macbook/default.nix @@ -17,6 +17,7 @@ darwin.lib.darwinSystem { ../../modules/darwin ../../modules/applications/alacritty.nix ../../modules/applications/discord.nix + ../../modules/mail/himalaya.nix ../../modules/programming/nix.nix ../../modules/programming/terraform.nix ../../modules/programming/python.nix diff --git a/hosts/wsl/default.nix b/hosts/wsl/default.nix index 06730ce..9f96a44 100644 --- a/hosts/wsl/default.nix +++ b/hosts/wsl/default.nix @@ -6,7 +6,6 @@ nixpkgs.lib.nixosSystem { specialArgs = { }; modules = [ globals - home-manager.nixosModules.home-manager wsl.nixosModules.wsl home-manager.nixosModules.home-manager { @@ -20,14 +19,15 @@ nixpkgs.lib.nixosSystem { automountPath = "/mnt"; defaultUser = globals.user; startMenuLaunchers = true; - wslConf.network.generateResolvConf = true; # Turn off if breaking VPN + wslConf.network.generateResolvConf = true; # Turn off if it breaks VPN interop.includePath = - false; # Including Windows PATH will slow down Neovim + false; # Including Windows PATH will slow down Neovim command mode }; } ../common.nix ../../modules/wsl - ../../modules/system + ../../modules/nixos + ../../modules/mail/himalaya.nix ../../modules/programming/nix.nix ../../modules/programming/lua.nix ]; diff --git a/modules/colorscheme/gruvbox/default.nix b/modules/colorscheme/gruvbox/default.nix index 574e4c3..70fcd26 100644 --- a/modules/colorscheme/gruvbox/default.nix +++ b/modules/colorscheme/gruvbox/default.nix @@ -18,19 +18,5 @@ base0D = "#83a598"; # blue base0E = "#d3869b"; # purple base0F = "#d65d0e"; # brown - neovimConfig = '' - local M = {} - - M.packer = function(use) - use({ - "lifepillar/vim-gruvbox8", - config = function() - vim.g.gruvbox_italicize_strings = 0 - vim.cmd("colorscheme gruvbox8") - end, - }) - end - - return M - ''; + neovimConfig = ./neovim.lua; } diff --git a/modules/colorscheme/gruvbox/neovim.lua b/modules/colorscheme/gruvbox/neovim.lua new file mode 100644 index 0000000..086b0cb --- /dev/null +++ b/modules/colorscheme/gruvbox/neovim.lua @@ -0,0 +1,13 @@ +local M = {} + +M.packer = function(use) + use({ + "lifepillar/vim-gruvbox8", + config = function() + vim.g.gruvbox_italicize_strings = 0 + vim.cmd("colorscheme gruvbox8") + end, + }) +end + +return M diff --git a/modules/darwin/default.nix b/modules/darwin/default.nix index 66444f5..6497ab2 100644 --- a/modules/darwin/default.nix +++ b/modules/darwin/default.nix @@ -12,7 +12,4 @@ ./utilities.nix ]; - home-manager.users.${config.user}.home.stateVersion = "22.11"; - home-manager.users.root.home.stateVersion = "22.11"; - } diff --git a/modules/darwin/utilities.nix b/modules/darwin/utilities.nix index fd93007..b8f8824 100644 --- a/modules/darwin/utilities.nix +++ b/modules/darwin/utilities.nix @@ -14,11 +14,16 @@ kubectl k9s noti # Create notifications programmatically + (pkgs.writeShellScriptBin "ocr" + (builtins.readFile ../shell/bash/scripts/ocr.sh)) ]; programs.fish.shellAbbrs = { # Add noti for ghpr in Darwin ghpr = lib.mkForce "gh pr create && sleep 3 && noti gh run watch"; + + # Shortcut to edit hosts file + hosts = "sudo nvim /etc/hosts"; }; }; diff --git a/modules/editor/default.nix b/modules/editor/default.nix deleted file mode 100644 index 3362213..0000000 --- a/modules/editor/default.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ ... }: { - - imports = [ ./neovim ./notes.nix ./dotfiles.nix ]; - -} diff --git a/modules/hardware/monitors.nix b/modules/hardware/monitors.nix index 156848b..3ae0e6c 100644 --- a/modules/hardware/monitors.nix +++ b/modules/hardware/monitors.nix @@ -1,7 +1,7 @@ { config, pkgs, lib, ... }: { # Timezone required for Redshift schedule - imports = [ ../system/timezone.nix ]; + imports = [ ../nixos/timezone.nix ]; config = lib.mkIf config.gui.enable { diff --git a/modules/editor/neovim/default.nix b/modules/neovim/default.nix similarity index 93% rename from modules/editor/neovim/default.nix rename to modules/neovim/default.nix index db7ab89..62b77b6 100644 --- a/modules/editor/neovim/default.nix +++ b/modules/neovim/default.nix @@ -15,7 +15,7 @@ source = ./lua; recursive = true; # Allows adding more files }; - "nvim/lua/packer/colors.lua".text = config.gui.colorscheme.neovimConfig; + "nvim/lua/packer/colors.lua".source = config.gui.colorscheme.neovimConfig; }; programs.git.extraConfig.core.editor = "nvim"; diff --git a/modules/editor/neovim/init.lua b/modules/neovim/init.lua similarity index 100% rename from modules/editor/neovim/init.lua rename to modules/neovim/init.lua diff --git a/modules/editor/neovim/lua/keybinds.lua b/modules/neovim/lua/keybinds.lua similarity index 100% rename from modules/editor/neovim/lua/keybinds.lua rename to modules/neovim/lua/keybinds.lua diff --git a/modules/editor/neovim/lua/packer/completion.lua b/modules/neovim/lua/packer/completion.lua similarity index 100% rename from modules/editor/neovim/lua/packer/completion.lua rename to modules/neovim/lua/packer/completion.lua diff --git a/modules/editor/neovim/lua/packer/lsp.lua b/modules/neovim/lua/packer/lsp.lua similarity index 100% rename from modules/editor/neovim/lua/packer/lsp.lua rename to modules/neovim/lua/packer/lsp.lua diff --git a/modules/editor/neovim/lua/packer/misc.lua b/modules/neovim/lua/packer/misc.lua similarity index 100% rename from modules/editor/neovim/lua/packer/misc.lua rename to modules/neovim/lua/packer/misc.lua diff --git a/modules/editor/neovim/lua/packer/speed.lua b/modules/neovim/lua/packer/speed.lua similarity index 100% rename from modules/editor/neovim/lua/packer/speed.lua rename to modules/neovim/lua/packer/speed.lua diff --git a/modules/editor/neovim/lua/packer/syntax.lua b/modules/neovim/lua/packer/syntax.lua similarity index 100% rename from modules/editor/neovim/lua/packer/syntax.lua rename to modules/neovim/lua/packer/syntax.lua diff --git a/modules/editor/neovim/lua/packer/telescope.lua b/modules/neovim/lua/packer/telescope.lua similarity index 100% rename from modules/editor/neovim/lua/packer/telescope.lua rename to modules/neovim/lua/packer/telescope.lua diff --git a/modules/editor/neovim/lua/packer/toggleterm.lua b/modules/neovim/lua/packer/toggleterm.lua similarity index 100% rename from modules/editor/neovim/lua/packer/toggleterm.lua rename to modules/neovim/lua/packer/toggleterm.lua diff --git a/modules/editor/neovim/lua/packer/visuals.lua b/modules/neovim/lua/packer/visuals.lua similarity index 100% rename from modules/editor/neovim/lua/packer/visuals.lua rename to modules/neovim/lua/packer/visuals.lua diff --git a/modules/editor/neovim/lua/packer_init.lua b/modules/neovim/lua/packer_init.lua similarity index 100% rename from modules/editor/neovim/lua/packer_init.lua rename to modules/neovim/lua/packer_init.lua diff --git a/modules/editor/neovim/lua/settings.lua b/modules/neovim/lua/settings.lua similarity index 100% rename from modules/editor/neovim/lua/settings.lua rename to modules/neovim/lua/settings.lua diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix new file mode 100644 index 0000000..b5cc4b8 --- /dev/null +++ b/modules/nixos/default.nix @@ -0,0 +1,9 @@ +{ config, ... }: { + + imports = [ ./user.nix ./timezone.nix ./doas.nix ]; + + # Pin a state version to prevent warnings + system.stateVersion = + config.home-manager.users.${config.user}.home.stateVersion; + +} diff --git a/modules/system/doas.nix b/modules/nixos/doas.nix similarity index 100% rename from modules/system/doas.nix rename to modules/nixos/doas.nix diff --git a/modules/system/timezone.nix b/modules/nixos/timezone.nix similarity index 100% rename from modules/system/timezone.nix rename to modules/nixos/timezone.nix diff --git a/modules/system/user.nix b/modules/nixos/user.nix similarity index 100% rename from modules/system/user.nix rename to modules/nixos/user.nix diff --git a/modules/editor/dotfiles.nix b/modules/repositories/dotfiles.nix similarity index 82% rename from modules/editor/dotfiles.nix rename to modules/repositories/dotfiles.nix index 2d253e2..3a21f78 100644 --- a/modules/editor/dotfiles.nix +++ b/modules/repositories/dotfiles.nix @@ -16,6 +16,9 @@ }; + # Set a variable for dotfiles repo, not necessary but convenient + home.sessionVariables.DOTS = config.dotfilesPath; + }; } diff --git a/modules/editor/notes.nix b/modules/repositories/notes.nix similarity index 100% rename from modules/editor/notes.nix rename to modules/repositories/notes.nix diff --git a/legacy/bin/ocr b/modules/shell/bash/scripts/ocr.sh similarity index 71% rename from legacy/bin/ocr rename to modules/shell/bash/scripts/ocr.sh index 6f24fbf..1a6b0c7 100755 --- a/legacy/bin/ocr +++ b/modules/shell/bash/scripts/ocr.sh @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p tesseract # Yoinked from https://github.com/JJGO/dotfiles # Adapted from https://github.com/sdushantha/bin @@ -13,18 +14,6 @@ function notify-send() { PATH="/usr/local/bin/:$PATH" -# Check if the needed dependencies are installed -dependencies=(tesseract) -for dependency in "${dependencies[@]}"; do - type -p "$dependency" &>/dev/null || { - # The reason why we are sending the error as a notification is because - # user is most likely going to run this script by binding it to their - # keyboard, therefor they cant see any text that is outputed using echo - notify-send "ocr" "Could not find '${dependency}', is it installed?" - exit 1 - } -done - # Take screenshot by selecting the area screencapture -i "$IMAGE_FILE" @@ -47,7 +36,7 @@ tesseract "$IMAGE_FILE" "${TEXT_FILE//\.txt/}" # Check if the text was detected by checking number # of lines in the file -LINES=$(wc -l < $TEXT_FILE) +LINES=$(wc -l <$TEXT_FILE) if [ "$LINES" -eq 0 ]; then notify-send "ocr" "no text was detected" exit 1 @@ -55,10 +44,10 @@ fi # Copy text to clipboard # xclip -selection clip < "$TEXT_FILE" -pbcopy < "$TEXT_FILE" +pbcopy <"$TEXT_FILE" # Send a notification with the text that was grabbed using OCR -# notify-send "ocr" "$(cat $TEXT_FILE)" +notify-send "ocr" "$(cat $TEXT_FILE)" # Clean up # "Always leave the area better than you found it" diff --git a/modules/shell/nixpkgs.nix b/modules/shell/nixpkgs.nix index 0cf8adf..b878e25 100644 --- a/modules/shell/nixpkgs.nix +++ b/modules/shell/nixpkgs.nix @@ -46,7 +46,6 @@ }; # Provides "command-not-found" options - # Requires activating a manual download programs.nix-index = { enable = true; enableFishIntegration = true; @@ -54,7 +53,7 @@ }; - # Set system channels for nix-shell + # Set system channels, used for nix-shell commands nix = { nixPath = [ "nixpkgs=${pkgs.path}" ]; }; } diff --git a/modules/system/default.nix b/modules/system/default.nix deleted file mode 100644 index 1d602c8..0000000 --- a/modules/system/default.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ config, ... }: { - - imports = [ ./user.nix ./timezone.nix ./doas.nix ]; - - # Pin a state version to prevent warnings - system.stateVersion = "22.11"; - home-manager.users.${config.user}.home.stateVersion = "22.11"; - home-manager.users.root.home.stateVersion = "22.11"; - -} diff --git a/modules/wsl/default.nix b/modules/wsl/default.nix index be5a6d2..73c04ba 100644 --- a/modules/wsl/default.nix +++ b/modules/wsl/default.nix @@ -1,5 +1,6 @@ { config, lib, ... }: { + # Systemd doesn't work in WSL so these must be disabled services.geoclue2.enable = lib.mkForce false; location = { provider = lib.mkForce "manual"; }; services.localtimed.enable = lib.mkForce false; @@ -8,7 +9,8 @@ # home-manager.users.${config.user}.home.sessionPath = # [ "/mnt/c/Program Files/win32yank/" ]; - # Replace config directory with our repo + # Replace config directory with our repo, since it sources from config on + # every launch system.activationScripts.configDir.text = '' rm -rf /etc/nixos ln --symbolic --no-dereference --force ${config.dotfilesPath} /etc/nixos