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-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.
common = { pkgs , system , . . . }:
{
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.
common = { pkgs , system , . . . }:
2024-07-17 14:07:30 +10:00
{
imports = [
inputs . nixvim . homeManagerModules . nixvim
] ;
home . shellAliases = {
2024-07-16 20:00:34 +10:00
" g " = " g i t " ;
" l " = " l s " ;
" l l " = " l s - l a " ;
" a r s t " = " a s d f " ; # Colemak home row
} ;
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-16 20:00:34 +10:00
} ;
programs . starship . enable = true ;
programs . bash . enable = true ;
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 ;
programs . bash . bashrcExtra = /* 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-16 20:00:34 +10:00
programs . zsh = {
enable = true ;
enableCompletion = true ;
autocd = true ;
syntaxHighlighting . enable = true ;
autosuggestion . enable = true ;
} ;
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-16 20:00:34 +10:00
home . packages = with pkgs ; [
asdf
] ;
} ;
# 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
}