diff --git a/.gitmodules b/.gitmodules index c27e9ae..d282180 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,15 @@ [submodule "nvim"] path = src/user/modules/utils/modules/neovim/config/nvim url = https://github.com/itme-brain/nvim.git + [submodule "vim"] - path = src/user/modules/utils/modules/vim/config + path = src/user/modules/utils/modules/vim/vim url = https://github.com/itme-brain/vim.git + [submodule "git"] - path = src/user/modules/git/config + path = src/user/modules/git/git url = https://github.com/itme-brain/git.git + +[submodule "bash"] + path = src/user/modules/bash/config/bash + url = https://github.com/itme-brain/bash.git diff --git a/README.md b/README.md index 96a969a..cc8dc2d 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,25 @@ My modular Nix configs 🔥 NixOS Configurations: `desktop` · `workstation` · `server` (wip) · `vm` · `wsl` +## Fresh Install 🚀 + +From the NixOS live installer: + +```bash +# Enable flakes (not enabled by default on installer) +echo "experimental-features = nix-command flakes" | sudo tee -a /etc/nix/nix.conf + +# Clone repo +nix run nixpkgs#git -- clone --recurse-submodules https://github.com/itme-brain/nixos.git +cd nixos + +# Enter dev shell and install +nix develop +just install desktop +``` + +Replace `desktop` with `workstation` or `vm` as needed. + ## Getting Started 🔧 ```bash diff --git a/justfile b/justfile index e30b07f..ea7aaff 100644 --- a/justfile +++ b/justfile @@ -1,200 +1,54 @@ SYSTEM := "$(echo $HOSTNAME)" +VALID_SYSTEMS := "desktop workstation server wsl vm laptop" # Print this list default: @just --list +# Validate system argument +[private] +_validate SYSTEM: + #!/usr/bin/env bash + case "{{SYSTEM}}" in + desktop|workstation|server|wsl|vm|laptop) ;; + *) echo "Error: Unknown system '{{SYSTEM}}'. Use one of: {{VALID_SYSTEMS}}"; exit 1 ;; + esac + # Clean up build artifacts clean: #!/usr/bin/env bash set -euo pipefail echo "Cleaning build artifacts" - if [ -d result ]; then - echo "Removing result directory..." - rm ./result - fi - if ls *.qcow2 1> /dev/null 2>&1; then - echo "Removing virtual disks..." - rm ./*.qcow2 - fi + rm -f result + rm -f ./*.qcow2 echo "Done" # Output what derivations will be built -out TYPE SYSTEM="desktop": - #!/usr/bin/env bash - set -euo pipefail - case "{{TYPE}}" in - "nix") - if - [ "{{SYSTEM}}" = "desktop" ] || \ - [ "{{SYSTEM}}" = "workstation" ] || \ - [ "{{SYSTEM}}" = "server" ] || \ - [ "{{SYSTEM}}" = "wsl" ] || \ - [ "{{SYSTEM}}" = "vm" ] || \ - [ "{{SYSTEM}}" = "laptop" ] - then - echo "Outputting derivations to be built for NixOS config - {{SYSTEM}}..." - nix build --dry-run .#nixosConfigurations."{{SYSTEM}}".config.system.build.toplevel -L - exit 0 - else - cat <> Reboot to new generation ->>\033[0m" - @echo "Switching to next generation on reboot" @sudo nixos-rebuild boot --flake .#{{SYSTEM}} # Commit all changes and push to upstream @@ -237,6 +86,84 @@ gh COMMIT_MESSAGE: git commit -m "{{COMMIT_MESSAGE}}" git push +# List available disks for installation +disks: + @echo "Available disks:" + @lsblk -d -o NAME,SIZE,MODEL + @echo "" + @echo "Disk IDs (use these for install):" + @ls /dev/disk/by-id/ | grep -E '^(ata|nvme|scsi|usb)' | grep -v 'part' || true + +# Install NixOS from live USB (interactive disk selection) +install SYSTEM: + #!/usr/bin/env bash + set -euo pipefail + + DISKO_CONFIG="./src/system/machines/{{SYSTEM}}/modules/disko/default.nix" + + if [[ ! -f "$DISKO_CONFIG" ]]; then + echo "Error: No disko config for '{{SYSTEM}}'" + echo "Available: desktop, workstation, vm" + exit 1 + fi + + # Build array of disk options with readable info + declare -a DISK_IDS + declare -a DISK_OPTIONS + + for id in /dev/disk/by-id/*; do + name=$(basename "$id") + # Skip partitions and non-disk entries + [[ "$name" =~ part ]] && continue + [[ ! "$name" =~ ^(ata|nvme|scsi)- ]] && continue + + # Resolve to device and get info + dev=$(readlink -f "$id") + dev_name=$(basename "$dev") + size=$(lsblk -dn -o SIZE "$dev" 2>/dev/null) || continue + model=$(lsblk -dn -o MODEL "$dev" 2>/dev/null | xargs) || model="" + + DISK_IDS+=("$id") + DISK_OPTIONS+=("$dev_name $size $model") + done + + if [[ ${#DISK_IDS[@]} -eq 0 ]]; then + echo "No disks found!" + exit 1 + fi + + echo "Select a disk:" + select opt in "${DISK_OPTIONS[@]}"; do + if [[ -n "$opt" ]]; then + idx=$((REPLY - 1)) + DISK="${DISK_IDS[$idx]}" + break + else + echo "Invalid selection" + fi + done + + echo "" + echo -e "\033[31m!! WARNING: This will DESTROY all data on $DISK !!\033[0m" + read -p "Continue? [y/N]: " confirm + case "${confirm,,}" in + y|yes) ;; + *) echo "Aborted."; exit 1 ;; + esac + + echo "Partitioning $DISK..." + sudo nix \ + --extra-experimental-features "nix-command flakes" \ + run github:nix-community/disko -- \ + --mode disko \ + --arg disk "\"$DISK\"" \ + "$DISKO_CONFIG" + + echo "Installing NixOS..." + sudo nixos-install --flake .#{{SYSTEM}} --no-root-passwd + + echo -e "\033[32mDone! Reboot to start NixOS.\033[0m" + # Fetch resources and compute sha256 hash hash URL: #!/usr/bin/env bash diff --git a/src/system/machines/desktop/modules/disko/default.nix b/src/system/machines/desktop/modules/disko/default.nix index 5bf5734..d9943db 100644 --- a/src/system/machines/desktop/modules/disko/default.nix +++ b/src/system/machines/desktop/modules/disko/default.nix @@ -1,16 +1,12 @@ -let - dev = "/dev/disk/by-id/ata-CT2000MX500SSD1_2137E5D2D47D"; - -in +{ disk }: { disko.devices = { disk = { one = { type = "disk"; - device = dev; + device = disk; content = { - type = "table"; - format = "gpt"; + type = "gpt"; partitions = { boot = { size = "1G"; @@ -38,28 +34,18 @@ in nix = { type = "lvm_vg"; lvs = { - aaa = { - size = "1M"; - }; - zzz = { - size = "1M"; - }; root = { - size = "252G"; + size = "5%"; content = { - name = "root"; type = "filesystem"; format = "ext4"; mountpoint = "/"; - mountOptions = [ - "defaults" - ]; + mountOptions = [ "defaults" ]; }; }; home = { size = "100%FREE"; content = { - name = "home"; type = "filesystem"; format = "ext4"; mountpoint = "/home"; diff --git a/src/system/machines/vm/modules/disko/default.nix b/src/system/machines/vm/modules/disko/default.nix index 398129c..5376126 100644 --- a/src/system/machines/vm/modules/disko/default.nix +++ b/src/system/machines/vm/modules/disko/default.nix @@ -1,11 +1,10 @@ -{ disks ? [ "/dev/vda" ], ... }: - +{ disk ? "/dev/vda" }: { disko.devices = { disk = { one = { - device = builtins.elemAt disks 0; type = "disk"; + device = disk; content = { type = "gpt"; partitions = { @@ -17,8 +16,6 @@ format = "vfat"; mountpoint = "/boot"; }; - bootable = true; - priority = 1; }; primary = { size = "100%"; @@ -36,12 +33,6 @@ vm = { type = "lvm_vg"; lvs = { - aaa = { - size = "1M"; - }; - zzz = { - size = "1M"; - }; root = { size = "100%"; content = { diff --git a/src/system/machines/workstation/modules/disko/default.nix b/src/system/machines/workstation/modules/disko/default.nix index 5bf5734..d9943db 100644 --- a/src/system/machines/workstation/modules/disko/default.nix +++ b/src/system/machines/workstation/modules/disko/default.nix @@ -1,16 +1,12 @@ -let - dev = "/dev/disk/by-id/ata-CT2000MX500SSD1_2137E5D2D47D"; - -in +{ disk }: { disko.devices = { disk = { one = { type = "disk"; - device = dev; + device = disk; content = { - type = "table"; - format = "gpt"; + type = "gpt"; partitions = { boot = { size = "1G"; @@ -38,28 +34,18 @@ in nix = { type = "lvm_vg"; lvs = { - aaa = { - size = "1M"; - }; - zzz = { - size = "1M"; - }; root = { - size = "252G"; + size = "5%"; content = { - name = "root"; type = "filesystem"; format = "ext4"; mountpoint = "/"; - mountOptions = [ - "defaults" - ]; + mountOptions = [ "defaults" ]; }; }; home = { size = "100%FREE"; content = { - name = "home"; type = "filesystem"; format = "ext4"; mountpoint = "/home"; diff --git a/src/user/default.nix b/src/user/default.nix index 3c1ebbb..ca18159 100644 --- a/src/user/default.nix +++ b/src/user/default.nix @@ -4,10 +4,15 @@ let entries = builtins.readDir dir; names = builtins.attrNames entries; - isModuleDir = path: + excludedDirs = [ "config" "scripts" ]; + isSubmodule = path: + builtins.pathExists "${path}/.git" && + builtins.readFileType "${path}/.git" == "regular"; + isModuleDir = path: builtins.pathExists path && builtins.readFileType path == "directory" && - builtins.baseNameOf path != "config"; + !(builtins.elem (builtins.baseNameOf path) excludedDirs) && + !(isSubmodule path); isModule = file: file == "default.nix"; isNix = file: builtins.match ".*\\.nix" file != null && file != "default.nix"; diff --git a/src/user/modules/bash/config/alias.nix b/src/user/modules/bash/config/alias.nix deleted file mode 100644 index 321631d..0000000 --- a/src/user/modules/bash/config/alias.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ lib, config, ... }: - -with lib; -let - gui = config.modules.user.gui.wm; - wm = { - enable = builtins.any (mod: mod.enable or false) (builtins.attrValues gui); - }; - -in -{ - cd = "cd -L"; - grep = "grep --color"; - tree = "eza --tree --icons=never"; - lt = mkForce "eza --tree --icons=never"; - open = mkIf wm.enable "xdg-open"; -} diff --git a/src/user/modules/bash/config/bash b/src/user/modules/bash/config/bash new file mode 160000 index 0000000..25d0555 --- /dev/null +++ b/src/user/modules/bash/config/bash @@ -0,0 +1 @@ +Subproject commit 25d055514de104f471c4c36dae83dc835ee006de diff --git a/src/user/modules/bash/config/bashrc.nix b/src/user/modules/bash/config/bashrc.nix deleted file mode 100644 index ee90a14..0000000 --- a/src/user/modules/bash/config/bashrc.nix +++ /dev/null @@ -1,8 +0,0 @@ -'' -set -o vi - -bind 'set completion-ignore-case on' -bind 'set completion-map-case on' - -export TERM=linux -'' diff --git a/src/user/modules/bash/config/prompt.nix b/src/user/modules/bash/config/prompt.nix deleted file mode 100644 index 008cd80..0000000 --- a/src/user/modules/bash/config/prompt.nix +++ /dev/null @@ -1,154 +0,0 @@ -{ config, lib, ... }: - -with lib; -let - git = config.modules.user.git; - gui = config.modules.user.gui.alacritty; - -in -'' -check_ssh() { - if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then - ssh_PS1="\n\[\033[01;37m\]\u@\h:\[\033[00m\]\n" - return 0 - fi -} - -${optionalString git.enable '' -check_venv() { - add_icon() { - local icon=$1 - if [[ ! $venv_icons =~ $icon ]]; then - venv_icons+="$icon " - fi - } - - remove_icon() { - local icon=$1 - venv_icons=''${venv_icons//$icon/} - } - - py="py" - js="js" - nix="nix" - - ${optionalString gui.enable '' - if [ -n "$DISPLAY" ]; then - py="" - js="󰌞" - nix="" - fi - ''} - - python_icon="\[\033[01;33m\]$py\[\033[00m\]" - node_icon="\[\033[01;93m\]$js\[\033[00m\]" - nix_icon="\[\033[01;34m\]$nix\[\033[00m\]" - - if [ -n "$IN_NIX_SHELL" ]; then - add_icon "$nix_icon" - else - remove_icon "$nix_icon" - fi - - if [ -n "$VIRTUAL_ENV" ]; then - add_icon "$python_icon" - else - remove_icon "$python_icon" - fi - - if [ -d "''${git_root}/node_modules" ]; then - add_icon "$node_icon" - else - remove_icon "$node_icon" - fi -} - -set_git_dir() { - ${if gui.enable then '' - if [ -n "$DISPLAY" ]; then - project_icon=" " - else - project_icon="../" - fi - '' else '' - project_icon="../" - ''} - local superproject_root=$(git rev-parse --show-superproject-working-tree 2>/dev/null) - if [[ -n "$superproject_root" ]]; then - local submodule_name=$(basename "$git_root") - - working_dir="\[\033[01;34m\]$project_icon''${superproject_root##*/}/$submodule_name$git_curr_dir\[\033[00m\]" - elif [ "$git_curr_dir" == "." ]; then - working_dir="\[\033[01;34m\]$project_icon$git_root_dir\[\033[00m\]" - return 0 - else - working_dir="\[\033[01;34m\]$project_icon$git_root_dir$git_curr_dir\[\033[00m\]" - return 0 - fi -} - -relative_path() { - local absolute_target=$(readlink -f "$1") - local absolute_base=$(readlink -f "$2") - echo "''${absolute_target#$absolute_base}" -} - -check_project() { - local git_root=$(git rev-parse --show-toplevel 2>/dev/null) - - if [ -n "$git_root" ]; then - local git_branch=$(git branch --show-current 2>/dev/null) - - if [ -z "$git_branch" ]; then - git_branch=$(git describe --tags --exact-match 2>/dev/null) - git_branch=''${git_branch:-$(git rev-parse --short HEAD 2>/dev/null)} - fi - - local git_curr_dir=$(relative_path "." "$git_root") - local git_root_dir=$(basename "$git_root") - - ${if gui.enable then '' - if [ -n "$DISPLAY" ]; then - git_branch_PS1="\[\033[01;31m\]$git_branch 󰘬:\[\033[00m\]" - else - git_branch_PS1="\[\033[01;31m\]$git_branch:\[\033[00m\]" - fi - '' else '' - git_branch_PS1="\[\033[01;31m\]$git_branch:\[\033[00m\]" - ''} - - set_git_dir - check_venv - - return 0 - fi -} -''} - -function set_prompt() { - local green_arrow="\[\033[01;32m\]>> " - local white_text="\[\033[00m\]" - local working_dir="\[\033[01;34m\]\w\[\033[00m\]" - - local ssh_PS1 - - check_ssh - - ${optionalString git.enable '' - local venv_icons - local git_branch_PS1 - - check_project - ''} - - ${if git.enable - then - ''PS1="$ssh_PS1\n$working_dir\n$venv_icons$green_arrow$git_branch_PS1$white_text"'' - else - ''PS1="$ssh_PS1\n$working_dir\n$green_arrow$white_text"'' - } - return 0 -} - -PROMPT_COMMAND="set_prompt" -'' diff --git a/src/user/modules/bash/default.nix b/src/user/modules/bash/default.nix index 601d69a..1dc7110 100644 --- a/src/user/modules/bash/default.nix +++ b/src/user/modules/bash/default.nix @@ -9,13 +9,15 @@ in config = mkIf cfg.enable { programs.bash = { enable = true; - enableCompletion = true; - - initExtra = import ./config/prompt.nix { inherit lib config; }; - bashrcExtra = import ./config/bashrc.nix; - shellAliases = import ./config/alias.nix { inherit lib config; }; + initExtra = "source ~/.config/bash/bashrc"; profileExtra = import ./config/shellHook.nix { inherit lib config; }; }; + + # .bashrc + home.file.".config/bash" = { + source = ./config/bash; + recursive = true; + }; programs = { ripgrep.enable = true; diff --git a/src/user/modules/git/default.nix b/src/user/modules/git/default.nix index ec54b88..26baea5 100644 --- a/src/user/modules/git/default.nix +++ b/src/user/modules/git/default.nix @@ -22,7 +22,7 @@ in git-crypt ]; file.".config/git" = { - source = ./config; + source = ./git; recursive = true; }; }; diff --git a/src/user/modules/git/config b/src/user/modules/git/git similarity index 100% rename from src/user/modules/git/config rename to src/user/modules/git/git diff --git a/src/user/modules/utils/modules/vim/default.nix b/src/user/modules/utils/modules/vim/default.nix index 8805e0f..61cafa1 100644 --- a/src/user/modules/utils/modules/vim/default.nix +++ b/src/user/modules/utils/modules/vim/default.nix @@ -16,7 +16,7 @@ in vim ]; file.".vim" = { - source = ./config; + source = ./vim; recursive = true; }; }; diff --git a/src/user/modules/utils/modules/vim/config b/src/user/modules/utils/modules/vim/vim similarity index 100% rename from src/user/modules/utils/modules/vim/config rename to src/user/modules/utils/modules/vim/vim