diff --git a/base/gui-programs.nix b/base/gui-programs.nix index 62b386c..f98fedf 100644 --- a/base/gui-programs.nix +++ b/base/gui-programs.nix @@ -3,23 +3,17 @@ environment.systemPackages = with pkgs; [ alacritty discord - emacsPgtkGcc feh firefox - flameshot pavucontrol slack spotify - sqlite # needed for org-roam zathura ]; - fonts.fonts = with pkgs; [ - input-fonts - emacs-all-the-icons-fonts - ]; - networking.networkmanager.enable = true; programs.nm-applet.enable = true; + + # NOTE: needed for home emacs configuration nixpkgs.config.input-fonts.acceptLicense = true; } diff --git a/base/programs.nix b/base/programs.nix index 0770768..57d7f8b 100644 --- a/base/programs.nix +++ b/base/programs.nix @@ -14,10 +14,6 @@ AddKeysToAgent yes ''; }; - tmux = { - enable = true; - baseIndex = 1; - }; }; environment.systemPackages = with pkgs; [ @@ -26,6 +22,7 @@ fd ripgrep tree + packages.tmux-thumbs wget # development diff --git a/flake.nix b/flake.nix index edb5671..fb18bcf 100644 --- a/flake.nix +++ b/flake.nix @@ -67,12 +67,17 @@ home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; home-manager.users.alarsyo = import ./home; + home-manager.verbose = true; } { nixpkgs.overlays = [ emacs-overlay.overlay + (self: super: { + packages = import ./packages { pkgs = super; }; + }) + # uncomment this to build everything from scratch, fun but takes a # while # diff --git a/home/default.nix b/home/default.nix index 5a16987..0da2e12 100644 --- a/home/default.nix +++ b/home/default.nix @@ -1,5 +1,12 @@ { ... }: { + imports = [ + ./emacs.nix + ./flameshot.nix + ./tmux.nix + ./x + ]; + home.stateVersion = "20.09"; home.username = "alarsyo"; diff --git a/home/emacs.nix b/home/emacs.nix new file mode 100644 index 0000000..5b1808e --- /dev/null +++ b/home/emacs.nix @@ -0,0 +1,29 @@ +{ config, lib, pkgs, ... }: +{ + options.my.home.emacs = with lib; { + enable = mkEnableOption "Emacs daemon configuration"; + }; + + config = lib.mkIf config.my.home.emacs.enable { + home.packages = with pkgs; [ + sqlite # needed by org-roam + + # fonts used by my config + input-fonts + emacs-all-the-icons-fonts + ]; + # make sure above fonts are discoverable + fonts.fontconfig.enable = true; + + services.emacs = { + enable = true; + # generate emacsclient desktop file + client.enable = true; + }; + + programs.emacs = { + enable = true; + package = pkgs.emacsPgtkGcc; + }; + }; +} diff --git a/home/flameshot.nix b/home/flameshot.nix new file mode 100644 index 0000000..359fc8c --- /dev/null +++ b/home/flameshot.nix @@ -0,0 +1,13 @@ +{ config, lib, ... }: +let + cfg = config.my.home.flameshot; +in +{ + options.my.home.flameshot = with lib; { + enable = mkEnableOption "flameshot autolaunch"; + }; + + config.services.flameshot = lib.mkIf cfg.enable { + enable = true; + }; +} diff --git a/home/tmux.nix b/home/tmux.nix new file mode 100644 index 0000000..24402eb --- /dev/null +++ b/home/tmux.nix @@ -0,0 +1,15 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.my.home.tmux; +in +{ + options.my.home.tmux = with lib; { + enable = mkEnableOption "tmux dotfiles"; + }; + + config.programs.tmux = lib.mkIf cfg.enable { + enable = true; + baseIndex = 1; + plugins = with pkgs; [ packages.tmux-thumbs ]; + }; +} diff --git a/home/x/default.nix b/home/x/default.nix new file mode 100644 index 0000000..ca92c09 --- /dev/null +++ b/home/x/default.nix @@ -0,0 +1,11 @@ +{ config, lib, pkgs, ... }: +{ + imports = [ + ./i3.nix + ./i3bar.nix + ]; + + options.my.home.x = with lib; { + enable = mkEnableOption "X server configuration"; + }; +} diff --git a/home/x/i3.nix b/home/x/i3.nix new file mode 100644 index 0000000..23121bf --- /dev/null +++ b/home/x/i3.nix @@ -0,0 +1,121 @@ +{ config, lib, pkgs, ... }: +let + isEnabled = config.my.home.x.enable; + + myTerminal = + # FIXME: fix when terminal is setup in home + # if config.my.home.terminal.program != null + if true + then "alacritty" + else "i3-sensible-terminal"; + + alt = "Mod1"; # `Alt` key + modifier = "Mod4"; # `Super` key + + logoutMode = "[L]ogout, [S]uspend, [P]oweroff, [R]eboot"; + + # colors + colorBg = "#282828"; + colorRed = "#cc241d"; + colorGreen = "#98971a"; + colorYellow = "#d79921"; + colorBlue = "#458588"; + colorPurple = "#b16286"; + colorAqua = "#689d68"; + colorGray = "#a89984"; + colorDarkGray = "#1d2021"; +in +{ + config = lib.mkIf isEnabled { + my.home = { + flameshot.enable = true; + }; + + xsession.windowManager.i3 = { + enable = true; + + config = { + inherit modifier; + + bars = + let + barConfigPath = + config.xdg.configFile."i3status-rust/config-top.toml".target; + in + [ + { + statusCommand = "i3status-rs ${barConfigPath}"; + position = "top"; + fonts = [ "DejaVu Sans Mono 9" ]; + + colors = { + background = colorBg; + statusline = colorYellow; + + focusedWorkspace = { + border = colorAqua; + background = colorAqua; + text = colorDarkGray; + }; + inactiveWorkspace = { + border = colorDarkGray; + background = colorDarkGray; + text = colorYellow; + }; + activeWorkspace = { + border = colorAqua; + background = colorDarkGray; + text = colorYellow; + }; + urgentWorkspace = { + border = colorRed; + background = colorRed; + text = colorBg; + }; + }; + } + ]; + + focus = { + followMouse = true; + mouseWarping = true; + }; + + fonts = [ + "DejaVu Sans Mono 8" + ]; + + keybindings = lib.mkOptionDefault { + "${modifier}+Shift+e" = ''mode "${logoutMode}"''; + "${modifier}+i" = "exec emacsclient -c"; + }; + + modes = + let + makeModeBindings = attrs: attrs // { + "Escape" = "mode default"; + "Return" = "mode default"; + }; + in + { + ${logoutMode} = makeModeBindings { + "l" = "exec --no-startup-id i3-msg exit, mode default"; + "s" = "exec --no-startup-id systemctl suspend, mode default"; + "p" = "exec --no-startup-id systemctl poweroff, mode default"; + "r" = "exec --no-startup-id systemctl reboot, mode default"; + }; + }; + + startup = [ + # FIXME: make it conditional on "nvidia" being part of video drivers + { + command = "nvidia-settings -a '[gpu:0]/GPUPowerMizerMode=1'"; + notification = false; + } + ]; + + terminal = myTerminal; + }; + }; + }; +} diff --git a/home/x/i3bar.nix b/home/x/i3bar.nix new file mode 100644 index 0000000..644a06b --- /dev/null +++ b/home/x/i3bar.nix @@ -0,0 +1,22 @@ +{ config, lib, pkgs, ... }: +let + isEnabled = config.my.home.x.enable; +in +{ + config = lib.mkIf isEnabled { + home.packages = with pkgs; [ + alsaUtils # Used by `sound` block + lm_sensors # Used by `temperature` block + ]; + + programs.i3status-rust = { + enable = true; + + bars = { + top = { + theme = "gruvbox-light"; + }; + }; + }; + }; +} diff --git a/hosts/boreal/default.nix b/hosts/boreal/default.nix index 71615c6..bd66dcb 100644 --- a/hosts/boreal/default.nix +++ b/hosts/boreal/default.nix @@ -10,6 +10,8 @@ in imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix + + ./home.nix ]; # Use the systemd-boot EFI boot loader. @@ -38,7 +40,7 @@ in # List services that you want to enable: my.services = { wireguard = { - enable = true; + enable = false; iface = "wg"; port = 51820; @@ -69,11 +71,6 @@ in layout = "fr"; xkbVariant = "us"; }; - - emacs = { - enable = true; - package = pkgs.emacsPgtkGcc; - }; }; sound.enable = true; diff --git a/hosts/boreal/home.nix b/hosts/boreal/home.nix new file mode 100644 index 0000000..c39bf22 --- /dev/null +++ b/hosts/boreal/home.nix @@ -0,0 +1,9 @@ +{ ... }: +{ + home-manager.users.alarsyo = { + # Keyboard settings & i3 settings + my.home.x.enable = true; + my.home.emacs.enable = true; + my.home.tmux.enable = true; + }; +} diff --git a/packages/default.nix b/packages/default.nix new file mode 100644 index 0000000..befb57c --- /dev/null +++ b/packages/default.nix @@ -0,0 +1,4 @@ +{ pkgs }: +{ + tmux-thumbs = pkgs.callPackage ./tmux-thumbs.nix {}; +} diff --git a/packages/fix.patch b/packages/fix.patch new file mode 100644 index 0000000..38295c4 --- /dev/null +++ b/packages/fix.patch @@ -0,0 +1,41 @@ +diff --git a/src/swapper.rs b/src/swapper.rs +index aff33e1..cb5f21a 100644 +--- a/src/swapper.rs ++++ b/src/swapper.rs +@@ -210,11 +210,10 @@ impl<'a> Swapper<'a> { + }; + + let pane_command = format!( +- "tmux capture-pane -t {active_pane_id} -p{scroll_params} | tail -n {height} | {dir}/target/release/thumbs -f '%U:%H' -t {tmp} {args}; tmux swap-pane -t {active_pane_id}; {zoom_command} tmux wait-for -S {signal}", ++ "tmux capture-pane -t {active_pane_id} -p{scroll_params} | tail -n {height} | @@replace-me@@/thumbs -f '%U:%H' -t {tmp} {args}; tmux swap-pane -t {active_pane_id}; {zoom_command} tmux wait-for -S {signal}", + active_pane_id = active_pane_id, + scroll_params = scroll_params, + height = self.active_pane_height.unwrap_or(i32::MAX), +- dir = self.dir, + tmp = TMP_FILE, + args = args.join(" "), + zoom_command = zoom_command, +diff --git a/tmux-thumbs.sh b/tmux-thumbs.sh +index 92d5625..c6300c7 100755 +--- a/tmux-thumbs.sh ++++ b/tmux-thumbs.sh +@@ -35,4 +35,4 @@ add-param command string + add-param upcase-command string + add-param osc52 boolean + +-"${CURRENT_DIR}/target/release/tmux-thumbs" "${PARAMS[@]}" || true ++@@replace-me@@ "${PARAMS[@]}" || true +diff --git a/tmux-thumbs.tmux b/tmux-thumbs.tmux +index 4fc9355..87c5346 100755 +--- a/tmux-thumbs.tmux ++++ b/tmux-thumbs.tmux +@@ -8,9 +8,3 @@ THUMBS_KEY="$(tmux show-option -gqv @thumbs-key)" + THUMBS_KEY=${THUMBS_KEY:-$DEFAULT_THUMBS_KEY} + + tmux bind-key "${THUMBS_KEY}" run-shell -b "${CURRENT_DIR}/tmux-thumbs.sh" +- +-BINARY="${CURRENT_DIR}/target/release/thumbs" +- +-if [ ! -f "$BINARY" ]; then +- tmux split-window "cd ${CURRENT_DIR} && cargo build --release --target-dir=target && echo 'Press any key to continue...' && read -k1" +-fi diff --git a/packages/tmux-thumbs.nix b/packages/tmux-thumbs.nix new file mode 100644 index 0000000..cd69486 --- /dev/null +++ b/packages/tmux-thumbs.nix @@ -0,0 +1,38 @@ +{ pkgs, lib, rustPlatform, fetchFromGitHub }: +let + pname = "tmux-thumbs"; + version = "0.5.1"; + tmux-thumbs-binary = rustPlatform.buildRustPackage { + pname = pname; + version = version; + + src = fetchFromGitHub { + owner = "fcsonline"; + repo = pname; + rev = version; + sha256 = "sha256-rU+tsrYJxoqF8Odh2ucvNekc+fLnSY6kFoVFUjqaTFE="; + }; + + cargoSha256 = "sha256-/F9tftRLqC6dk7lX41C8RUMqlrgzc0nkunc0rue5zuM="; + + patches = [ ./fix.patch ]; + postPatch = '' + substituteInPlace src/swapper.rs --replace '@@replace-me@@' '$out/bin/thumbs' + ''; + meta = {}; + }; +in pkgs.tmuxPlugins.mkTmuxPlugin { + pluginName = pname; + version = version; + rtpFilePath = "tmux-thumbs.tmux"; + src = fetchFromGitHub { + owner = "fcsonline"; + repo = pname; + rev = version; + sha256 = "sha256-rU+tsrYJxoqF8Odh2ucvNekc+fLnSY6kFoVFUjqaTFE="; + }; + patches = [ ./fix.patch ]; + postInstall = '' + substituteInPlace $target/tmux-thumbs.sh --replace '@@replace-me@@' '${tmux-thumbs-binary}/bin/tmux-thumbs' + ''; +}