2024-07-16 11:31:08 +10:00
{
inputs = {
2024-07-16 20:00:34 +10:00
# Principle inputs (updated by `nix run .#update`)
nixpkgs . url = " g i t h u b : n i x o s / n i x p k g s / n i x o s - u n s t a b l e " ;
nix-darwin . url = " g i t h u b : l n l 7 / n i x - d a r w i n / m a s t e r " ;
nix-darwin . inputs . nixpkgs . follows = " n i x p k g s " ;
home-manager . url = " g i t h u b : n i x - c o m m u n i t y / h o m e - m a n a g e r " ;
home-manager . inputs . nixpkgs . follows = " n i x p k g s " ;
flake-parts . url = " g i t h u b : h e r c u l e s - c i / f l a k e - p a r t s " ;
2024-07-17 10:57:58 +10:00
nixos-flake . url = " g i t h u b : s r i d / n i x o s - f l a k e " ;
2024-07-16 20:00:34 +10:00
# Neovim
nixvim = {
url = " g i t h u b : n i x - c o m m u n i t y / n i x v i m " ;
# nixvim has a lot of inputs we are using, so pin them to same version
inputs = {
nixpkgs . follows = " n i x p k g s " ;
nix-darwin . follows = " n i x - d a r w i n " ;
home-manager . follows = " h o m e - m a n a g e r " ;
flake-parts . follows = " f l a k e - p a r t s " ;
treefmt-nix . follows = " t r e e f m t - n i x " ;
} ;
} ;
2024-07-16 11:31:08 +10:00
2024-07-17 14:40:55 +10:00
# https://developer.1password.com/docs/cli/shell-plugins/nix/
_1password-shell-plugins = {
url = " g i t h u b : 1 P a s s w o r d / s h e l l - p l u g i n s " ;
inputs . nixpkgs . follows = " n i x p k g s " ;
inputs . flake-utils . follows = " n i x v i m / d e v s h e l l / f l a k e - u t i l s " ;
} ;
2024-07-16 20:00:34 +10:00
nix-index-database . url = " g i t h u b : n i x - c o m m u n i t y / n i x - i n d e x - d a t a b a s e " ;
nix-index-database . inputs . nixpkgs . follows = " n i x p k g s " ;
treefmt-nix . url = " g i t h u b : n u m t i d e / t r e e f m t - n i x " ;
treefmt-nix . inputs . nixpkgs . follows = " n i x p k g s " ;
2024-07-16 11:31:08 +10:00
} ;
2024-07-16 20:00:34 +10:00
outputs = inputs @ { self , . . . }:
inputs . flake-parts . lib . mkFlake { inherit inputs ; }
(
let
myUsername = " b j e a n e s " ;
in
{
systems = [ " x 8 6 _ 6 4 - l i n u x " " a a r c h 6 4 - l i n u x " " a a r c h 6 4 - d a r w i n " ] ;
imports = [
inputs . nixos-flake . flakeModule
inputs . treefmt-nix . flakeModule
] ;
# flake-parts will export this wholesale as the flakes' `outputs`, with no per-system transposition. See `perSystem` below for this.
flake = {
# Configurations for Linux (NixOS) machines
nixosConfigurations = { } ;
# Configurations for macOS machines
darwinConfigurations = {
# Personal M1 Max MBP
Bandersnatch = self . nixos-flake . lib . mkMacosSystem {
nixpkgs . hostPlatform = " a a r c h 6 4 - d a r w i n " ;
imports = [
self . nixosModules . common # See below for "nixosModules"!
self . nixosModules . darwin
# Your machine's configuration.nix goes here
( { pkgs , . . . }: {
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system . stateVersion = 4 ;
} )
# Your home-manager configuration
self . darwinModules_ . home-manager
{
home-manager . users . ${ myUsername } = {
imports = [
self . homeModules . common # See below for "homeModules"!
self . homeModules . darwin
] ;
home . stateVersion = " 2 4 . 0 5 " ;
} ;
}
] ;
} ;
} ;
# All nixos/nix-darwin configurations are kept here.
nixosModules = {
# Common nixos/nix-darwin configuration shared between Linux and macOS.
2024-07-17 14:17:29 +10:00
common = { pkgs , . . . }:
2024-07-16 20:00:34 +10:00
{
home-manager . backupFileExtension = " b a k - h m " ;
home-manager . useUserPackages = true ;
# home-manager.verbose = true;
nixpkgs . config . allowUnfree = true ;
2024-07-17 14:03:08 +10:00
environment . variables = { } ;
2024-07-16 20:00:34 +10:00
environment . systemPackages = with pkgs ; [
git
bat
] ;
} ;
# NixOS specific configuration
linux = { pkgs , . . . }: {
2024-07-17 14:03:08 +10:00
imports = [
inputs . nixvim . nixosModules . nixvim
] ;
2024-07-16 20:00:34 +10:00
users . users . ${ myUsername } . isNormalUser = true ;
} ;
# nix-darwin specific configuration
darwin = { pkgs , . . . }: {
2024-07-17 14:03:08 +10:00
imports = [
inputs . nixvim . nixDarwinModules . nixvim
] ;
2024-07-16 20:00:34 +10:00
nix = {
useDaemon = true ;
## Control the version of Nix that nix-darwin uses. At time of writing, it defaults to 2.18.x, but latest is 2.23.3.
## Commented out because versions after 2.18.x are apparently pretty buggy
# package = pkgs.nixVersions.latest;
# Use Lix (a Nix-compatible lang -- https://lix.systems)
package = pkgs . lix ;
settings = {
trusted-users = [ " r o o t " myUsername ] ;
allowed-users = [ " r o o t " myUsername " @ n i x b l d " ] ;
} ;
extraOptions = ''
extra-nix-path = " n i x p k g s = f l a k e : n i x p k g s "
experimental-features = nix-command flakes
'' ;
} ;
homebrew . enable = true ;
# This needs to be here in addition to the home-manager configuration below in order to write /etc/zshenv to correctly configure ZSH. This is confusing, but...
# https://github.com/LnL7/nix-darwin/issues/1003
# https://github.com/LnL7/nix-darwin/issues/922#issuecomment-2041430035
programs . zsh . enable = true ;
2024-07-17 14:05:22 +10:00
programs . bash . enable = true ;
2024-07-16 20:00:34 +10:00
security . pam . enableSudoTouchIdAuth = true ;
users . users . ${ myUsername } . home = " / U s e r s / ${ myUsername } " ;
} ;
} ;
# All home-manager configurations are kept here; they are evaluated in the context of the user's home-manager profile.
# i.e. `foo = true` is equivalent to `home-manager.users.bjeanes.foo = true`.
homeModules = {
# Common home-manager configuration shared between Linux and macOS.
2024-07-17 14:17:29 +10:00
common = { pkgs , . . . }:
2024-07-17 14:07:30 +10:00
{
imports = [
inputs . nixvim . homeManagerModules . nixvim
2024-07-17 14:40:55 +10:00
inputs . _1password-shell-plugins . hmModules . default
2024-07-17 14:07:30 +10:00
] ;
home . shellAliases = {
2024-07-17 14:20:23 +10:00
g = " g i t " ;
l = " l s " ;
ll = " l s - l a " ;
arst = " a s d f " ; # Colemak home row
cat = " b a t " ;
2024-07-16 20:00:34 +10:00
} ;
2024-07-17 14:03:08 +10:00
programs . nixvim = {
enable = true ;
defaultEditor = true ;
viAlias = true ;
vimAlias = true ;
} ;
2024-07-16 20:00:34 +10:00
programs . git = {
enable = true ;
aliases = {
2024-07-16 23:52:46 +10:00
br = " b r a n c h " ;
c = " c o m m i t - v " ;
2024-07-16 20:00:34 +10:00
co = " c h e c k o u t " ;
2024-07-16 23:52:46 +10:00
commit = " c o m m i t - v " ;
lg = " l o g - - d e c o r a t e - - g r a p h - - p r e t t y = f o r m a t : ' % C r e d % h % C r e s e t - % C ( y e l l o w ) % d % C r e s e t % s % C g r e e n ( % c r ) % C r e s e t ' - - a b b r e v - c o m m i t - - d a t e = r e l a t i v e " ;
2024-07-16 20:00:34 +10:00
st = " s t a t u s " ;
2024-07-16 23:52:46 +10:00
unadd = " r e s e t H E A D " ;
me = " ! s h - c ' e c h o ` g i t c o n f i g u s e r . n a m e ` \\ < ` g i t c o n f i g u s e r . e m a i l ` \\ > ' " ;
mine = " ! s h - c ' g i t l g - - a u t h o r = \" ` g i t m e ` \" ' " ;
2024-07-16 20:00:34 +10:00
} ;
2024-07-16 23:53:44 +10:00
extraConfig = {
apply . whitespace = " f i x " ;
color = {
ui = " a u t o " ;
branch = " a u t o " ;
diff = " a u t o " ;
status = " a u t o " ;
} ;
branch = {
autosetupmerge = " a l w a y s " ;
autosetuprebase = " l o c a l " ;
} ;
pull . rebase = true ;
push . default = " c u r r e n t " ;
remote . pushDefault = " o r i g i n " ;
status = {
short = true ;
branch = true ;
showUntrackedFiles = " a l l " ;
} ;
} ;
2024-07-17 14:17:46 +10:00
ignores = [
" * . s w p "
] ;
2024-07-16 20:00:34 +10:00
} ;
2024-07-16 23:53:44 +10:00
# difftastic will show syntactical/structural changes in diffs
# programs.git.difftastic.enable = true;
# delta will show diffs with language-aware syntax highlighting
programs . git . delta . enable = true ;
programs . git . delta . package = pkgs . delta ;
2024-07-17 14:18:02 +10:00
programs . bash . initExtra = /* b a s h */ ''
2024-07-17 00:11:20 +10:00
eval " $ ( ${ pkgs . delta } / b i n / d e l t a - - g e n e r a t e - c o m p l e t i o n b a s h ) "
2024-07-16 23:53:44 +10:00
'' ;
programs . zsh . initExtra = /* z s h */ ''
2024-07-17 00:11:20 +10:00
eval " $ ( ${ pkgs . delta } / b i n / d e l t a - - g e n e r a t e - c o m p l e t i o n z s h ) "
2024-07-16 23:53:44 +10:00
'' ;
2024-07-17 14:10:59 +10:00
programs . lazygit . enable = true ;
programs . lazygit . settings = {
# lazygit can pull the pager out of Git's config, but `programs.git.delta.enable = true` sets
# the pager to `delta` directly, wheras `lazygit` requires `delta` to be called with
# `--paging=never` due to rendering issues.
#
# https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md
git . paging . pager = " ${ pkgs . delta } / b i n / d e l t a - - p a g i n g = n e v e r " ;
update . method = " n e v e r " ; # we will manage it here
disableStartupPopups = true ;
os . editPreset = " n v i m " ;
} ;
2024-07-16 20:00:34 +10:00
programs . zsh = {
enable = true ;
enableCompletion = true ;
autocd = true ;
syntaxHighlighting . enable = true ;
autosuggestion . enable = true ;
} ;
2024-07-17 14:18:02 +10:00
programs . bash = {
enable = true ;
enableCompletion = true ;
enableVteIntegration = true ;
} ;
2024-07-17 14:09:50 +10:00
programs . starship . enable = true ;
2024-07-16 20:00:34 +10:00
2024-07-16 23:51:41 +10:00
programs . direnv . enable = true ;
programs . direnv . enableZshIntegration = true ;
programs . direnv . enableBashIntegration = true ;
programs . direnv . nix-direnv . enable = true ;
2024-07-17 14:20:23 +10:00
programs . bat . enable = true ;
programs . bat . config = {
map-syntax = [
" f l a k e . l o c k : J S O N "
] ;
} ;
2024-07-17 14:22:12 +10:00
# By default, this integration also hooks into shell ^R for history search, but atuin is better
# and fortunately appears to take precedence when both are enabled
2024-07-17 14:21:23 +10:00
programs . fzf . enable = true ;
programs . fzf . enableZshIntegration = true ;
programs . fzf . enableBashIntegration = true ;
programs . fzf . fileWidgetOptions = [
" - - p r e v i e w ' ${ pkgs . bat } / b i n / b a t - - c o l o r = a l w a y s - - s t y l e = n u m b e r s - - l i n e - r a n g e : 5 0 0 { } ' "
] ;
2024-07-17 14:20:23 +10:00
2024-07-17 14:22:12 +10:00
# Shell history recording + UI
programs . atuin . enable = true ;
programs . atuin . enableZshIntegration = true ;
programs . atuin . enableBashIntegration = true ;
programs . atuin . settings = {
dialect = " u k " ;
filter_mode_shell_up_key_binding = " s e s s i o n " ;
workspaces = true ;
style = " c o m p a c t " ;
inline_height = 20 ;
enter_accept = false ;
ctrl_n_shortcuts = true ;
stats . common_prefix = [
" s u d o "
" t i m e "
] ;
} ;
2024-07-17 14:40:55 +10:00
programs . _1password-shell-plugins = {
enable = true ;
plugins = with pkgs ; [
gh # github
cargo
heroku
tea # gitea
glab # gitlab
] ;
} ;
2024-07-16 20:00:34 +10:00
home . packages = with pkgs ; [
2024-07-17 14:24:09 +10:00
# TODO: https://gist.github.com/axelbdt/0de9f5f9ba8a2100326b793f7bfb8658?permalink_comment_id=4977667#gistcomment-4977667
asdf-vm
2024-07-16 20:00:34 +10:00
] ;
} ;
# home-manager config specific to Linux / NixOS
linux = { } ;
# home-manager config specific to Darwin
2024-07-17 14:03:08 +10:00
darwin = {
# Yank/paste in Neovim to/from macOS clipboard by default
programs . nixvim . clipboard . register = " u n n a m e d p l u s " ;
} ;
2024-07-16 20:00:34 +10:00
} ;
} ;
perSystem = { self' , inputs' , pkgs , system , config , . . . }: {
# Non-NixOS Linux machine TumTum
legacyPackages . homeConfigurations . " ${ myUsername } @ t u m t u m " =
self . nixos-flake . lib . mkHomeConfiguration pkgs {
imports = [
self . homeModules . common
self . homeModules . linux
] ;
} ;
# Make `nix run` equivalent to `nix run .#activate`
packages . default = self' . packages . activate ;
treefmt . config = {
projectRootFile = " f l a k e . l o c k " ;
programs . nixpkgs-fmt . enable = true ;
} ;
} ;
}
) ;
2024-07-16 11:31:08 +10:00
}