From 5a083da9bf475a30996541230777997fd98904aa Mon Sep 17 00:00:00 2001 From: cspark Date: Mon, 5 Aug 2024 17:36:13 +0100 Subject: [PATCH] Init new configuration --- README.org | 3 + configurations/macos/home.nix | 130 +++++++++++ configurations/wsl/home.nix | 191 +++++++++++++++ .../wsl/resources/home-manager/.inputrc | 12 + .../.local/share/applications/ncmpcpp.desktop | 8 + .../.local/share/applications/vieb.desktop | 9 + .../.local/share/applications/yazi.desktop | 10 + .../home-manager/.mpdcron/hooks/player | 3 + .../home-manager/.mpdcron/mpdcron.conf | 31 +++ flake.lock | 39 +++- flake.nix | 166 ++++--------- global-home.nix | 218 ++++++++++++++++++ global-resources/home-manager/.inputrc | 12 + 13 files changed, 698 insertions(+), 134 deletions(-) create mode 100644 README.org create mode 100644 configurations/macos/home.nix create mode 100644 configurations/wsl/home.nix create mode 100644 configurations/wsl/resources/home-manager/.inputrc create mode 100644 configurations/wsl/resources/home-manager/.local/share/applications/ncmpcpp.desktop create mode 100644 configurations/wsl/resources/home-manager/.local/share/applications/vieb.desktop create mode 100644 configurations/wsl/resources/home-manager/.local/share/applications/yazi.desktop create mode 100755 configurations/wsl/resources/home-manager/.mpdcron/hooks/player create mode 100644 configurations/wsl/resources/home-manager/.mpdcron/mpdcron.conf create mode 100644 global-home.nix create mode 100644 global-resources/home-manager/.inputrc diff --git a/README.org b/README.org new file mode 100644 index 0000000..d97ef83 --- /dev/null +++ b/README.org @@ -0,0 +1,3 @@ +* Bootstrap + +Clone this git repository into directory ~/.config/home-manager diff --git a/configurations/macos/home.nix b/configurations/macos/home.nix new file mode 100644 index 0000000..14ec8b1 --- /dev/null +++ b/configurations/macos/home.nix @@ -0,0 +1,130 @@ + +{ pkgs, ... }: + +{ + networking.computerName = "cspark-macos-desktop"; + networking.hostName = "cspark-macos-desktop"; + networking.localHostName = "cspark-macos-desktop"; + + nixpkgs.config.allowUnfree = true; + + # Nix packages. + environment.systemPackages = with pkgs; [ + git + unrar + pass + fastfetch + neovim + yt-dlp + qbittorrent + emacs + neovim + discord + ]; + + # Homebrew configuration and packages. + homebrew.enable = true; + # Homebrew formulae + homebrew.brews = [ + ]; + # Homebrew casks + homebrew.casks = [ + "steam" + "librewolf" + # "eloston-chromium" # Ungoogled Chromium + "chromium" + # "blackhole-2ch" # Virtual Audio driver that I'm using alongside the builtin Mac audio routing (Multi-Output/Aggregate + ]; + + services.yabai = { + enable = true; + config = { + external_bar = "off:40:0"; + menubar_opacity = 1.0; + mouse_follows_focus = "off"; + focus_follows_mouse = "off"; + display_arrangement_order = "default"; + window_origin_display = "default"; + window_placement = "second_child"; + window_zoom_persist = "on"; + window_shadow = "on"; + window_animation_duration = 0.0; + window_animation_easing = "ease_out_circ"; + window_opacity_duration = 0.0; + active_window_opacity = 1.0; + normal_window_opacity = 0.90; + window_opacity = "off"; + insert_feedback_color = "0xffd75f5f"; + split_ratio = 0.50; + split_type = "auto"; + auto_balance = "off"; + top_padding = 12; + bottom_padding = 12; + left_padding = 12; + right_padding = 12; + window_gap = 06; + layout = "bsp"; + mouse_modifier = "fn"; + mouse_action1 = "move"; + mouse_action2 = "resize"; + mouse_drop_action = "swap"; + }; + }; + services.skhd = { + enable = true; + skhdConfig = '' + cmd - return : open -a Terminal "`pwd`" + ''; + }; + + + # Auto upgrade nix package and the daemon service. + services.nix-daemon.enable = true; + # nix.package = pkgs.nix; + + # Necessary for using flakes on this system. + nix.settings.experimental-features = "nix-command flakes"; + + # Create /etc/zshrc that loads the nix-darwin environment. + # programs.zsh.enable = true; # default shell on catalina + # programs.fish.enable = true; + programs.bash = { + enable = true; + enableCompletion = true; + interactiveShellInit = '' + export PS1="\[\e[92;40m\]\h\[\e[m\]:\[\e[93m\]\W\[\e[m\] \\$ " + cd ~ + neofetch + ''; + }; + environment.shellAliases = { + edit = "emacs -nw"; + nix-darwin-rebuild-system-flake = "nix run nix-darwin -- switch --flake ~/.config/nix-darwin#desktop"; + }; + + # Set Git commit hash for darwin-version. + system.configurationRevision = self.rev or self.dirtyRev or null; + + # Used for backwards compatibility, please read the changelog before changing. + # $ darwin-rebuild changelog + system.stateVersion = 4; + + # The platform the configuration will be used on. + nixpkgs.hostPlatform = "x86_64-darwin"; + }; + in + { + # Build darwin flake using: + # $ darwin-rebuild build --flake .#Curts-Mac-Pro + darwinConfigurations = { + desktop = nix-darwin.lib.darwinSystem { + specialArgs = {inherit inputs;}; + modules = [ + configuration + ]; + }; + }; + + # Expose the package set, including overlays, for convenience. + darwinPackages = self.darwinConfigurations.desktop-macos.pkgs; + }; diff --git a/configurations/wsl/home.nix b/configurations/wsl/home.nix new file mode 100644 index 0000000..fcf6015 --- /dev/null +++ b/configurations/wsl/home.nix @@ -0,0 +1,191 @@ +{ config, pkgs, home, ... }: + +let + homedir = "/home/cspark"; +in +{ + # 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? + # (pkgs.nerdfonts.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: + # (pkgs.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 + '') + ]; + + # 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 + # ''; + + # MPDCRON Configuration + ".mpdcron/mpdcron.conf".source = ./resources/home-manager/.mpdcron/mpdcron.conf; + ".mpdcron/hooks/player".source = ./resources/home-manager/.mpdcron/hooks/player; + }; + + # 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; + + # Home Manager can also manage your environment variables through + # 'home.sessionVariables'. These will be explicitly sourced when using a + # shell provided by Home Manager. 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 + # + home.sessionVariables = { + # EDITOR = "emacs"; + }; + + programs.bash = { + # bashrcExtra = "fastfetch"; + shellAliases = { + nix-rebuild-system-flake = "home-manager switch --flake ~/.config/home-manager#wsl"; + }; + initExtra = '' + [ -z "$(ps -f ''${PPID} | grep nvim)" ] && nvim +terminal + ''; + bashrcExtra = '' +# set a fancy prompt (non-color, unless we know we "want" color) +case "$TERM" in + xterm-color|*-256color) color_prompt=yes;; +esac + +# uncomment for a colored prompt, if the terminal has the capability; turned +# off by default to not distract the user: the focus in a terminal window +# should be on the output of commands, not on the prompt +#force_color_prompt=yes + +if [ -n "$force_color_prompt" ]; then + if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then + # We have color support; assume it's compliant with Ecma-48 + # (ISO/IEC-6429). (Lack of such support is extremely rare, and such + # a case would tend to support setf rather than setaf.) + color_prompt=yes + else + color_prompt= + fi +fi + +if [ "$color_prompt" = yes ]; then + PS1="''${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ " +else + PS1="''${debian_chroot:+($debian_chroot)}\u@\h:\w\$ " +fi +unset color_prompt force_color_prompt + +# enable color support of ls and also add handy aliases +if [ -x /usr/bin/dircolors ]; then + test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" + alias ls='ls --color=auto' + #alias dir='dir --color=auto' + #alias vdir='vdir --color=auto' + + alias grep='grep --color=auto' + alias fgrep='fgrep --color=auto' + alias egrep='egrep --color=auto' +fi + ''; + }; + + # 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 $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" ]; + }; + }; + +} diff --git a/configurations/wsl/resources/home-manager/.inputrc b/configurations/wsl/resources/home-manager/.inputrc new file mode 100644 index 0000000..0565daf --- /dev/null +++ b/configurations/wsl/resources/home-manager/.inputrc @@ -0,0 +1,12 @@ +set editing-mode vi +set show-mode-in-prompt on +set vi-ins-mode-string "\e[1;30;104mInsert\e[m \1\e[6 q\2" +set vi-cmd-mode-string "\e[1;30;107mNormal\e[m \1\e[2 q\2" + +# Duration to wait before escaping out of Insert mode on Esc keypress +set keyseq-timeout 0 + +# optionally: +# switch to block cursor before executing a command +set keymap vi-insert +RETURN: "\e\n" diff --git a/configurations/wsl/resources/home-manager/.local/share/applications/ncmpcpp.desktop b/configurations/wsl/resources/home-manager/.local/share/applications/ncmpcpp.desktop new file mode 100644 index 0000000..eab278b --- /dev/null +++ b/configurations/wsl/resources/home-manager/.local/share/applications/ncmpcpp.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=NCMPCPP +Comment=Run ncurses music player CPP +Categories=Other; +Icon=konsole +Type=Application +Exec=sh -c "$TERM -e ncmpcpp" +Terminal=false diff --git a/configurations/wsl/resources/home-manager/.local/share/applications/vieb.desktop b/configurations/wsl/resources/home-manager/.local/share/applications/vieb.desktop new file mode 100644 index 0000000..c48ef8f --- /dev/null +++ b/configurations/wsl/resources/home-manager/.local/share/applications/vieb.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Categories=Network;WebBrowser +Exec=vieb --enable-features=UseOzonePlatform --ozone-platform=wayland %U +GenericName=Vieb Web Browser +Icon=vieb +MimeType=text/html;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https +Name=Vieb Web Browser +Type=Application +Version=1.4 diff --git a/configurations/wsl/resources/home-manager/.local/share/applications/yazi.desktop b/configurations/wsl/resources/home-manager/.local/share/applications/yazi.desktop new file mode 100644 index 0000000..76f7145 --- /dev/null +++ b/configurations/wsl/resources/home-manager/.local/share/applications/yazi.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=Yazi File Manager +Icon=yazi +Comment=Blazing fast terminal file manager written in Rust, based on async I/O +Terminal=false +Exec=sh -c "$TERM -e yazi %u" +Type=Application +MimeType=inode/directory +Categories=Utility;Core;System;FileTools;FileManager;ConsoleOnly +Keywords=File;Manager;Explorer;Browser;Launcher diff --git a/configurations/wsl/resources/home-manager/.mpdcron/hooks/player b/configurations/wsl/resources/home-manager/.mpdcron/hooks/player new file mode 100755 index 0000000..499bd0d --- /dev/null +++ b/configurations/wsl/resources/home-manager/.mpdcron/hooks/player @@ -0,0 +1,3 @@ +#!/bin/sh + +systemctl --user restart mpd-discord-rpc.service \ No newline at end of file diff --git a/configurations/wsl/resources/home-manager/.mpdcron/mpdcron.conf b/configurations/wsl/resources/home-manager/.mpdcron/mpdcron.conf new file mode 100644 index 0000000..f7b20d9 --- /dev/null +++ b/configurations/wsl/resources/home-manager/.mpdcron/mpdcron.conf @@ -0,0 +1,31 @@ +# mpdcron configuration file +[main] +# Path to the PID file, by default the PID file is MPDCRON_DIR/mpdcron.pid +# pidfile = /path/to/mpdcron.pid +# Wait this many seconds after sending signal to kill the daemon. +# Default is 3 seconds. +killwait = 3 +# Logging level, default is 0 +# 0: Warnings and errors only +# 1: Info and below +# 2: Debug and below +loglevel = 0 +[mpd] +# Semicolon delimited list of events to wait for. +# By default mpdcron waits for all events. +# Valid events are: +# database: Song database has been updated. +# stored_playlist: A stored playlist has been modified, created, +# deleted or renamed. +# playlist: The queue has been modified. +# player: The player state has been changed: play, stop, pause, seek, ... +# mixer: The volume has been modified. +# output: An audio output device has been enabled or disabled. +# options: Options have changed: crossfade, random, repeat, ... +# update: A database update has started or finished. +events = player +# Interval in seconds to reconnect to mpd after an error or disconnect. +reconnect = 5 +# Timeout in milliseconds for mpd timeout, 0 for default timeout of +# libmpdclient. +timeout = 0 \ No newline at end of file diff --git a/flake.lock b/flake.lock index f810204..08d6b86 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,25 @@ { "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722630065, + "narHash": "sha256-QfM/9BMRkCmgWzrPDK+KbgJOUlSJnfX4OvsUupEUZvA=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "afc892db74d65042031a093adb6010c4c3378422", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, "nix-darwin": { "inputs": { "nixpkgs": [ @@ -7,11 +27,11 @@ ] }, "locked": { - "lastModified": 1711763326, - "narHash": "sha256-sXcesZWKXFlEQ8oyGHnfk4xc9f2Ip0X/+YZOq3sKviI=", + "lastModified": 1722609272, + "narHash": "sha256-Kkb+ULEHVmk07AX+OhwyofFxBDpw+2WvsXguUS2m6e4=", "owner": "LnL7", "repo": "nix-darwin", - "rev": "36524adc31566655f2f4d55ad6b875fb5c1a4083", + "rev": "f7142b8024d6b70c66fd646e1d099d3aa5bfec49", "type": "github" }, "original": { @@ -22,22 +42,23 @@ }, "nixpkgs": { "locked": { - "lastModified": 1711715736, - "narHash": "sha256-9slQ609YqT9bT/MNX9+5k5jltL9zgpn36DpFB7TkttM=", - "owner": "NixOS", + "lastModified": 1722630782, + "narHash": "sha256-hMyG9/WlUi0Ho9VkRrrez7SeNlDzLxalm9FwY7n/Noo=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "807c549feabce7eddbf259dbdcec9e0600a0660d", + "rev": "d04953086551086b44b6f3c6b7eeb26294f207da", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", + "owner": "nixos", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { + "home-manager": "home-manager", "nix-darwin": "nix-darwin", "nixpkgs": "nixpkgs" } diff --git a/flake.nix b/flake.nix index f18424f..0887cc3 100644 --- a/flake.nix +++ b/flake.nix @@ -1,138 +1,54 @@ { - description = "Nix-Darwin Configuration Flake"; + description = "NixOS/Home Manager Configuration for my personal machines"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - nix-darwin.url = "github:LnL7/nix-darwin"; - nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nix-darwin = { + url = "github:LnL7/nix-darwin"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = inputs@{ self, nix-darwin, nixpkgs }: - let - configuration = { pkgs, ... }: { - networking.computerName = "cspark-macos-desktop"; - networking.hostName = "cspark-macos-desktop"; - networking.localHostName = "cspark-macos-desktop"; - - nixpkgs.config.allowUnfree = true; + outputs = inputs@{ self, nix-darwin, nixpkgs, home-manager, ... }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + defaultPackage.x86_64-linux = home-manager.defaultPackage.x86_64-linux; + defaultPackage.x86_64-darwin = home-manager.defaultPackage.x86_64-darwin; - # Nix packages. - environment.systemPackages = with pkgs; [ - git - unrar - pass - neofetch - neovim - yt-dlp - qbittorrent - emacs - discord - ]; + homeConfigurations = { + wsl = home-manager.lib.homeManagerConfiguration { + inherit pkgs; - # Homebrew configuration and packages. - homebrew.enable = true; - # Homebrew formulae - homebrew.brews = [ - ]; - # Homebrew casks - homebrew.casks = [ - "steam" - "librewolf" - # "eloston-chromium" # Ungoogled Chromium - "chromium" - # "blackhole-2ch" # Virtual Audio driver that I'm using alongside the builtin Mac audio routing (Multi-Output/Aggregate - ]; + # Specify your home configuration modules here, for example, + # the path to your home.nix. + modules = [ + ./global-home.nix + ./configurations/wsl/home.nix + ]; - services.yabai = { - enable = true; - config = { - external_bar = "off:40:0"; - menubar_opacity = 1.0; - mouse_follows_focus = "off"; - focus_follows_mouse = "off"; - display_arrangement_order = "default"; - window_origin_display = "default"; - window_placement = "second_child"; - window_zoom_persist = "on"; - window_shadow = "on"; - window_animation_duration = 0.0; - window_animation_easing = "ease_out_circ"; - window_opacity_duration = 0.0; - active_window_opacity = 1.0; - normal_window_opacity = 0.90; - window_opacity = "off"; - insert_feedback_color = "0xffd75f5f"; - split_ratio = 0.50; - split_type = "auto"; - auto_balance = "off"; - top_padding = 12; - bottom_padding = 12; - left_padding = 12; - right_padding = 12; - window_gap = 06; - layout = "bsp"; - mouse_modifier = "fn"; - mouse_action1 = "move"; - mouse_action2 = "resize"; - mouse_drop_action = "swap"; - }; + # Optionally use extraSpecialArgs + # to pass through arguments to home.nix + }; }; - services.skhd = { - enable = true; - skhdConfig = '' - cmd - return : open -a Terminal "`pwd`" - ''; + # Build darwin flake using: + # $ darwin-rebuild build --flake .#Curts-Mac-Pro + darwinConfigurations = { + desktop = nix-darwin.lib.darwinSystem { + specialArgs = {inherit inputs;}; + modules = [ + ./global-home.nix + ./configurations/macos/home.nix + ]; + }; }; - - # Auto upgrade nix package and the daemon service. - services.nix-daemon.enable = true; - # nix.package = pkgs.nix; - - # Necessary for using flakes on this system. - nix.settings.experimental-features = "nix-command flakes"; - - # Create /etc/zshrc that loads the nix-darwin environment. - # programs.zsh.enable = true; # default shell on catalina - # programs.fish.enable = true; - programs.bash = { - enable = true; - enableCompletion = true; - interactiveShellInit = '' - export PS1="\[\e[92;40m\]\h\[\e[m\]:\[\e[93m\]\W\[\e[m\] \\$ " - cd ~ - neofetch - ''; - }; - environment.shellAliases = { - edit = "emacs -nw"; - nix-darwin-rebuild-system-flake = "nix run nix-darwin -- switch --flake ~/.config/nix-darwin#desktop"; - }; - - # Set Git commit hash for darwin-version. - system.configurationRevision = self.rev or self.dirtyRev or null; - - # Used for backwards compatibility, please read the changelog before changing. - # $ darwin-rebuild changelog - system.stateVersion = 4; - - # The platform the configuration will be used on. - nixpkgs.hostPlatform = "x86_64-darwin"; + # Expose the package set, including overlays, for convenience. + darwinPackages = self.darwinConfigurations.desktop-macos.pkgs; }; - in - { - # Build darwin flake using: - # $ darwin-rebuild build --flake .#Curts-Mac-Pro - darwinConfigurations = { - desktop = nix-darwin.lib.darwinSystem { - specialArgs = {inherit inputs;}; - modules = [ - configuration - ]; - }; - }; - - # Expose the package set, including overlays, for convenience. - darwinPackages = self.darwinConfigurations.desktop-macos.pkgs; - }; } diff --git a/global-home.nix b/global-home.nix new file mode 100644 index 0000000..a25d425 --- /dev/null +++ b/global-home.nix @@ -0,0 +1,218 @@ +{ config, pkgs, ... }: + +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? + # (nerdfonts.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 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 + '') + + fastfetch + + neovim + emacs-gtk + + ffmpeg + + mpdcron + + pass + + ripgrep + yazi + ncdu + + ]; + + # 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; + }; + + # 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 $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" ]; + }; + }; + + # 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=${pkgs.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 -nw"; + EDITOR = "nvim"; + + # Dotnet path not found fix + DOTNET_ROOT = "${pkgs.dotnet-sdk}"; + }; + + programs.bash = { + enable = true; + enableCompletion = true; + initExtra = '' + . "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" + fastfetch + ''; + shellAliases = { + sudo = "sudo "; + doas = "doas "; + edit = "$EDITOR"; + cd = "source cd-nvim"; + }; + }; + + programs.git = { + enable = true; + userName = "cspark"; + userEmail = "git@cspark.dev"; + }; + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; +} diff --git a/global-resources/home-manager/.inputrc b/global-resources/home-manager/.inputrc new file mode 100644 index 0000000..0565daf --- /dev/null +++ b/global-resources/home-manager/.inputrc @@ -0,0 +1,12 @@ +set editing-mode vi +set show-mode-in-prompt on +set vi-ins-mode-string "\e[1;30;104mInsert\e[m \1\e[6 q\2" +set vi-cmd-mode-string "\e[1;30;107mNormal\e[m \1\e[2 q\2" + +# Duration to wait before escaping out of Insert mode on Esc keypress +set keyseq-timeout 0 + +# optionally: +# switch to block cursor before executing a command +set keymap vi-insert +RETURN: "\e\n"