1
0
Fork 0

Use nix-darwin+home-manager

This commit is contained in:
Daniel Kempkens 2022-02-03 23:35:52 +01:00
parent 882f3c6239
commit 577ccb543a
14 changed files with 198 additions and 119 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
.DS_Store .DS_Store
*.auth *.auth
result

View file

@ -1,5 +1,7 @@
## Installation ## Installation
⚠️ I have switched to a combination of `nix-darwin` and `home-manager`. The installation instructions below only do not work that setup.
```bash ```bash
# nix # nix
sh <(curl -L https://nixos.org/nix/install) sh <(curl -L https://nixos.org/nix/install)

View file

@ -1,6 +0,0 @@
{
xdg.configFile.kitty = {
source = ./kitty;
recursive = true;
};
}

View file

@ -1,40 +0,0 @@
shell /Users/daniel/.nix-profile/bin/fish --interactive
shell_integration no-cursor
# Fonts
font_family JetBrainsMono Nerd Font
bold_font auto
italic_font auto
bold_italic_font auto
font_size 13.0
# Theme
include dracula.conf
window_padding_width 3
tab_title_template "{index}: {title[:25]}"
tab_bar_style separator
tab_separator " ┇ "
macos_titlebar_color background
macos_traditional_fullscreen yes
macos_show_window_title_in window
# Keymap
kitty_mod cmd
# Cursor
cursor_blink_interval 0
# Mouse
detect_urls no
allow_hyperlinks no
# Bell
enable_audio_bell no
visual_bell_duration 0.0
# Scrollback
scrollback_pager_history_size 2

41
darwin-configuration.nix Normal file
View file

@ -0,0 +1,41 @@
{ pkgs, lib, ... }:
{
nix = {
binaryCaches = [
"https://nix-community.cachix.org"
];
binaryCachePublicKeys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
trustedUsers = [
"@admin"
];
extraOptions = ''
experimental-features = nix-command flakes
keep-derivations = true
keep-outputs = true
auto-optimise-store = true
'';
};
users.nix.configureBuildUsers = true;
environment = {
darwinConfig = "$HOME/.config/nixpkgs/darwin-configuration.nix";
};
services = {
nix-daemon.enable = true;
};
fonts = {
enableFontDir = true;
fonts = with pkgs; [
(nerdfonts.override { fonts = [ "JetBrainsMono" ]; })
];
};
}

View file

@ -1,5 +1,25 @@
{ {
"nodes": { "nodes": {
"darwin": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1642495030,
"narHash": "sha256-u1ZlFbLWzkM6zOfuZ1tr0tzTuDWucOYwALPWDWLorkE=",
"owner": "lnl7",
"repo": "nix-darwin",
"rev": "bcdb6022b3a300abf59cb5d0106c158940f5120e",
"type": "github"
},
"original": {
"owner": "lnl7",
"repo": "nix-darwin",
"type": "github"
}
},
"flake-compat": { "flake-compat": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -38,11 +58,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1643837728, "lastModified": 1643919871,
"narHash": "sha256-iW/5eMRQmzdctv2dAUlIaZnVWwcmaznNajS+ft1MXHg=", "narHash": "sha256-qDDTcqvKcrdIOHfdjbzIniE8+gsopiE+3qC/y14ItyY=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "9d369c75ce2fdeb296ad42bcdc8c1a523c494550", "rev": "1fa809f7830d5febc8638cd6edc1dfab293df4af",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -135,6 +155,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"darwin": "darwin",
"home-manager": "home-manager", "home-manager": "home-manager",
"neovim-nightly-overlay": "neovim-nightly-overlay", "neovim-nightly-overlay": "neovim-nightly-overlay",
"nifoc-overlay": "nifoc-overlay", "nifoc-overlay": "nifoc-overlay",

View file

@ -2,6 +2,11 @@
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
darwin = {
url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = { home-manager = {
url = "github:nix-community/home-manager"; url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -18,21 +23,12 @@
}; };
}; };
outputs = inputs@{ self, nixpkgs, home-manager, ... }: { outputs = inputs@{ self, nixpkgs, darwin, home-manager, ... }:
homeConfigurations = {
daniel = home-manager.lib.homeManagerConfiguration {
system = "aarch64-darwin";
homeDirectory = "/Users/daniel";
username = "daniel";
stateVersion = "21.11";
configuration = { config, pkgs, ... }:
let let
overlay-neovim = inputs.neovim-nightly-overlay.overlay; overlay-neovim = inputs.neovim-nightly-overlay.overlay;
overlay-nifoc = inputs.nifoc-overlay.overlay; overlay-nifoc = inputs.nifoc-overlay.overlay;
in
{ nixpkgsConfig = {
nixpkgs = {
overlays = [ overlays = [
overlay-neovim overlay-neovim
overlay-nifoc overlay-nifoc
@ -43,10 +39,22 @@
allowBroken = true; allowBroken = true;
}; };
}; };
in
{
darwinConfigurations."Styx" = darwin.lib.darwinSystem {
system = "aarch64-darwin";
modules = [
./darwin-configuration.nix
imports = [ ./home.nix ]; home-manager.darwinModules.home-manager
}; {
}; nixpkgs = nixpkgsConfig;
nix.nixPath = { nixpkgs = "${nixpkgs}"; };
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.daniel = import ./home.nix;
}
];
}; };
}; };
} }

View file

@ -5,7 +5,7 @@
./programs/fish.nix ./programs/fish.nix
./programs/starship.nix ./programs/starship.nix
./programs/direnv.nix ./programs/direnv.nix
./config/kitty.nix ./programs/kitty.nix
./programs/nvim ./programs/nvim
@ -24,6 +24,8 @@
]; ];
home = { home = {
stateVersion = "21.11";
packages = with pkgs; [ packages = with pkgs; [
aria2 aria2
arp-scan arp-scan
@ -56,25 +58,25 @@
yt-dlp yt-dlp
]; ];
sessionVariables = {
TERMINFO_DIRS = "${pkgs.kitty.terminfo.outPath}/share/terminfo";
};
activation = { activation = {
updateAppCaches = lib.hm.dag.entryAfter [ "onFilesChange" "installPackages" "copyFonts" ] '' updateAppCaches = lib.hm.dag.entryAfter [ "onFilesChange" "installPackages" "copyFonts" ] ''
# nixpkgs
echo "Calculating new NIX_PATH value ..."
"$HOME/.bin/calculate-nix-path"
# neovim # neovim
echo -n 'Removing luacache file: ' echo -n 'Removing luacache file: '
rm -f "$HOME/.cache/nvim/luacache" rm -f "$HOME/.cache/nvim/luacache"
echo 'Done' echo 'Done'
echo -n 'Running LuaCacheClear: '
nvim -c 'try | execute "LuaCacheClear" | echo "Done" | catch /.*/ | echo "Command not found" | endtry | q' --headless
printf '\nRunning TSUpdateSync ... '
nvim -c 'try | execute "TSUpdateSync" | echo "Done" | catch /.*/ | echo "Command not found" | endtry | q' --headless
printf '\n'
'';
reportChanges = lib.hm.dag.entryAfter [ "updateAppCaches" ] '' nvim_bin="/etc/profiles/per-user/$USER/bin/nvim"
nvd diff $oldGenPath $newGenPath if [ -e "$nvim_bin" ]; then
echo -n 'Running LuaCacheClear: '
$nvim_bin -c 'try | execute "LuaCacheClear" | echo "Done" | catch /.*/ | echo "Command not found" | endtry | q' --headless
printf '\nRunning TSUpdateSync ... '
$nvim_bin -c 'try | execute "TSUpdateSync" | echo "Done" | catch /.*/ | echo "Command not found" | endtry | q' --headless
printf '\n'
fi
''; '';
}; };
}; };

View file

@ -67,7 +67,7 @@
]; ];
shellAliases = { shellAliases = {
hmsw = "home-manager switch --flake ~/.config/nixpkgs/#$USER"; drsw = "nix-darwin-switch";
j = "z"; j = "z";
ji = "zi"; ji = "zi";
la = "exa --long --all --group --header --group-directories-first --sort=type --icons"; la = "exa --long --all --group --header --group-directories-first --sort=type --icons";
@ -80,7 +80,7 @@
yti = "ytdl_with_options -F"; yti = "ytdl_with_options -F";
upa = "nix flake update ~/.config/nixpkgs -v"; upa = "nix flake update ~/.config/nixpkgs -v";
upn = "$HOME/.config/nixpkgs/programs/nvim/update-plugins.sh"; upn = "$HOME/.config/nixpkgs/programs/nvim/update-plugins.sh";
ucl = "nix-collect-garbage -d && nix-store --gc && calculate-nix-path"; ucl = "nix-collect-garbage -d && nix-store --gc";
}; };
functions = { functions = {
@ -111,12 +111,9 @@
# Disable greeting # Disable greeting
set fish_greeting set fish_greeting
if test -e "$HOME/.cache/fish/nix_path_value" if [ -z "$__NIX_DARWIN_SET_ENVIRONMENT_DONE" ]
set -gx NIX_PATH (cat "$HOME/.cache/fish/nix_path_value") set __nifoc_nix_darwin_set_env (cat /run/current-system/etc/bashrc | grep '-set-environment' | cut -d '.' -f 2)
end fenv source "$__nifoc_nix_darwin_set_env"
if test -e /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
fenv source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
end end
if test -d "$HOME/.bin" if test -d "$HOME/.bin"

47
programs/kitty.nix Normal file
View file

@ -0,0 +1,47 @@
{
programs.kitty = {
enable = true;
settings = {
# Shell
shell = "/etc/profiles/per-user/daniel/bin/fish --interactive";
shell_integration = "no-cursor";
# Theme/Layout
window_padding_width = 3;
tab_title_template = "\"{index}: {title[:25]}\"";
tab_bar_style = "separator";
tab_separator = "\" \"";
macos_titlebar_color = "background";
macos_traditional_fullscreen = true;
macos_show_window_title_in = "window";
# UX
kitty_mod = "cmd";
cursor_blink_interval = 0;
enable_audio_bell = false;
visual_bell_duration = 0;
# Mouse
detect_urls = false;
allow_hyperlinks = false;
# Scrollback
scrollback_pager_history_size = 2;
};
font = {
name = "JetBrainsMono Nerd Font";
size = 13;
};
extraConfig = ''
include dracula.conf
'';
};
xdg.configFile.kitty = {
source = ../config/kitty;
recursive = true;
};
}

View file

@ -36,6 +36,7 @@ in
extraPackages = with pkgs; [ extraPackages = with pkgs; [
gcc gcc
gnumake gnumake
git
nodejs-16_x nodejs-16_x
tree-sitter tree-sitter

View file

@ -91,12 +91,12 @@
}; };
nvim-treesitter = pkgs.vimUtils.buildVimPluginFrom2Nix { nvim-treesitter = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "nvim-treesitter"; pname = "nvim-treesitter";
version = "1643811536"; version = "1643912584";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "nvim-treesitter"; owner = "nvim-treesitter";
repo = "nvim-treesitter"; repo = "nvim-treesitter";
rev = "c9b11ac70c24a3854998c9a92c94759b1d1b52ef"; rev = "3cfbde4db05dc9f3f38fcee212849799bb6f2e54";
sha256 = "AbLilgMrkzUs/fjshFettSmrdISjBF6nqHVngoynaH8="; sha256 = "HQ9NLHhOQPB6Xcj9G6UqDAWiB0LuDs0iZzRhfyD0XKo=";
}; };
meta.homepage = "https://github.com/nvim-treesitter/nvim-treesitter"; meta.homepage = "https://github.com/nvim-treesitter/nvim-treesitter";
}; };
@ -191,12 +191,12 @@
}; };
null-ls-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix { null-ls-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "null-ls.nvim"; pname = "null-ls.nvim";
version = "1643322091"; version = "1643829703";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "jose-elias-alvarez"; owner = "jose-elias-alvarez";
repo = "null-ls.nvim"; repo = "null-ls.nvim";
rev = "2ae4a5e2e2b35716c44c104ef1afa35ecb40c444"; rev = "b8bedca6786e975216c073bbd72eb3e76f78e21b";
sha256 = "55NdHFFmuyoU0ELNnYXvhPGH1iVhyaXkm3zgkNmwO/g="; sha256 = "WTE78hReuJToqo5ndgPuCe1oTGIoPAdggT9RDnGsruw=";
}; };
meta.homepage = "https://github.com/jose-elias-alvarez/null-ls.nvim"; meta.homepage = "https://github.com/jose-elias-alvarez/null-ls.nvim";
}; };
@ -312,12 +312,12 @@
}; };
cmp-path = pkgs.vimUtils.buildVimPluginFrom2Nix { cmp-path = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "cmp-path"; pname = "cmp-path";
version = "1642430705"; version = "1643823794";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "hrsh7th"; owner = "hrsh7th";
repo = "cmp-path"; repo = "cmp-path";
rev = "c5230cb439df9547294678d0f1c1465ad7989e5f"; rev = "466b6b8270f7ba89abd59f402c73f63c7331ff6e";
sha256 = "qKPYOW+Nid3CdFJfeU1JVb9zaDZAk2F/WQ4ddjNDRnk="; sha256 = "xYzTpqVKpBBnajqqRRzAXlHAC13VGK1D9mFr3bntepY=";
}; };
meta.homepage = "https://github.com/hrsh7th/cmp-path"; meta.homepage = "https://github.com/hrsh7th/cmp-path";
}; };
@ -433,12 +433,12 @@
}; };
undotree = pkgs.vimUtils.buildVimPluginFrom2Nix { undotree = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "undotree"; pname = "undotree";
version = "1640333528"; version = "1643910486";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "mbbill"; owner = "mbbill";
repo = "undotree"; repo = "undotree";
rev = "c4984fc6dcc6c4e190f2f8cd5fffb65b0aaa51d2"; rev = "8a01863a8204b2382ec341d0203c4e9665212221";
sha256 = "3x01yjy4j7y/SjsUxnI2xOGQxo7GdZsCsBQyqOhK6pk="; sha256 = "43Yco/5Q2t8lVRQbgeXLpygXga0cKmLfdjvCPCsPDGo=";
}; };
meta.homepage = "https://github.com/mbbill/undotree"; meta.homepage = "https://github.com/mbbill/undotree";
}; };
@ -532,12 +532,12 @@
}; };
nvim-notify = pkgs.vimUtils.buildVimPluginFrom2Nix { nvim-notify = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "nvim-notify"; pname = "nvim-notify";
version = "1643665769"; version = "1643832273";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "rcarriga"; owner = "rcarriga";
repo = "nvim-notify"; repo = "nvim-notify";
rev = "83ebb5971eaecc0b2c70fb4ed540e87cbf50af6a"; rev = "d6f880728da487d0ac4f957835c46b3f2af91fca";
sha256 = "fGW87jNWO3j1r6cU8OKTb0ggPJQFJXPDDAGAg4ZTdyY="; sha256 = "vI/R92pY+qXaRrg62bcwsdNS1vLpwxrZEj3pO++jdzc=";
}; };
meta.homepage = "https://github.com/rcarriga/nvim-notify"; meta.homepage = "https://github.com/rcarriga/nvim-notify";
}; };

View file

@ -1,8 +0,0 @@
#!/bin/sh
mkdir -p "$HOME/.cache/fish"
nix flake metadata "$HOME/.config/nixpkgs" --json 2>/dev/null | \
jq -r '.locks.nodes.nixpkgs.locked | "\(.type):\(.owner)/\(.repo)/\(.rev)"' | \
xargs -I {} nix flake metadata {} --json | \
jq -r '. | "nixpkgs=\(.path)"' >"$HOME/.cache/fish/nix_path_value"

View file

@ -0,0 +1,13 @@
#!/usr/bin/env fish
pushd ~/.config/nixpkgs
rm -rf result
set system_old (readlink /run/current-system)
env TERM=xterm-256color darwin-rebuild switch --flake .
set system_new (readlink /run/current-system)
nvd diff "$system_old" "$system_new"
rm -f result
popd