From 0712b63194645ba93372e52c245570e501a82198 Mon Sep 17 00:00:00 2001 From: Bryan Ramos Date: Mon, 5 Jun 2023 15:14:24 -0400 Subject: [PATCH] still working --- flake.nix | 13 +- machines/desktop/default.nix | 1 - modules/alacritty/default.nix | 83 +++++++ modules/bash/default.nix | 210 +++++++++--------- modules/git/default.nix | 6 +- modules/git/gitconfig | 4 + modules/gpg/default.nix | 11 + modules/gtk/default.nix | 10 + {homeConfig => modules}/home.nix | 0 modules/nvim/default.nix | 154 ++++++++++++- sysConfig/desktop/default.nix | 8 + .../desktop/hardware.nix | 36 ++- sysConfig/desktop/partitions.nix | 79 +++++++ {machines => sysConfig}/desktop/system.nix | 67 ++---- 14 files changed, 508 insertions(+), 174 deletions(-) delete mode 100644 machines/desktop/default.nix create mode 100644 modules/alacritty/default.nix create mode 100644 modules/git/gitconfig create mode 100644 modules/gpg/default.nix create mode 100644 modules/gtk/default.nix rename {homeConfig => modules}/home.nix (100%) create mode 100644 sysConfig/desktop/default.nix rename machines/desktop/hardware-configuration.nix => sysConfig/desktop/hardware.nix (72%) create mode 100644 sysConfig/desktop/partitions.nix rename {machines => sysConfig}/desktop/system.nix (68%) diff --git a/flake.nix b/flake.nix index 4d4df0d..682826e 100644 --- a/flake.nix +++ b/flake.nix @@ -8,12 +8,12 @@ inputs.nixpkgs.follows = "nixpkgs"; }; nur = { - url = "github:nix-community/NUR"; - inputs.nixpkgs.follows = "nixpkgs"; + url = "github:nix-community/NUR"; + inputs.nixpkgs.follows = "nixpkgs"; }; disko = { - url = "github:nix-community/disko"; - inputs.nixpkgs.follows = "nixpkgs"; + url = "github:nix-community/disko"; + inputs.nixpkgs.follows = "nixpkgs"; }; }; @@ -30,11 +30,10 @@ in { - nixosConfigurations.socrates = nixpkgs.lib.nixosSystem { + nixosConfigurations.socratesV2 = nixpkgs.lib.nixosSystem { inherit pkgs; modules = [ - ./machines/hardware-configuration.nix - ./machines/system.nix + ./machines disko.nixosModules.disko home-manager.nixosModules.home-manager{ home-manager.useGlobalPkgs = true; diff --git a/machines/desktop/default.nix b/machines/desktop/default.nix deleted file mode 100644 index 11196be..0000000 --- a/machines/desktop/default.nix +++ /dev/null @@ -1 +0,0 @@ -{ imports = ./.; } diff --git a/modules/alacritty/default.nix b/modules/alacritty/default.nix new file mode 100644 index 0000000..4ad3473 --- /dev/null +++ b/modules/alacritty/default.nix @@ -0,0 +1,83 @@ +{ pkgs, lib, config, ... } = + +with lib; +let cfg = config.modules.alacritty; + +in { + options.modules.alacritty = { enable = mkEnableOption "alacritty"; }; + config = mkIf cfg.enable { + programs.alacritty = { + enable = true; + settings = { + + scrolling = { + history = 10000; + multiplier = 3; + }; + + window = { + opacity = 0.95; + }; + + colors = { + primary = { + background = 0x0d1117; + foreground = 0xb3b1ad; + }; + + normal = { + black = 0x484f58; + red = 0xff7b72; + green = 0x3fb950; + yellow = 0xd29922; + blue = 0x58a6ff; + magenta = 0xbc8cff; + cyan = 0x39c5cf; + white = 0xb1bac4; + }; + + bright = { + black = 0x6e7681; + red = 0xffa198; + green = 0x56d364; + yellow = 0xe3b341; + blue = 0x79c0ff; + magenta = 0xd2a8ff; + cyan = 0x56d4dd; + white = 0xf0f6fc; + }; + + font = { + normal = { + family = TerminusWithNerdFont; + style = Medium; + }; + + bold = { + family = TerminusWithNerdFont; + style = Bold; + }; + + italic = { + family = TerminusWithNerdFont; + style = Medium Italic; + }; + + bold_italic = { + family = TerminusWithNerdFont; + style = Bold Italic; + }; + + size = 14; + + cursor = { + color = 0xffffff; + style = { + shape = Block; + blinking = Always; + blink-interval = 750; + }; + }; + }; + }; +} diff --git a/modules/bash/default.nix b/modules/bash/default.nix index 62c0e18..f023ddb 100644 --- a/modules/bash/default.nix +++ b/modules/bash/default.nix @@ -64,120 +64,118 @@ in { unset flake_icon } PROMPT_COMMAND="set_ps1_prompt; $PROMPT_COMMAND" + ''; - function cdg() { - if [[ $1 == "--help" ]]; then - echo "A simple utility for navigating to the root of a git repo" - return 0 - fi + bashrcExtra = '' + function cdg() { + if [[ $1 == "--help" ]]; then + echo "A simple utility for navigating to the root of a git repo" + return 0 + fi - # Check for invalid command - if [[ -n "$1" ]]; then - echo "Invalid command: $1. Try 'cdg --help'." - return 1 - fi + # Check for invalid command + if [[ -n "$1" ]]; then + echo "Invalid command: $1. Try 'cdg --help'." + return 1 + fi - local root_dir - root_dir=$(git rev-parse --show-toplevel 2>/dev/null) - local git_status=$? + local root_dir + root_dir=$(git rev-parse --show-toplevel 2>/dev/null) + local git_status=$? - if [ $git_status -ne 0 ]; then - echo "Error: Not a git repo." - return 1 - fi + if [ $git_status -ne 0 ]; then + echo "Error: Not a git repo." + return 1 + fi - cd "$root_dir" - } + cd "$root_dir" + } - function ldv() { - if [[ $1 == "help" ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then - cat << EOF - ldv - A simple utility for setting up development environments effortlessly. - Commands: - ldv Start a preconfigured nix shell. - init Create a new dev template in the current working directory. - help Show available commands and options. - - Contributions welcome: https://github.com/itme-brain/ldv - EOF - - elif [[ $1 == "init" ]] || [[ $1 == "-i" ]] || [[ $1 == "--init" ]]; then - if [[ -e ./shell.nix ]] || [[ -e ./.envrc ]]; then + function ldv() { + if [[ $1 == "help" ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then cat << EOF - Existing environment found. - Initialization cancelled. - EOF - return + ldv + A simple utility for setting up development environments effortlessly. + Commands: + ldv Start a preconfigured nix shell. + init Create a new dev template in the current working directory. + help Show available commands and options. + + Contributions welcome: https://github.com/itme-brain/ldv + EOF + + elif [[ $1 == "init" ]] || [[ $1 == "-i" ]] || [[ $1 == "--init" ]]; then + if [[ -e ./shell.nix ]] || [[ -e ./.envrc ]]; then + cat << EOF + Existing environment found. + Initialization cancelled. + EOF + return + fi + + cat << EOF + Initializing a new environment... + Select an environment: + 1. Web + 2. Elixir + 3. Haskell + EOF + + read -p "Enter the number of your choice: " choice + + case $choice in + 1) + wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/shells/web.nix -O shell.nix + wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/flake -O flake.nix + wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/envrc -O .envrc + direnv allow + ;; + 2) + wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/shells/elixir.nix -O shell.nix + wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/flake -O flake.nix + wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/envrc -O .envrc + direnv allow + ;; + 3) + wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/shells/haskell.nix -O shell.nix + wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/flake -O flake.nix + wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/envrc -O .envrc + direnv allow + ;; + *) + echo "Invalid choice." + ;; + esac + elif [[ -z $1 ]]; then + cat << EOF + Select an environment: + 1. Web + 2. Elixir + 3. Haskell + EOF + + read -p "Enter the number of your choice: " choice + + case $choice in + 1) + (nix develop github:itme-brain/ldv#web) + ;; + 2) + (nix develop github:itme-brain/ldv#elixir) + ;; + 3) + (nix develop github:itme-brain/ldv#haskell) + ;; + # Add more cases here... + *) + echo "Invalid choice." + ;; + esac + else + echo "Error: Invalid command. Try 'ldv --help'" fi - - cat << EOF - Initializing a new environment... - Select an environment: - 1. Web - 2. Elixir - 3. Haskell - EOF - - read -p "Enter the number of your choice: " choice - - case $choice in - 1) - wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/shells/web.nix -O shell.nix - wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/flake -O flake.nix - wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/envrc -O .envrc - direnv allow - ;; - 2) - wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/shells/elixir.nix -O shell.nix - wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/flake -O flake.nix - wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/envrc -O .envrc - direnv allow - ;; - 3) - wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/shells/haskell.nix -O shell.nix - wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/flake -O flake.nix - wget -q https://raw.githubusercontent.com/itme-brain/ldv/main/utils/envrc -O .envrc - direnv allow - ;; - *) - echo "Invalid choice." - ;; - esac - elif [[ -z $1 ]]; then - cat << EOF - Select an environment: - 1. Web - 2. Elixir - 3. Haskell - EOF - - read -p "Enter the number of your choice: " choice - - case $choice in - 1) - (nix develop github:itme-brain/ldv#web) - ;; - 2) - (nix develop github:itme-brain/ldv#elixir) - ;; - 3) - (nix develop github:itme-brain/ldv#haskell) - ;; - # Add more cases here... - *) - echo "Invalid choice." - ;; - esac - else - echo "Error: Invalid command. Try 'ldv --help'" - fi - } - - if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - ldv "$@" - fi - ''; + } + ''; shellAliases = { ls = "lsd"; diff --git a/modules/git/default.nix b/modules/git/default.nix index 2167008..90ffccd 100644 --- a/modules/git/default.nix +++ b/modules/git/default.nix @@ -9,11 +9,13 @@ in config = mkIf cfg.enable { programs.git = { enable = true; - userName = "Bryan Ramos"; - userEmail = "bryan@ramos.codes"; extraConfig = { init = { defaultBranch = "main"; }; }; }; + + home.file = { + ".gitconfig".source = ./gitconfig; + }; }; } diff --git a/modules/git/gitconfig b/modules/git/gitconfig new file mode 100644 index 0000000..c7beb3f --- /dev/null +++ b/modules/git/gitconfig @@ -0,0 +1,4 @@ +[user] + email = bryan@ramos.codes + name = Bryan Ramos + signingkey = F1F3466458452B2DF351F1E864D12BA95ACE1F2D diff --git a/modules/gpg/default.nix b/modules/gpg/default.nix new file mode 100644 index 0000000..6da48fc --- /dev/null +++ b/modules/gpg/default.nix @@ -0,0 +1,11 @@ +{ pkgs, lib, config, ... }: + +with lib; +let cfg = config.modules.gpg; + +in { + options.modules.gpg = { enable = mkEnableOption "gpg"; }; + config = mkIf cfg.enable { + programs.gpg.enable = true; + }; +} diff --git a/modules/gtk/default.nix b/modules/gtk/default.nix new file mode 100644 index 0000000..ce7f29b --- /dev/null +++ b/modules/gtk/default.nix @@ -0,0 +1,10 @@ +{ pkgs, lib, config, ... }: + +with lib; +let cfg = config.modules.PROGRAM; + +in { + options.modules.PROGRAM = { enable = mkEnableOption "PROGRAM"; }; + config = mkIf cfg.enable { + }; +} diff --git a/homeConfig/home.nix b/modules/home.nix similarity index 100% rename from homeConfig/home.nix rename to modules/home.nix diff --git a/modules/nvim/default.nix b/modules/nvim/default.nix index 592cfb8..9950375 100644 --- a/modules/nvim/default.nix +++ b/modules/nvim/default.nix @@ -8,7 +8,7 @@ let cfg = config.modules.neovim; src = pkgs.fetchFromGithub { owner = "projekt0n"; repo = "github-nvim-theme"; - rev = "62b7b54a90c70c20cd1641f9facfced46bdd3561"; + rev = "ea713c37691b2519f56cd801a2330bdf66393d0f"; sha256 = "0cwr3b5r2ac7aizxmwb3mlhdc2sh0pw670vcwps79x9jp52yrj2y"; }; }; @@ -27,7 +27,6 @@ in { vimAlias = true; plugins = with pkgs.vimPlugins; [ - { plugin = github-theme; config = '' @@ -37,13 +36,15 @@ in { ''; } - lazygit.nvim + { plugin = lazygit.nvim; } + { plugin = LazyVim; config = '' lua << EOF return { {'williamboman/mason.nvim', enabled = false }, + {'williamboman/mason-lspconfig.nvim', enabled = false }, {'nvim-treesitter/nvim-treesitter', enabled = false }, } EOF @@ -65,19 +66,162 @@ in { } { - plugin = nvim-treesitter.withAllGrammars + plugin = nvim-treesitter.withAllGrammars; config = '' lua << EOF - + require'nvim-treesitter.configs'.setup { + highlight = { + enable = true, + }, + } EOF ''; } ]; + + extraLuaConfig = '' + lua << EOF + vim.opt.tabstop = 2 + vim.opt.shiftwidth = 2 + vim.opt.expandtab = true + + vim.o.clipboard = "unnamedplus" + EOF + ''; + + generatedConfigs = { + lua = '' + require("config.lazy") + + local lsp = require("lsp-zero").preset({}) + + lsp.on_attach(function(client, bufnr) + lsp.default_keymaps({ buffer = bufnr }) + end) + + lsp.setup_servers({ + "tsserver", + "eslint", + "hls", + "pyright", + "nil_ls", + "cssls", + "html", + "jsonls", + "diagnosticls", + "lua_ls", + "marksman", + "purescriptls", + "tailwindcss", + "bashls", + }) + + require("lspconfig").lua_ls.setup(lsp.nvim_lua_ls()) + + lsp.setup() + + local cmp = require("cmp") + cmp.setup({ + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + }, + }) + + vim.cmd([[ + au BufRead,BufNewFile *.purs set filetype=purescript + ]]) + + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + local luasnip = require("luasnip") + + cmp.setup({ + enabled = function() + -- disable completion in comments + local context = require("cmp.config.context") + -- keep command mode completion enabled when cursor is in a comment + if vim.api.nvim_get_mode().mode == "c" then + return true + else + return not context.in_treesitter_capture("comment") and not context.in_syntax_group("Comment") + end + end, + mapping = { + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() + -- they way you will only jump inside the snippet region + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + 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" }), + + [""] = cmp.mapping({ + i = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }) + else + fallback() + end + end, + s = cmp.mapping.confirm({ select = true }), + c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), + }), + }, + }) + + vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + -- Disable virtual_text + virtual_text = false, + }) + + require("notify").setup({ + background_colour = "#000000", + }) + ''; + }; }; home.packages = with pkgs; [ + nodePackages.eslint + nodePackages.vscode-langservers-extracted + nodePackages.typescript-language-server + nodePackages.diagnostic-languageserver + nodePackages.pyright + nodePackages.purescript-language-server + nodePackages."@tailwindcss/language-server" + nodePackages.bash-language-server + marksman + nil nixfmt + sumneko-lua-language-server stylua + haskell-language-server hlint ]; }; diff --git a/sysConfig/desktop/default.nix b/sysConfig/desktop/default.nix new file mode 100644 index 0000000..7343235 --- /dev/null +++ b/sysConfig/desktop/default.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + imports = [ + ./hardware.nix + ./system.nix + ]; +} diff --git a/machines/desktop/hardware-configuration.nix b/sysConfig/desktop/hardware.nix similarity index 72% rename from machines/desktop/hardware-configuration.nix rename to sysConfig/desktop/hardware.nix index 7d7d455..13fedf1 100644 --- a/machines/desktop/hardware-configuration.nix +++ b/sysConfig/desktop/hardware.nix @@ -2,17 +2,31 @@ { imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - - nix.system-features = "kvm"; - environment.systemPackages = pkgs.virt-manager; +# Kernel boot.initrd.availableKernelModules = [ "vmd" "xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" ]; boot.initrd.kernelModules = [ "dm-snapshot" ]; boot.extraModulePackages = [ ]; boot.kernelParams = [ "intel_iommu=on" ]; boot.kernelModules = [ "kvm-intel" "virtio" "vfio-pci" "coretemp" ]; boot.kernelPackages = pkgs.linuxPackages_latest; + +# Bootloader + boot.loader = { + grub = { + enable = true; + useOSProber = true; + devices = [ "nodev" ]; + efiSupport = true; + configurationLimit = 5; + }; + efi = { + canTouchEfiVariables = true; + }; + }; + +# FStab fileSystems."/" = { device = "/dev/disk/by-uuid/af24c5b3-8a6e-4333-a61d-922a97928cae"; fsType = "ext4"; @@ -28,6 +42,8 @@ fsType = "vfat"; }; +# GPU + programs.sway.extraOptions = "--unsupported-gpu"; services.xserver.videoDrivers = [ "nvidia" ]; hardware = { opengl.enable = true; @@ -37,6 +53,20 @@ }; }; +# Virtualisation + nix.system-features = "kvm"; + environment.systemPackages = pkgs.virt-manager; + + virtualisation.libvirtd = { + enable = true; + qemu = { + package = pkgs.qemu_kvm; + runAsRoot = true; + ovmf.enable = true; + }; + }; + +# CPU powerManagement.cpuFreqGovernor = lib.mkDefault "performance"; hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; } diff --git a/sysConfig/desktop/partitions.nix b/sysConfig/desktop/partitions.nix new file mode 100644 index 0000000..3b0d215 --- /dev/null +++ b/sysConfig/desktop/partitions.nix @@ -0,0 +1,79 @@ +{ disks ? [ "/dev/nvme0n1" "/dev/sda" ], ... }: { + disko.devices = { + disk = { + one = { + type = "disk"; + device = builtins.elemAt disks 0; + content = { + type = "table"; + format = "gpt"; + partitions = [ + { + name = "boot"; + start = "0"; + end = "100M"; + fs-type = "fat32"; + bootable = true; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + } + { + name = "primary"; + start = "100M"; + end = "100%"; + content = { + type = "lvm_pv"; + vg = "pool"; + }; + } + ]; + }; + }; + }; + + disk = { + two = { + type = "disk"; + device = builtins.elemAt disks 1; + content = { + + } + }; + }; + lvm_vg = { + pool = { + type = "lvm_vg"; + lvs = { + aaa = { + size = "1M"; + }; + zzz = { + size = "1M"; + }; + root = { + size = "100M"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + mountOptions = [ + "defaults" + ]; + }; + }; + home = { + size = "100%FREE"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/home"; + }; + }; + }; + }; + }; + }; +} diff --git a/machines/desktop/system.nix b/sysConfig/desktop/system.nix similarity index 68% rename from machines/desktop/system.nix rename to sysConfig/desktop/system.nix index 58670e7..ed5f38d 100644 --- a/machines/desktop/system.nix +++ b/sysConfig/desktop/system.nix @@ -6,7 +6,6 @@ nix = { extraOptions = "experimental-features = nix-command flakes"; settings = { - allowed-users = "bryan"; auto-optimise-store = true; }; gc = { @@ -22,57 +21,34 @@ security.sudo.wheelNeedsPassword = false; - boot = { - loader = { - grub = { - enable = true; - useOSProber = true; - devices = [ "nodev" ]; - efiSupport = true; - configurationLimit = 5; - }; - - efi = { - canTouchEfiVariables = true; - }; - }; -# extraModprobeConfig = '' -# options vfio-pci ids=10de:1f82,10de:10fa -# ''; - }; - +# GUI programs = { sway = { enable = true; + extraPackages = with pkgs; [ - rofi-wayland - grim - slurp - wl-clipboard + rofi-wayland + grim + slurp + wl-clipboard - xdg-utils + xdg-utils - fontconfig - qogir-icon-theme - emote + fontconfig + qogir-icon-theme + emote + + pavucontrol + ]; - pavucontrol - ]; extraSessionCommands = '' if [ -z "$DISPLAY" ] && [ "$(tty)" = "/dev/tty1" ]; then exec sway fi - - if [ "$XDG_CURRENT_DESKTOP" = "sway" ] ; then - export _JAVA_AWT_WM_NONREPARENTING=1 - fi + export _JAVA_AWT_WM_NONREPARENTING=1 ''; }; - - xwayland = { - enable = true; - }; - + xwayland.enable = true; xdg.portal.wlr.enable = true; gnupg = { @@ -81,8 +57,6 @@ enableSSHSupport = true; }; }; - - git.enable = true; }; services.pipewire = { @@ -109,6 +83,7 @@ ]; }; +# System Services services = { trezord.enable = true; @@ -125,6 +100,7 @@ useXkbConfig = true; }; + # Locale time = { timeZone = "America/New_York"; }; @@ -148,13 +124,4 @@ networkmanager.enable = true; firewall.enable = true; }; - - virtualisation.libvirtd = { - enable = true; - qemu = { - package = pkgs.qemu_kvm; - runAsRoot = true; - ovmf.enable = true; - }; - }; }