From 91a72346057e058cb772ab7b330cd4d3484ab21b Mon Sep 17 00:00:00 2001 From: Bryan Ramos Date: Sun, 4 Jun 2023 14:44:58 -0400 Subject: [PATCH] Further refactoring --- flake.nix | 17 +- machines/desktop/default.nix | 7 + machines/desktop/hardware-configuration.nix | 3 + machines/desktop/me.nix | 10 - machines/desktop/system.nix | 243 ++++++++++++++++++++ modules/git/default.nix | 19 ++ modules/system/configuration.nix | 159 ------------- modules/template.nix | 10 + 8 files changed, 290 insertions(+), 178 deletions(-) create mode 100644 machines/desktop/default.nix delete mode 100644 machines/desktop/me.nix create mode 100644 machines/desktop/system.nix create mode 100644 modules/git/default.nix delete mode 100644 modules/system/configuration.nix create mode 100644 modules/template.nix diff --git a/flake.nix b/flake.nix index 6d548d7..4d4df0d 100644 --- a/flake.nix +++ b/flake.nix @@ -31,17 +31,16 @@ in { nixosConfigurations.socrates = nixpkgs.lib.nixosSystem { - inherit system; - modules = [ - ./sysConfig - disko.nixosModules.disko - ]; - }; - - homeConfigurations.bryan = home-manager.lib.homeManagerConfiguration { inherit pkgs; modules = [ - ./homeConfig/home.nix + ./machines/hardware-configuration.nix + ./machines/system.nix + disko.nixosModules.disko + home-manager.nixosModules.home-manager{ + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.bryan = import ./homeConfig/home.nix; + } ]; }; }; diff --git a/machines/desktop/default.nix b/machines/desktop/default.nix new file mode 100644 index 0000000..28a6ea5 --- /dev/null +++ b/machines/desktop/default.nix @@ -0,0 +1,7 @@ +{ pkgs, lib, config, ... }: + +{ + import = [ + ./. + ]; +} diff --git a/machines/desktop/hardware-configuration.nix b/machines/desktop/hardware-configuration.nix index 985e26a..7d7d455 100644 --- a/machines/desktop/hardware-configuration.nix +++ b/machines/desktop/hardware-configuration.nix @@ -2,6 +2,9 @@ { imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + + nix.system-features = "kvm"; + environment.systemPackages = pkgs.virt-manager; boot.initrd.availableKernelModules = [ "vmd" "xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" ]; boot.initrd.kernelModules = [ "dm-snapshot" ]; diff --git a/machines/desktop/me.nix b/machines/desktop/me.nix deleted file mode 100644 index 86f38a0..0000000 --- a/machines/desktop/me.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ config, pkgs, lib, ... }: - -{ - users.users.bryan = { - isNormalUser = true; - extraGroups = [ "wheel" "networkmanager" "home-manager" "input" "video" "audio" "kvm" "libvirtd" "docker" ]; - }; - - security.sudo.wheelNeedsPassword = false; -} diff --git a/machines/desktop/system.nix b/machines/desktop/system.nix new file mode 100644 index 0000000..60415c7 --- /dev/null +++ b/machines/desktop/system.nix @@ -0,0 +1,243 @@ +{ pkgs, lib, config, ... }: +{ + system.stateVersion = "23.05"; + environment.defaultPackages = [ ]; + + nix = { + extraOptions = "experimental-features = nix-command flakes"; + settings = { + allowed-users = "bryan"; + auto-optimise-store = true; + }; + gc = { + automatics = true; + options = "weekly"; + }; + }; + + users.users.bryan = { + isNormalUser = true; + extraGroups = [ "wheel" "networkmanager" "home-manager" "input" "video" "audio" "kvm" "libvirtd" "docker" ]; + }; + + 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 +# ''; + }; + + programs = { + sway = { + enable = true; + extraPackages = with pkgs; [ + rofi-wayland + grim + slurp + wl-clipboard + + xdg-utils + + fontconfig + qogir-icon-theme + emote + + pavucontrol + ]; + }; + + xwayland = { + enable = true; + }; + + bash = { + enable = true; + enableCompletion = true; + enableLsColors = true; + blesh.enable = true; + + shellInit = '' + if [ -z "$DISPLAY" ] && [ "$(tty)" = "/dev/tty1" ]; then + exec sway + fi + + if [ "$XDG_CURRENT_DESKTOP" = "sway" ] ; then + # https://github.com/swaywm/sway/issues/595 + export _JAVA_AWT_WM_NONREPARENTING=1 + fi + + export EDITOR=nvim + eval "$(direnv hook bash)" + ''; + + promptInit = '' + # Check if the current shell is an SSH session + is_ssh_session() { + if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then + return 0 + else + return 1 + fi + } + + # PS1 Config + function set_ps1_prompt() { + local git_branch="" + local flake_icon="" + local cur_dir="" + + # Check if we're inside a git repository + if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + # If we are, get the current branch name + git_branch="$(git symbolic-ref --short HEAD 2>/dev/null)" + + # If the command failed, we're in a detached HEAD state, so get the short SHA + if [ $? -ne 0 ]; then + git_branch="$(git rev-parse --short HEAD 2>/dev/null)" + fi + + # Wrap the branch name and : in braces and color it red + git_branch=" \[\033[01;31m\]$git_branch󰘬:\[\033[00m\]" + + # Check if flake.nix file exists + if [ -f "$(git rev-parse --show-toplevel)/flake.nix" ]; then + # If it exists, set the flake icon and color it blue + flake_icon="\[\033[01;34m\] \[\033[00m\]" + fi + + # Get the root directory of the git repository + git_root="$(basename "$(git rev-parse --show-toplevel)")" + + # Get the current directory relative to the Git root + cur_dir=$(realpath --relative-to=$(git rev-parse --show-toplevel) .) + if [ "$cur_dir" == "." ]; then + cur_dir="\[\033[01;34m\] $git_root\[\033[00m\]" + else + cur_dir="\[\033[01;34m\] $git_root/$cur_dir\[\033[00m\]" + fi + else + # If not in a Git repository, just show the normal path + cur_dir="\[\033[01;34m\]\w\[\033[00m\]" + fi + + if [ -n "${IN_NIX_SHELL:+x}" ]; then + PS1="$cur_dir\n$flake_icon\[\033[01;32m\]nixShell>$git_branch\[\033[00m\]" + else + if ! is_ssh_session; then + PS1="\n$cur_dir\n$flake_icon\[\033[01;32m\]>$git_branch\[\033[00m\]" + else + PS1="\n\[\033[01;34m\]\w\[\033[00m\]\n\[\033[01;32m\]\u@\h:\[\033[00m\] " + fi + fi + unset flake_icon + } + + PROMPT_COMMAND="set_ps1_prompt; $PROMPT_COMMAND" + ''; + + shellAliases = { + ls = "lsd"; + hmup="home-manager switch --flake '$HOME/Documents/projects/nixos#bryan'"; + nixup="sudo nixos-rebuild switch --flake '$HOME/Documents/projects/nixos#socrates'"; + }; + }; + + gnupg = { + agent = { + enable = true; + enableSSHSupport = true; + }; + }; + + git.enable = true; + }; + + fonts = { + fonts = with pkgs; [ + terminus_font + nerdfonts + + noto-fonts + noto-fonts-cjk + + emojione + ]; + }; + + xdg.portal.wlr.enable = true; + + services.pipewire = { + enable = true; + audio.enable = true; + + wireplumber.enable = true; + + pulse.enable = true; + jack.enable = true; + alsa.enable = true; + alsa.support32Bit = true; + }; + + services = { + trezord.enable = true; + + cron = { + enable = true; + systemCronJobs = [ + "0 0 * * * bryan /home/bryan/Documents/scripts/lnbackup_script.sh" + ]; + }; + }; + + console = { + font = "Lat2-Terminus16"; + useXkbConfig = true; + }; + + time = { + timeZone = "America/New_York"; + }; + + services.timesyncd = { + enable = true; + servers = [ + "0.pool.ntp.org" + "1.pool.ntp.org" + "2.pool.ntp.org" + "3.pool.ntp.org" + ]; + }; + + i18n.defaultLocale = "en_US.UTF-8"; + + # Networking + networking = { + hostName = "socrates"; + useDHCP = lib.mkDefault true; + networkmanager.enable = true; + firewall.enable = true; + }; + + virtualisation.libvirtd = { + enable = true; + qemu = { + package = pkgs.qemu_kvm; + runAsRoot = true; + ovmf.enable = true; + }; + }; +} diff --git a/modules/git/default.nix b/modules/git/default.nix new file mode 100644 index 0000000..2167008 --- /dev/null +++ b/modules/git/default.nix @@ -0,0 +1,19 @@ +{ pkgs, lib, config, ... }: + +with lib; +let cfg = config.modules.git; + +in +{ + options.modules.git = { enable = mkEnableOption "git"; }; + config = mkIf cfg.enable { + programs.git = { + enable = true; + userName = "Bryan Ramos"; + userEmail = "bryan@ramos.codes"; + extraConfig = { + init = { defaultBranch = "main"; }; + }; + }; + }; +} diff --git a/modules/system/configuration.nix b/modules/system/configuration.nix deleted file mode 100644 index 86d7523..0000000 --- a/modules/system/configuration.nix +++ /dev/null @@ -1,159 +0,0 @@ -{ config, pkgs, lib, ... }: -{ - system.stateVersion = "23.05"; - environment.defaultPackages = [ ]; - - nix = { - extraOptions = "experimental-features = nix-command flakes"; - settings = { - allowed-users = "bryan"; - auto-optimise-store = true; - system-features = [ - "kvm" - ]; - }; - gc = { - automatics = true; - options = "weekly"; - }; - }; - - 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 -# ''; - }; - - programs = { - sway = { - enable = true; - extraPackages = with pkgs; [ - rofi-wayland - grim - slurp - wl-clipboard - - xdg-utils - - fontconfig - qogir-icon-theme - emote - - virt-manager - pavucontrol - ]; - }; - - bash = { - enable = true; - enableCompletion = true; - enableLsColors = true; - blesh.enable = true; - - shellInit = '' - - ''; - }; - - gnupg = { - agent = { - enable = true; - enableSSHSupport = true; - }; - }; - - xwayland = { - enable = true; - }; - - git.enable = true; - }; - - fonts = { - fonts = with pkgs; [ - terminus_font - nerdfonts - - noto-fonts - noto-fonts-cjk - - emojione - ]; - }; - - xdg.portal.wlr.enable = true; - - services.pipewire = { - enable = true; - audio.enable = true; - - wireplumber.enable = true; - - pulse.enable = true; - jack.enable = true; - alsa.enable = true; - alsa.support32Bit = true; - }; - - services = { - trezord.enable = true; - - cron = { - enable = true; - systemCronJobs = [ - "0 0 * * * bryan /home/bryan/Documents/scripts/lnbackup_script.sh" - ]; - }; - }; - - console = { - font = "Lat2-Terminus16"; - useXkbConfig = true; - }; - - time = { - timeZone = "America/New_York"; - }; - - services.timesyncd = { - enable = true; - servers = [ - "0.pool.ntp.org" - "1.pool.ntp.org" - "2.pool.ntp.org" - "3.pool.ntp.org" - ]; - }; - - i18n.defaultLocale = "en_US.UTF-8"; - - # Networking - networking = { - hostName = "socrates"; - useDHCP = lib.mkDefault true; - networkmanager.enable = true; - firewall.enable = true; - }; - - virtualisation.libvirtd = { - enable = true; - qemu = { - package = pkgs.qemu_kvm; - runAsRoot = true; - ovmf.enable = true; - }; - }; -} diff --git a/modules/template.nix b/modules/template.nix new file mode 100644 index 0000000..ce7f29b --- /dev/null +++ b/modules/template.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 { + }; +}