{ config, pkgs, lib, inputs, ... }: let homedir = "/home/cspark"; in { # Home Manager needs a bit of information about you and the paths it should # manage. home.username = "cspark"; home.homeDirectory = "${homedir}"; # This value determines the Home Manager release that your configuration is # compatible with. This helps avoid breakage when a new Home Manager release # introduces backwards incompatible changes. # # You should not change this value, even if you update Home Manager. If you do # want to update the value, then make sure to first check the Home Manager # release notes. home.stateVersion = "23.11"; # Please read the comment before changing. # Allow unfree packages nixpkgs.config.allowUnfree = true; # The home.packages option allows you to install Nix packages into your # environment. home.packages = with pkgs; [ # # Adds the 'hello' command to your environment. It prints a friendly # # "Hello, world!" when run. # pkgs.hello # # It is sometimes useful to fine-tune packages, for example, by applying # # overrides. You can do that directly here, just don't forget the # # parentheses. Maybe you want to install Nerd Fonts with a limited number of # # fonts? # (nerd-fonts.override { fonts = [ "FantasqueSansMono" ]; }) # # You can also create simple shell scripts directly inside your # # configuration. For example, this adds a command 'my-hello' to your # # environment: # (writeShellScriptBin "my-hello" '' # echo "Hello, ${config.home.username}!" # '') # Scripts to bind/unbind usbkey from usbip server (pkgs.writeShellScriptBin "usbip_usbkey_bind" '' USBKEYBUSID="$(echo `grep 0930 /sys/bus/usb/devices/*/idVendor | cut -d '/' -f 6`)" sudo usbip bind -b $USBKEYBUSID '') (pkgs.writeShellScriptBin "usbip_usbkey_unbind" '' USBKEYBUSID="$(echo `grep 0930 /sys/bus/usb/devices/*/idVendor | cut -d '/' -f 6`)" sudo usbip unbind -b $USBKEYBUSID '') # Scripts to replace user utils with ones that can interface with the neovim inbuilt terminal (pkgs.writeShellScriptBin "cd-nvim" '' if [ "$1" ]; then builtin cd "''$(realpath "$1")" && printf "\033]7;file://''${PWD}\033\\" else builtin cd "''${HOME}" && printf "\033]7;file://''${PWD}\033\\" fi '') # Version for zoxide (pkgs.writeShellScriptBin "z-nvim" '' if [ "$1" ]; then builtin-z "''${1}" && printf "\033]7;file://''${PWD}\033\\" else builtin-z "''${HOME}" && printf "\033]7;file://''${PWD}\033\\" fi '') (pkgs.writeShellScriptBin "zi-nvim" '' if [ "$1" ]; then builtin-zi "''${1}" && printf "\033]7;file://''${PWD}\033\\" else builtin-zi "''${HOME}" && printf "\033]7;file://''${PWD}\033\\" fi '') # Setup mail (pkgs.writeShellScriptBin "mu-mail-init" '' mu init --maildir=~/Mail --my-address=work@cspark.dev --my-address=services@cspark.dev --my-address=personal@cspark.dev --my-address=alerts@cspark.dev--my-address=services@tuxtank.dev --my-address=alerts@tuxtank.dev '') # Re-encode a video to a target size in MB using ffmpeg. (pkgs.writeShellScriptBin "vidresize" '' # Re-encode a video to a target size in MB. # Example: # ./this_script.sh video.mp4 15 T_SIZE="$2" # target size in MB T_FILE="''${1%.*}-$2MB.mp4" # filename out # Original duration in seconds O_DUR=$(\ ffprobe \ -v error \ -show_entries format=duration \ -of csv=p=0 "$1") # Original audio rate O_ARATE=$(\ ffprobe \ -v error \ -select_streams a:0 \ -show_entries stream=bit_rate \ -of csv=p=0 "$1") # Original audio rate in KiB/s O_ARATE=$(\ awk \ -v arate="$O_ARATE" \ 'BEGIN { printf "%.0f", (arate / 1024) }') # Target size is required to be less than the size of the original audio stream T_MINSIZE=$(\ awk \ -v arate="$O_ARATE" \ -v duration="$O_DUR" \ 'BEGIN { printf "%.2f", ( (arate * duration) / 8192 ) }') # Equals 1 if target size is ok, 0 otherwise IS_MINSIZE=$(\ awk \ -v size="$T_SIZE" \ -v minsize="$T_MINSIZE" \ 'BEGIN { print (minsize < size) }') # Give useful information if size is too small if [[ $IS_MINSIZE -eq 0 ]]; then printf "%s\n" "Target size ''${T_SIZE}MB is too small!" >&2 printf "%s %s\n" "Try values larger than" "''${T_MINSIZE}MB" >&2 exit 1 fi # Set target audio bitrate T_ARATE=$O_ARATE # Calculate target video rate - MB -> KiB/s T_VRATE=$(\ awk \ -v size="$T_SIZE" \ -v duration="$O_DUR" \ -v audio_rate="$O_ARATE" \ 'BEGIN { print ( ( size * 8192.0 ) / ( 1.048576 * duration ) - audio_rate) }') # Perform the conversion ffmpeg \ -y \ -i "$1" \ -c:v libx264 \ -b:v "$T_VRATE"k \ -pass 1 \ -an \ -f mp4 \ /dev/null \ && \ ffmpeg \ -i "$1" \ -c:v libx264 \ -b:v "$T_VRATE"k \ -pass 2 \ -c:a aac \ -b:a "$T_ARATE"k \ "$T_FILE" '') ]; # Home Manager is pretty good at managing dotfiles. The primary way to manage # plain files is through 'home.file'. home.file = { # # Building this configuration will create a copy of 'dotfiles/screenrc' in # # the Nix store. Activating the configuration will then make '~/.screenrc' a # # symlink to the Nix store copy. # ".screenrc".source = dotfiles/screenrc; # # You can also set the file content immediately. # ".gradle/gradle.properties".text = '' # org.gradle.console=verbose # org.gradle.daemon.idletimeout=3600000 # ''; # ".local/share/applications/ncmpcpp.desktop".text = '' # [Desktop Entry] # Name=NCMPCPP # Comment=Run ncurses music player CPP # Categories=Other; # Icon=konsole # Type=Application # Exec=konsole -e ncmpcpp # Terminal=false # ''; # Inputrc file for VI mode ".inputrc".source = ./global-resources/home-manager/.inputrc; # Global Wallpapers "Pictures/Wallpapers".source = ./global-resources/home-manager/Pictures/Wallpapers; # MPDCRON Configuration ".mpdcron/mpdcron.conf".source = ./global-resources/home-manager/.mpdcron/mpdcron.conf; ".mpdcron/hooks/player".source = ./global-resources/home-manager/.mpdcron/hooks/player; # MU4E Mail ".mbsyncrc".source = ./global-resources/home-manager/.mbsyncrc; }; xdg = { enable = true; configFile = { # Fastfetch Configuration "fastfetch/config.jsonc".source = ./global-resources/home-manager/.config/fastfetch/config.jsonc; "fastfetch/sunlogo1.txt".source = ./global-resources/home-manager/.config/fastfetch/sunlogo1.txt; "fastfetch/sunlogo2.txt".source = ./global-resources/home-manager/.config/fastfetch/sunlogo2.txt; # Chawan Configuration "chawan/config.toml".source = ./global-resources/home-manager/.config/chawan/config.toml; # Custom Keyboard Layout Configuration # Standalone XKB "xkb/engrammer.xkb".source = ./global-resources/home-manager/.config/xkb/engrammer.xkb; # Symbol "xkb/symbols/engrammer".source = ./global-resources/home-manager/.config/xkb/symbols/engrammer; "xkb/symbols/canary".source = ./global-resources/home-manager/.config/xkb/symbols/canary; # Wl Kbptr Configuration "wl-kbptr/config".source = ./global-resources/home-manager/.config/wl-kbptr/config; }; }; # Have to enable the mpd and mpd-discord-rpc user services manually for now #services.mpd = { # enable = true; # musicDirectory = "${homedir}/Spool2_Secret/Music/Flac"; # network.startWhenNeeded = true; # extraConfig = '' # audio_output { # type "pipewire" # name "PipeWire Output" # } # ''; #}; services.mpd-discord-rpc.enable = true; #programs.ncmpcpp.enable = true; # Alternatively, Mopidy over MPD services.mopidy = let mopidyPackagesOverride = pkgs.mopidyPackages.overrideScope (prev: final: { extraPkgs = pkgs: [ pkgs.yt-dlp ]; }); in { enable = true; extensionPackages = with mopidyPackagesOverride; [ mopidy-local mopidy-mpd mopidy-youtube ]; settings = { logging = { verbosity = 1; }; audio = { output = "pulsesink server=127.0.0.1"; }; file = { enabled = false; }; local = { enabled = true; media_dir = "${homedir}/Spool2_Secret/Music/Flac"; library = "sqlite"; }; mpd = { enabled = true; hostname = "::"; command_blacklist = ""; }; youtube = { enabled = true; youtube_dl_package = "yt_dlp"; }; }; }; systemd.user.services.mopidy-scan.Install.WantedBy = lib.mkForce []; # Home Manager is pretty good at managing dotfiles. The primary way to manage # plain files is through 'home.file'. home.file = { # # Building this configuration will create a copy of 'dotfiles/screenrc' in # # the Nix store. Activating the configuration will then make '~/.screenrc' a # # symlink to the Nix store copy. # ".screenrc".source = dotfiles/screenrc; # # You can also set the file content immediately. # ".gradle/gradle.properties".text = '' # org.gradle.console=verbose # org.gradle.daemon.idletimeout=3600000 # ''; ".local/share/applications/ncmpcpp.desktop".source = ./global-resources/home-manager/.local/share/applications/ncmpcpp.desktop; ".local/share/applications/yazi.desktop".source = ./global-resources/home-manager/.local/share/applications/yazi.desktop; ".local/share/applications/yt-x.desktop".source = ./global-resources/home-manager/.local/share/applications/yt-x.desktop; ".local/share/applications/chawan.desktop".source = ./global-resources/home-manager/.local/share/applications/chawan.desktop; ".local/share/applications/librewolf-work.desktop".source = ./global-resources/home-manager/.local/share/applications/librewolf-work.desktop; #".local/share/applications/vieb.desktop".source = ./global-resources/home-manager/.local/share/applications/vieb.desktop; #".local/share/applications/arch-nyxt-gstfix.desktop".source = ./global-resources/home-manager/.local/share/applications/arch-nyxt-gstfix.desktop; #".local/share/applications/arch-nyxt-run-gstfix.sh".source = ./global-resources/home-manager/.local/share/applications/arch-nyxt-run-gstfix.sh; #".local/share/applications/Arch-steam.desktop".source = ./global-resources/home-manager/.local/share/applications/Arch-steam.desktop; }; # Emacs Config Init Service systemd.user.services.emacs-config-initialiser = let script = pkgs.writeShellScript "emacs-config-initialiser-script" '' if [[ ! -d $HOME/.emacs.d ]]; then mkdir -p $HOME/.emacs.d git clone https://git.cspark.dev/cspark/Emacs-Configuration-Modern $HOME/.emacs.d else exit 0 fi ''; in { Unit = { Description = "Initialises default emacs configuration if not available"; }; Service = { ExecStart = "${script}"; }; Install = { WantedBy = [ "default.target" ]; }; }; # Neovim Config Init Service systemd.user.services.neovim-config-initialiser = let script = pkgs.writeShellScript "neovim-config-initialiser-script" '' if [[ ! -d $HOME/.config/nvim ]]; then mkdir -p $HOME/.config/nvim git clone https://git.cspark.dev/cspark/Neovim-Configuration $HOME/.config/nvim else exit 0 fi ''; in { Unit = { Description = "Initialises default neovim configuration if not available"; }; Service = { ExecStart = "${script}"; }; Install = { WantedBy = [ "default.target" ]; }; }; # Emacs install and enable daemon/server mode. Set to use unstable pure gtk branch (From emacs-overlay) #services.emacs = { # enable = true; # package = pkgs.emacs-gtk; #}; # MPDCRON to automate MPD related events, using it to automatically restart mpd-discord-rpc service to solve issues systemd.user.services.mpdcron = let script = pkgs.writeShellScript "mpdcron-script" '' mpdcron -n ''; in { Unit = { Description = "Start MPDCRON on boot"; }; Service = { ExecStart = "${script}"; Environment = "PATH=${inputs.nixpkgs-stable.legacyPackages.x86_64-linux.mpdcron}/bin:${pkgs.systemd}/bin"; }; Install = { WantedBy = [ "default.target" ]; }; }; # Home Manager can also manage your environment variables through # 'home.sessionVariables'. If you don't want to manage your shell through Home # Manager then you have to manually source 'hm-session-vars.sh' located at # either # # ~/.nix-profile/etc/profile.d/hm-session-vars.sh # # or # # ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh # # or # # /etc/profiles/per-user/cspark/etc/profile.d/hm-session-vars.sh # # Add custom directories to $PATH home.sessionPath = [ "$HOME/.dotnet/tools" ]; home.sessionVariables = { EDITOR = "emacsclient -r"; # EDITOR = "nvim"; # Dotnet path not found fix DOTNET_ROOT = "${pkgs.dotnet-sdk}"; }; programs.bash = { enable = true; enableCompletion = true; # bashrcExtra = "fastfetch"; initExtra = '' . "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" # Nicer terminal prompt export PS1="\[\e[0;36m\]\u\[\e[0m\]@\[\e[0;33m\]\h\[\e[0m\]:\[\e[0;35m\]\w\[\e[0m\] \$ "; eval "$(zoxide init bash --cmd builtin-z)" # Initialise zoxide as terminal command builtin-z # To be set if inside distrobox, ensures all applications work correctly. They should use distrobox libs/binaries instead of systems. if [[ -n $DISTROBOX_ENTER_PATH ]]; then # Set your locale variables and export them export PATH=/usr/bin:$PATH export LD_LIBRARY_PATH=/usr/lib64:/usr/lib:/usr/lib32:$LD_LIBRARY_PATH # This is specific to AMD GPUs export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/radeon_icd.x86_64.json:/usr/share/vulkan/icd.d/radeon_icd.i686.json fi ([[ -z $(tty) ]] && nvim +terminal) || fastfetch ''; shellAliases = { sudo = "sudo "; doas = "doas "; edit = "$EDITOR"; # Override the default cd and z (zoxide) terminal commands to ensure to add our custom hooks onto it for neovim integration #cd = "source cd-nvim"; z = "source z-nvim"; #cd = "source z-nvim"; # Now will use z (zoxide) as the default cd command instead zi = "source zi-nvim"; #cdi = "source zi-nvim"; # A smarter, better "cp" cp2 = "rsync -ah --info=progress2"; }; }; programs.git = { enable = true; userName = "cspark"; userEmail = "git@cspark.dev"; extraConfig = { safe = { directory = "/etc/nixos"; }; }; }; # Let Home Manager install and manage itself. programs.home-manager.enable = true; }