[feat] Add some stuff for nix

This commit is contained in:
Uttarayan Mondal
2024-02-15 06:46:02 +05:30
parent 6a009ef91c
commit 5ca9d2165c
9 changed files with 498 additions and 359 deletions

View File

@@ -1,11 +1,9 @@
.PHONY: run build genzai .PHONY: darwin build default
default: build default: build
darwin:
nix run nix-darwin -- switch --flake ~/.local/share/dotfiles/config/nix
switch: home:
nix run home-manager/master -- switch --flake ~/.local/share/dotfiles/config/nix nix run home-manager/master -- switch --flake ~/.local/share/dotfiles/config/nix
build:
nix run home-manager/master -- build --flake ~/.local/share/dotfiles/config/nix
genzai:
nix build .#homeConfigurations.genzai

View File

@@ -1,10 +1,38 @@
{pkgs, ...}: { {
pkgs,
device,
...
}: {
imports = [
./yabai.nix
./skhd.nix
];
environment.systemPackages = with pkgs; [
nix
neovim
];
nix = { nix = {
settings = { settings = {
experimental-features = "nix-command flakes repl-flake"; experimental-features = "nix-command flakes repl-flake";
max-jobs = 8; max-jobs = 8;
trusted-users = ["root" "fs0c131y"];
}; };
extraOptions = ''
build-users-group = nixbld
extra-nix-path = nixpkgs=flake:nixpkgs
'';
package = pkgs.nix;
}; };
programs.bash.enable = true;
programs.zsh.enable = true;
programs.fish.enable = true;
nixpkgs.hostPlatform = device.system;
services.nix-daemon.enable = true;
system.stateVersion = 4;
system.keyboard.enableKeyMapping = true; system.keyboard.enableKeyMapping = true;
system.keyboard.remapCapsLockToControl = true; system.keyboard.remapCapsLockToControl = true;
system.keyboard.swapLeftCommandAndLeftAlt = true; system.keyboard.swapLeftCommandAndLeftAlt = true;

View File

@@ -16,13 +16,14 @@
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { outputs =
nixpkgs, { nixpkgs
home-manager, , home-manager
nix-darwin, , nix-darwin
flake-utils, , flake-utils
... , ...
} @ inputs: let } @ inputs:
let
devices = [ devices = [
{ {
name = "mirai"; name = "mirai";
@@ -47,12 +48,15 @@
]; ];
linux = builtins.filter (x: x.system == "x86_64-linux") devices; linux = builtins.filter (x: x.system == "x86_64-linux") devices;
darwin = builtins.filter (x: x.system == "aarch64-darwin") devices; darwin = builtins.filter (x: x.system == "aarch64-darwin") devices;
in { in
homeConfigurations = builtins.listToAttrs (builtins.map (device: { {
homeConfigurations = builtins.listToAttrs (builtins.map
(device: {
name = device.user; name = device.user;
value = let value =
let
pkgs = nixpkgs.legacyPackages.${device.system}; pkgs = nixpkgs.legacyPackages.${device.system};
overlays = [inputs.neovim-nightly-overlay.overlay]; overlays = [ inputs.neovim-nightly-overlay.overlay ];
in in
home-manager.lib.homeManagerConfiguration { home-manager.lib.homeManagerConfiguration {
inherit pkgs; inherit pkgs;
@@ -66,68 +70,35 @@
}) })
linux); linux);
darwinConfigurations = builtins.listToAttrs (builtins.map (device: { darwinConfigurations =
builtins.listToAttrs
(builtins.map
(device: {
name = device.name; name = device.name;
value = let value =
let
pkgs = nixpkgs.legacyPackages.${device.system}; pkgs = nixpkgs.legacyPackages.${device.system};
in { overlays = [ inputs.neovim-nightly-overlay.overlay ];
"Uttarayans-MacBook-Pro" = nix-darwin.lib.darwinSystem { in
nix-darwin.lib.darwinSystem {
inherit pkgs;
modules = [ modules = [
home-manager.darwinModules.home-manager
./darwin.nix ./darwin.nix
({config, ...}: { home-manager.darwinModules.home-manager
{
home-manager = { home-manager = {
users = { useGlobalPkgs = true;
fs0c131y = { useUserPackages = true;
home = "/Users/${device.user}"; extraSpecialArgs = {
stateVersion = "21.05"; inherit device;
configuration = home-manager.configurations.fs0c131y; inherit overlays;
}; };
users.${device.user}.imports = [ ./home.nix ];
}; };
}; }
})
]; ];
}; };
};
}) })
darwin); darwin);
}; };
} }
# "fs0c131y" = let
# system = "x86_64-linux";
# overlays = [inputs.neovim-nightly-overlay.overlay];
# pkgs = nixpkgs.legacyPackages.${system};
# in
# home-manager.lib.homeManagerConfiguration
# {
# inherit pkgs;
# modules = [
# ./home.nix
# {
# nixpkgs.overlays = overlays;
# }
# ];
# };
# darwinConfigurations = let
# system = "aarch64-darwin";
# pkgs = nixpkgs.legacyPackages.${system};
# in {
# "Uttarayans-MacBook-Pro" = darwin.lib.darwinSystem {
# modules = [
# home-manager.darwinModules.home-manager
# ./darwin.nix
# ({config, ...}: {
# home-manager = {
# users = {
# fs0c131y = {
# home = "/Users/fs0c131y";
# stateVersion = "21.05";
# configuration = home-manager.configurations.fs0c131y;
# };
# };
# };
# })
# ];
# };
# };

View File

@@ -1,12 +1,21 @@
{ { config
config, , pkgs
pkgs, , lib
... , device
}: let , overlays
, ...
}:
let
start-tmux = (import ./scripts/start-tmux.nix) pkgs; start-tmux = (import ./scripts/start-tmux.nix) pkgs;
in in
# https://mipmip.github.io/home-manager-option-search/ # https://mipmip.github.io/home-manager-option-search/
{ {
nixpkgs.overlays = [
(self: super: {
neovim-nightly = overlays.neovim-nightly;
})
];
imports = [ imports = [
# Include the results of the hardware scan. # Include the results of the hardware scan.
./tmux.nix ./tmux.nix
@@ -73,7 +82,7 @@ in
}; };
keychain = { keychain = {
enable = true; enable = true;
keys = ["id_ed25519"]; # keys = [ "id_ed25519" ];
enableFishIntegration = true; enableFishIntegration = true;
enableNushellIntegration = true; enableNushellIntegration = true;
}; };
@@ -128,15 +137,20 @@ in
home = { home = {
# Home Manager needs a bit of information about you and the paths it should # Home Manager needs a bit of information about you and the paths it should
# manage. # manage.
username = "fs0c131y"; username = device.user;
homeDirectory = "/home/fs0c131y"; homeDirectory =
if device.system == "x86-64-linux" then
lib.mkForce "/home/${device.user}"
else
lib.mkForce "/Users/${device.user}";
stateVersion = "23.11"; stateVersion = "23.11";
packages = [ packages = [
pkgs.macchina pkgs.macchina
pkgs.alejandra pkgs.alejandra
pkgs.neovim-nightly # pkgs.neovim-nightly
pkgs.cachix pkgs.cachix
# # Adds the 'hello' command to your environment. It prints a friendly # # Adds the 'hello' command to your environment. It prints a friendly
# # "Hello, world!" when run. # # "Hello, world!" when run.
@@ -176,4 +190,4 @@ in
"${config.home.homeDirectory}/.nix-profile/bin" "${config.home.homeDirectory}/.nix-profile/bin"
]; ];
}; };
} }

View File

@@ -1,2 +1,9 @@
substituters = https://cache.nixos.org https://nix-community.cachix.org # Generated by https://github.com/DeterminateSystems/nix-installer.
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= # See `/nix/nix-installer --version` for the version details.
build-users-group = nixbld
experimental-features = nix-command flakes repl-flake
bash-prompt-prefix = (nix:$name)\040
max-jobs = auto
extra-nix-path = nixpkgs=flake:nixpkgs
upgrade-nix-store-path-url = https://install.determinate.systems/nix-upgrade/stable/universal

View File

@@ -1,6 +1,5 @@
{ { pkgs
pkgs, , ...
...
}: }:
pkgs.writeShellScript "start-tmux" '' pkgs.writeShellScript "start-tmux" ''
live_sessions=$(${pkgs.tmux}/bin/tmux list-sessions 2>/dev/null) live_sessions=$(${pkgs.tmux}/bin/tmux list-sessions 2>/dev/null)
@@ -14,15 +13,16 @@ pkgs.writeShellScript "start-tmux" ''
exit 1 exit 1
fi fi
IFS=$'\n' IFS=$'\n'
for live_session in $live_sessions;do for live_session in $live_sessions;
do
live_session_name=$(echo $live_session | ${pkgs.coreutils}/bin/cut -d: -f1) live_session_name=$(echo $live_session | ${pkgs.coreutils}/bin/cut -d: -f1)
if [ -z "''\${all_sessions##*$live_session_name*}" ];then # see https://stackoverflow.com/questions/229551/how-to-check-if-a-string-contains-a-substring-in-bash if [ -z "''\${all_sessions##*$live_session_name*}" ];then # see https://stackoverflow.com/questions/229551/how-to-check-if-a-string-contains-a-substring-in-bash
all_sessions="$(echo "$all_sessions" | sed "s/$live_session_name/$live_session/g")" all_sessions="$(echo "$all_sessions" | sed "s/$live_session_name/$live_session/g")"
else else
all_sessions=$(echo -e "$all_sessions\n$live_session") all_sessions="$(echo -e "$all_sessions\n$live_session")"
# Okay I know this is ugly it is 5:13 my brain is not working
fi fi
session=$(echo "''\$all_sessions" | fzf) done
session=$(echo "''\$all_sessions" | ${pkgs.fzf}/bin/fzf)
session_name=$(echo $session | cut -d: -f1) session_name=$(echo $session | cut -d: -f1)
if [ -z "$session" ];then if [ -z "$session" ];then
exit 0 exit 0
@@ -38,11 +38,12 @@ pkgs.writeShellScript "start-tmux" ''
if [ -z "''\${session##*attached*}" ];then if [ -z "''\${session##*attached*}" ];then
read -r -p "The session is already attached somewhere else. Attach it here too ? (y/N): " choice read -r -p "The session is already attached somewhere else. Attach it here too ? (y/N): " choice
if [ "$choice" == "y" ] || [ "$choice" == "Y" ];then if [ "$choice" == "y" ] || [ "$choice" == "Y" ];then
tmux attach-session -t$session_name ${pkgs.tmux}/bin/tmux attach-session -t$session_name
fi fi
else else
tmux attach-session -t$session_name ${pkgs.tmux}/bin/tmux attach-session -t$session_name
fi fi
done
'' ''

77
config/nix/skhd.nix Normal file
View File

@@ -0,0 +1,77 @@
{...}: {
services = {
skhd = {
enable = true;
skhdConfig = ''
# open terminal, blazingly fast compared to iTerm/Hyper
# alt - return : /Applications/kitty.app/Contents/MacOS/kitty --single-instance -d ~
alt - return : /Applications/WezTerm.app/Contents/MacOS/wezterm
shift + alt - return: pkill mpv
# alt + \ : pkill mpv
# open qutebrowser
# alt + shift - return : ~/Scripts/qtb.sh
# open mpv
alt - m : open -na /Applications/mpv.app $(pbpaste)
# close focused window
# alt - w : yabai -m window --close
alt - d : open -na "$(ls /Applications /System/Applications/ /System/Applications/Utilities/ | choose)"
# focus window
alt - h : yabai -m window --focus west
alt - j : yabai -m window --focus south
alt - k : yabai -m window --focus north
alt - l : yabai -m window --focus east
# alt - j : yabai -m window --focus prev
# alt - k : yabai -m window --focus next
# Float
shift + alt - f: yabai -m window --toggle float
alt - f: yabai -m window --toggle native-fullscreen
# swap window
# shift + alt - h : yabai -m window --swap west
# shift + alt - j : yabai -m window --swap south
# shift + alt - k : yabai -m window --swap north
# shift + alt - l : yabai -m window --swap east
# move window
shift + alt - h : yabai -m window --warp west
shift + alt - j : yabai -m window --warp south
shift + alt - k : yabai -m window --warp north
shift + alt - l : yabai -m window --warp east
# restart skhd
shift + alt - r : pkill skhd
# fast focus desktop
alt - 1 : yabai -m space --focus 1
alt - 2 : yabai -m space --focus 2
alt - 3 : yabai -m space --focus 3
alt - 4 : yabai -m space --focus 4
alt - 5 : yabai -m space --focus 5
alt - 6 : yabai -m space --focus 6
alt - 7 : yabai -m space --focus 7
alt - 8 : yabai -m space --focus 8
alt - 9 : yabai -m space --focus 9
alt - 0 : yabai -m space --focus 10
# Move window to desktop
shift + alt - 1 : yabai -m window --space 1
shift + alt - 2 : yabai -m window --space 2
shift + alt - 3 : yabai -m window --space 3
shift + alt - 4 : yabai -m window --space 4
shift + alt - 5 : yabai -m window --space 5
shift + alt - 6 : yabai -m window --space 6
shift + alt - 7 : yabai -m window --space 7
shift + alt - 8 : yabai -m window --space 8
shift + alt - 9 : yabai -m window --space 9
shift + alt - 0 : yabai -m window --space 10
'';
};
};
}

View File

@@ -1,4 +1,5 @@
{pkgs, ...}: let { pkgs, ... }:
let
tmux-super-fingers = tmux-super-fingers =
pkgs.tmuxPlugins.mkTmuxPlugin pkgs.tmuxPlugins.mkTmuxPlugin
{ {
@@ -20,7 +21,8 @@
tmux popup -d '#{pane_current_path}' -xC -yC -w$width -h$height -E "tmux attach -t scratch || tmux new -s scratch" tmux popup -d '#{pane_current_path}' -xC -yC -w$width -h$height -E "tmux attach -t scratch || tmux new -s scratch"
fi fi
''; '';
in { in
{
programs.tmux = { programs.tmux = {
enable = true; enable = true;
shell = "${pkgs.nushellFull}/bin/nu"; shell = "${pkgs.nushellFull}/bin/nu";
@@ -38,15 +40,12 @@ in {
plugin = tmuxPlugins.catppuccin; plugin = tmuxPlugins.catppuccin;
extraConfig = '' extraConfig = ''
set -g @catppuccin_flavour 'mocha' set -g @catppuccin_flavour 'mocha'
set -g @catppuccin_window_tabs_enabled on
set -g @catppuccin_status_modules_right ""
set -g @catppuccin_status_modules_right "battery application session date_time"
''; '';
} }
{ {
plugin = tmuxPlugins.battery; plugin = tmuxPlugins.battery;
extraConfig = '' extraConfig = ''
set -g @catppuccin_status_modules_right "application session user host date_time" set -g @catppuccin_status_modules_right "battery application session date_time"
''; '';
} }
]; ];

44
config/nix/yabai.nix Normal file
View File

@@ -0,0 +1,44 @@
{...}: {
services = {
yabai = {
enable = true;
enableScriptingAddition = true;
config = {
mouse_follows_focus = "on";
focus_follows_mouse = "on";
window_origin_display = "default";
window_placement = "second_child";
window_topmost = "off";
window_shadow = "on";
window_opacity = "off";
window_opacity_duration = "0.0";
active_window_opacity = "1.0";
normal_window_opacity = "0.90";
window_border = "off";
window_border_width = "6";
active_window_border_color = "0xff775759";
normal_window_border_color = "0xff555555";
insert_feedback_color = "0xffd75f5f";
split_ratio = "0.50";
auto_balance = "off";
mouse_modifier = "fn";
mouse_action1 = "move";
mouse_action2 = "resize";
mouse_drop_action = "swap";
layout = "bsp";
top_padding = "5";
bottom_padding = "5";
left_padding = "5";
right_padding = "5";
window_gap = "06";
};
extraConfig = ''
yabai -m rule --add app='System Preferences' manage=off
yabai -m rule --add app="choose" manage=off
yabai -m rule --add app="barrier" manage=off
yabai -m rule --add app="steam" manage=off
'';
};
};
}