mirror of
https://github.com/cupcakearmy/nix-macos.git
synced 2025-12-07 14:35:03 +00:00
Compare commits
6 Commits
eacfda0fd6
...
2c6299e326
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c6299e326 | |||
| 56fd365da5 | |||
| cb247c2967 | |||
| 9e5965499b | |||
| 1a6bc7b719 | |||
| c8569a1224 |
23
README.md
23
README.md
@@ -1,5 +1,15 @@
|
||||
# Dotfiles with Nix on macOS
|
||||
|
||||
<!--toc:start-->
|
||||
|
||||
- [Dotfiles with Nix on macOS](#dotfiles-with-nix-on-macos)
|
||||
- [Installation](#installation)
|
||||
- [Documentation](#documentation)
|
||||
- [Crypt](#crypt)
|
||||
- [CLI](#cli)
|
||||
- [TODO](#todo)
|
||||
<!--toc:end-->
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
@@ -43,6 +53,19 @@ cat .key.b64 | base64 --decode > .key
|
||||
git-crypt unlock .key
|
||||
```
|
||||
|
||||
## CLI
|
||||
|
||||
The repo also includes a setup that I use on servers which is a toned down version. It lives under `./cli`.
|
||||
|
||||
```bash
|
||||
# Install nix & the CLI
|
||||
curl -sSL https://raw.githubusercontent.com/cupcakearmy/nix/refs/heads/main/cli/install.sh | bash
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
Stuff that I would like to automate, but have not found a way/time
|
||||
|
||||
48
cli/flake.lock
generated
Normal file
48
cli/flake.lock
generated
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"nodes": {
|
||||
"home-manager": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1759853171,
|
||||
"narHash": "sha256-uqbhyXtqMbYIiMqVqUhNdSuh9AEEkiasoK3mIPIVRhk=",
|
||||
"owner": "nix-community",
|
||||
"repo": "home-manager",
|
||||
"rev": "1a09eb84fa9e33748432a5253102d01251f72d6d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "home-manager",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1759831965,
|
||||
"narHash": "sha256-vgPm2xjOmKdZ0xKA6yLXPJpjOtQPHfaZDRtH+47XEBo=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c9b6fb798541223bbb396d287d16f43520250518",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"home-manager": "home-manager",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
42
cli/flake.nix
Normal file
42
cli/flake.nix
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
description = "Server Shell";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
home-manager = {
|
||||
url = "github:nix-community/home-manager";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
nixpkgs,
|
||||
home-manager,
|
||||
...
|
||||
}:
|
||||
let
|
||||
profiles = import ./profiles.nix;
|
||||
in
|
||||
{
|
||||
homeConfigurations = nixpkgs.lib.genAttrs (builtins.map (p: p.name) profiles) (
|
||||
profile:
|
||||
let
|
||||
p = (nixpkgs.lib.findFirst (p: p.name == profile) null profiles);
|
||||
system = p.architecture;
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in
|
||||
home-manager.lib.homeManagerConfiguration {
|
||||
inherit pkgs;
|
||||
|
||||
modules = [ ./home.nix ];
|
||||
|
||||
extraSpecialArgs = {
|
||||
username = p.username;
|
||||
homeDirectory = p.homeDirectory;
|
||||
name = p.name;
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
21
cli/home.nix
Normal file
21
cli/home.nix
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
pkgs,
|
||||
username,
|
||||
name,
|
||||
homeDirectory,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
common = (import ../common/home.nix) { inherit pkgs; };
|
||||
overwrite = {
|
||||
home.username = username;
|
||||
home.homeDirectory = homeDirectory;
|
||||
home = {
|
||||
shellAliases = {
|
||||
hm = "nix run home-manager/master -- switch --flake github:cupcakearmy/nix?dir=cli#${name} -b backup";
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
lib.recursiveUpdate common overwrite
|
||||
87
cli/install.sh
Executable file
87
cli/install.sh
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "=== Nix Home Manager Setup ==="
|
||||
echo
|
||||
|
||||
# Check if Nix is installed
|
||||
if ! command -v nix &>/dev/null; then
|
||||
echo "Nix is not installed. Installing Nix..."
|
||||
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --determinate
|
||||
|
||||
# Source nix profile
|
||||
if [ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]; then
|
||||
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
|
||||
fi
|
||||
|
||||
echo "Nix installed successfully!"
|
||||
echo
|
||||
else
|
||||
echo "Nix is already installed."
|
||||
echo
|
||||
fi
|
||||
|
||||
# Detect architecture
|
||||
ARCH=$(uname -m)
|
||||
case "$ARCH" in
|
||||
x86_64)
|
||||
ARCH_NAME="x86"
|
||||
;;
|
||||
aarch64 | arm64)
|
||||
ARCH_NAME="arm"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture: $ARCH"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Detect OS
|
||||
OS=$(uname -s)
|
||||
case "$OS" in
|
||||
Linux)
|
||||
OS_NAME="linux"
|
||||
;;
|
||||
Darwin)
|
||||
OS_NAME="darwin"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported OS: $OS"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Detected: $ARCH_NAME / $OS_NAME"
|
||||
echo
|
||||
|
||||
# Clear any remaining input and prompt for user
|
||||
read -t 0.1 -n 10000 discard 2>/dev/null || true
|
||||
echo "Select user:"
|
||||
echo "1) root"
|
||||
read -p "Enter choice [1]: " USER_CHOICE
|
||||
USER_CHOICE=${USER_CHOICE:-1}
|
||||
|
||||
case "$USER_CHOICE" in
|
||||
1)
|
||||
USER_NAME="root"
|
||||
;;
|
||||
*)
|
||||
echo "Invalid choice. Defaulting to root."
|
||||
USER_NAME="root"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Build flake configuration name
|
||||
FLAKE_CONFIG="${USER_NAME}_${ARCH_NAME}_${OS_NAME}"
|
||||
|
||||
echo
|
||||
echo "Configuration: $FLAKE_CONFIG"
|
||||
echo "Running Home Manager..."
|
||||
echo
|
||||
|
||||
# Run home-manager
|
||||
nix run home-manager/master -- switch --flake "github:cupcakearmy/nix?dir=cli#${FLAKE_CONFIG}" -b backup
|
||||
|
||||
echo
|
||||
echo "=== Setup complete! ==="
|
||||
46
cli/pkgs.nix
Normal file
46
cli/pkgs.nix
Normal file
@@ -0,0 +1,46 @@
|
||||
{ pkgs }:
|
||||
with pkgs;
|
||||
[
|
||||
# Base
|
||||
tmux
|
||||
git
|
||||
git-lfs
|
||||
git-crypt
|
||||
gnutar
|
||||
gnupg
|
||||
htop
|
||||
btop
|
||||
rclone
|
||||
rename
|
||||
tmux
|
||||
tree
|
||||
wget
|
||||
rsync
|
||||
yq
|
||||
delta
|
||||
|
||||
# Rust utils
|
||||
bat
|
||||
eza
|
||||
fd
|
||||
ripgrep
|
||||
ripgrep-all
|
||||
zoxide
|
||||
uutils-coreutils-noprefix
|
||||
dust
|
||||
yazi
|
||||
starship
|
||||
|
||||
# Dev
|
||||
lazydocker
|
||||
k9s
|
||||
kubectl
|
||||
|
||||
# Editor
|
||||
neovim
|
||||
fzf
|
||||
lazygit
|
||||
|
||||
# Fonts
|
||||
nerd-fonts.jetbrains-mono
|
||||
]
|
||||
26
cli/profiles.nix
Normal file
26
cli/profiles.nix
Normal file
@@ -0,0 +1,26 @@
|
||||
[
|
||||
{
|
||||
name = "root_x86_linux";
|
||||
username = "root";
|
||||
architecture = "x86_64-linux";
|
||||
homeDirectory = "/root";
|
||||
}
|
||||
{
|
||||
name = "root_x86_macos";
|
||||
username = "root";
|
||||
architecture = "x86_64-darwin";
|
||||
homeDirectory = "/root";
|
||||
}
|
||||
{
|
||||
name = "root_arm_linux";
|
||||
username = "root";
|
||||
architecture = "aarch64-linux";
|
||||
homeDirectory = "/root";
|
||||
}
|
||||
{
|
||||
name = "root_arm_macos";
|
||||
username = "root";
|
||||
architecture = "aarch64-darwin";
|
||||
homeDirectory = "/root";
|
||||
}
|
||||
]
|
||||
122
common/home.nix
Normal file
122
common/home.nix
Normal file
@@ -0,0 +1,122 @@
|
||||
{
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
{
|
||||
|
||||
home.stateVersion = "25.11";
|
||||
|
||||
home.packages = with pkgs; [
|
||||
# Base
|
||||
tmux
|
||||
git
|
||||
git-lfs
|
||||
git-crypt
|
||||
gnutar
|
||||
gnupg
|
||||
htop
|
||||
btop
|
||||
rclone
|
||||
rename
|
||||
tmux
|
||||
tree
|
||||
wget
|
||||
rsync
|
||||
yq
|
||||
delta
|
||||
|
||||
# Rust utils
|
||||
bat
|
||||
eza
|
||||
fd
|
||||
ripgrep
|
||||
ripgrep-all
|
||||
zoxide
|
||||
uutils-coreutils-noprefix
|
||||
dust
|
||||
yazi
|
||||
starship
|
||||
|
||||
# Dev
|
||||
lazydocker
|
||||
k9s
|
||||
kubectl
|
||||
|
||||
# Editor
|
||||
neovim
|
||||
fzf
|
||||
lazygit
|
||||
|
||||
# Fonts
|
||||
nerd-fonts.jetbrains-mono
|
||||
];
|
||||
|
||||
fonts.fontconfig.enable = true;
|
||||
|
||||
home = {
|
||||
sessionVariables = {
|
||||
EDITOR = "nvim";
|
||||
};
|
||||
|
||||
shellAliases = {
|
||||
# Rust re-maps
|
||||
l = "eza -a1lh";
|
||||
ls = "eza";
|
||||
cat = "bat";
|
||||
cd = "z";
|
||||
|
||||
# QOL
|
||||
dc = "docker compose";
|
||||
rsync = "rsync -az --info=progress2";
|
||||
t = "tmux new-session -A -s main";
|
||||
e = "nvim";
|
||||
g = "lazygit";
|
||||
d = "lazydocker";
|
||||
k = "kubectl";
|
||||
};
|
||||
};
|
||||
|
||||
programs = {
|
||||
direnv.enable = true;
|
||||
zoxide.enable = true;
|
||||
|
||||
fish = {
|
||||
enable = true;
|
||||
interactiveShellInit = ''
|
||||
if type -q starship
|
||||
starship init fish | source
|
||||
end
|
||||
if type -q fnm
|
||||
fnm env --use-on-cd | source
|
||||
end
|
||||
if type -q nvs
|
||||
nvs env --source | source
|
||||
end
|
||||
'';
|
||||
};
|
||||
bash = {
|
||||
enable = true;
|
||||
};
|
||||
tmux = {
|
||||
enable = true;
|
||||
clock24 = true;
|
||||
mouse = true;
|
||||
extraConfig = ''
|
||||
# switch panes using Alt-arrow without prefix
|
||||
bind -n M-Left select-pane -L
|
||||
bind -n M-Right select-pane -R
|
||||
bind -n M-Up select-pane -U
|
||||
bind -n M-Down select-pane -D
|
||||
|
||||
# switch panes using jkhl
|
||||
bind h select-pane -L
|
||||
bind l select-pane -R
|
||||
bind j select-pane -U
|
||||
bind k select-pane -D
|
||||
'';
|
||||
shell = "${pkgs.fish}/bin/fish";
|
||||
terminal = "tmux-256color";
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user