First pass at a Nix flake for my laptop

Heavily inspired by these:
- https://github.com/zmre/mac-nix-simple-example
- https://github.com/dustinlyons/nixos-config
This commit is contained in:
Gene Liverman 2023-09-08 16:49:45 -04:00 committed by Gene Liverman
parent 1fb4bf12c8
commit 6430f175b2
6 changed files with 584 additions and 0 deletions

187
flake.lock generated Normal file
View file

@ -0,0 +1,187 @@
{
"nodes": {
"brew-src": {
"flake": false,
"locked": {
"lastModified": 1690184446,
"narHash": "sha256-fGjvNY6ON/cdExCfwhfqmHzoxs3AZ0sev7vyBHfPGJo=",
"owner": "Homebrew",
"repo": "brew",
"rev": "3b3300546b5a4e40b74f4ee33cf225cca280defe",
"type": "github"
},
"original": {
"owner": "Homebrew",
"ref": "4.1.1",
"repo": "brew",
"type": "github"
}
},
"darwin": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1692248770,
"narHash": "sha256-tZeFpETKQGbgnaSIO1AGWD27IyTcBm4D+A9d7ulQ4NM=",
"owner": "lnl7",
"repo": "nix-darwin",
"rev": "511177ffe8226c78c9cf6a92a7b5f2df3684956b",
"type": "github"
},
"original": {
"owner": "lnl7",
"repo": "nix-darwin",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1687709756,
"narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1694375657,
"narHash": "sha256-32X8dcty4vPXx+D4yJPQZBo5hJ1NQikALhevGv6elO4=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "f7848d3e5f15ed02e3f286029697e41ee31662d7",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "home-manager",
"type": "github"
}
},
"nix-darwin": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1688307440,
"narHash": "sha256-7PTjbN+/+b799YN7Tk2SS5Vh8A0L3gBo8hmB7Y0VXug=",
"owner": "LnL7",
"repo": "nix-darwin",
"rev": "b06bab83bdf285ea0ae3c8e145a081eb95959047",
"type": "github"
},
"original": {
"owner": "LnL7",
"repo": "nix-darwin",
"type": "github"
}
},
"nix-homebrew": {
"inputs": {
"brew-src": "brew-src",
"flake-utils": "flake-utils",
"nix-darwin": "nix-darwin",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1690495710,
"narHash": "sha256-7yF5A16Ayorrpcal74mRB1EqwUAHfXnoCIgDvj+ylgo=",
"owner": "zhaofengli-wip",
"repo": "nix-homebrew",
"rev": "d2738b78fd0f304f5a7ed4764b736ed2c7169b94",
"type": "github"
},
"original": {
"owner": "zhaofengli-wip",
"repo": "nix-homebrew",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1687274257,
"narHash": "sha256-TutzPriQcZ8FghDhEolnHcYU2oHIG5XWF+/SUBNnAOE=",
"path": "/nix/store/22qgs3skscd9bmrxv9xv4q5d4wwm5ppx-source",
"rev": "2c9ecd1f0400076a4d6b2193ad468ff0a7e7fdc5",
"type": "path"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1688049487,
"narHash": "sha256-100g4iaKC9MalDjUW9iN6Jl/OocTDtXdeAj7pEGIRh4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4bc72cae107788bf3f24f30db2e2f685c9298dc9",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1694459622,
"narHash": "sha256-PcbBuRJKFxgb+CUQ3sliI5oRaKHHAV+OSTv6GPAccEA=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "bb446a19f77e8d1d0c5ada7069d21a001442fc73",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"darwin": "darwin",
"home-manager": "home-manager",
"nix-homebrew": "nix-homebrew",
"nixpkgs": "nixpkgs_3"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

57
flake.nix Normal file
View file

@ -0,0 +1,57 @@
{
description = "A flake for all my stuff";
inputs = {
# Where we get most of our software. Giant mono repo with recipes
# called derivations that say how to build software.
nixpkgs.url = "github:nixos/nixpkgs";
# Controls system level software and settings including fonts
darwin = {
url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
# Manages things in home directory
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
# Manage Homebrew itself
nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew";
}; # end inputs
outputs = { self, nixpkgs, darwin, home-manager, nix-homebrew, ... }: {
# This is only set to work with x86 macOS right now... that will need to be updated
darwinConfigurations.Blue-Rock = darwin.lib.darwinSystem {
system = "x86_64-darwin";
pkgs = import nixpkgs { system = "x86_64-darwin"; };
modules = [
nix-homebrew.darwinModules.nix-homebrew
{
nix-homebrew = {
# Install Homebrew under the default prefix
enable = true;
# User owning the Homebrew prefix
user = "gene.liverman";
# Automatically migrate existing Homebrew installations
autoMigrate = true;
};
}
./modules/darwin
home-manager.darwinModules.home-manager
{
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users."gene.liverman".imports = [ ./modules/home-manager ];
};
}
]; # end modules
}; # end of darwinConfigurations.Blue-Rock
};
}

View file

@ -13,6 +13,7 @@ Plugin 'elzr/vim-json' " provides syntax highlighting for JSO
Plugin 'garbas/vim-snipmate' " provides code snippets
Plugin 'godlygeek/tabular' " provides a method for lining things up
Plugin 'honza/vim-snippets' " provides snippets for use with vim-snipmate
Plugin 'LnL7/vim-nix' " support for writing Nix expressions in vim
Plugin 'MarcWeber/vim-addon-mw-utils' " a utility used by vim-snipmate
Plugin 'mrk21/yaml-vim' " provides indentation and syntax highlighting for yaml
Plugin 'rbong/vim-flog' " git branch viewer built on fugitive

View file

@ -0,0 +1,61 @@
{ pkgs, ... }: {
nix.extraOptions = ''
# Generated by https://github.com/DeterminateSystems/nix-installer, version 0.11.0.
extra-nix-path = nixpkgs=flake:nixpkgs
experimental-features = nix-command flakes auto-allocate-uids
build-users-group = nixbld
bash-prompt-prefix = (nix:$name)\040
'';
fonts.fontDir.enable = false; # True will uninstall other fonts, false installs, but doesn't uninstall
fonts.fonts = [ (pkgs.nerdfonts.override { fonts = [
"Hack"
"SourceCodePro"
]; }) ];
programs.zsh.enable = true;
services.nix-daemon.enable = true;
system.stateVersion = 4;
users.users."gene.liverman".home = "/Users/gene.liverman";
environment = {
shells = with pkgs; [ bash zsh ];
loginShell = pkgs.zsh;
pathsToLink = [
"/Applications"
"/share/zsh"
];
systemPackages = with pkgs; [
coreutils
#adr-tools
chart-testing
colordiff
dog
dos2unix
# dust
subversion
# git-svn
gotop
# helm
hub
hugo
kopia
# kubernetes-cli
kubectx
mas
mtr
nmap
# node
openjdk
rename
tree
watch
wget
yq
];
};
}

View file

@ -0,0 +1,104 @@
{ pkgs, ... }: {
home.stateVersion = "23.11";
# home.packages = with pkgs; [
#
# ];
home.sessionVariables = {
CLICLOLOR = 1;
EDITOR = "vim";
PAGER = "less";
};
programs = {
bat.enable = true;
eza.enable = true;
gh.enable = true;
git = {
enable = true;
lfs.enable = true;
};
go = {
enable = true;
goPath = "go";
};
jq.enable = true;
k9s.enable = true;
neovim.enable = true;
oh-my-posh = {
enable = true;
enableZshIntegration = true;
settings = builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile ./files/beanbag.omp.json));
};
vim.enable = true;
zsh = {
enable = true;
enableCompletion = true;
enableAutosuggestions = true;
history.save = 1000000;
history.size = 1000000;
initExtra = ''
[ -f ~/.private-env ] && source ~/.private-env || echo '~/.private-env is missing'
# Start GPG agent
# Some tips from https://hedberg.io/yubikey-for-ssh/ helped simplify this:
if [[ $(uname) == 'Darwin' ]]; then
# Add GPG Suite binaries to the path:
export PATH=/usr/local/MacGPG2/bin:$PATH
fi
export GPG_TTY=$(tty)
if [[ `uname` == 'Linux' ]]; then
alias uwgconnect='nmcli dev wifi connect SecureWest password'
alias uwgforget='nmcli connection delete SecureWest'
alias ykey='sudo systemctl restart pcscd && sudo pkill -9 gpg-agent && source ~/.zshrc; ssh-add -L'
else
alias currentwifi='networksetup -getairportnetwork en0 |cut -d ":" -f2- | cut -d " " -f2-'
alias uwgconnect='networksetup -setairportnetwork en0 SecureWest'
alias uwgforget='networksetup -removepreferredwirelessnetwork en0 SecureWest'
alias ykey='pkill -9 gpg-agent && source ~/.zshrc; ssh-add -L'
fi
if [[ `uname` != 'Linux' ]]; then
function otpon() {
osascript -e 'tell application "yubiswitch" to KeyOn'
}
function otpoff() {
osascript -e 'tell application "yubiswitch" to KeyOff'
}
fi
'';
oh-my-zsh = {
enable = true;
plugins = [
"bundler"
"gem"
"git"
"github"
"history"
"kubectl"
"macos"
"pip"
"terraform"
"vagrant"
"vscode"
];
};
shellAliases = {
beo = "bundle exec onceover run spec --trace --force";
biv = "bundle install --path=vendor/bundle";
ce = "code-exploration";
gbc = ''
git branch --merged | command grep -vE "^(\*|\s*(main|master|develop|production)\s*$)" | command xargs -n 1 git branch -d
'';
gitextract = "git log --pretty=email --patch-with-stat --reverse --full-index --binary --";
gpge = "gpg2 --encrypt --sign --armor -r ";
hubpr = "hub pull-request --push --browse";
pssh = "ssh -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' -o PubkeyAcceptedKeyTypes=+ssh-rsa -o HostKeyAlgorithms=+ssh-rsa -o KexAlgorithms=+diffie-hellman-group1-sha1 -i ~/.ssh/id_rsa-acceptance";
sal = "ssh-add -L";
st = "open -a SourceTree";
sz = "source ~/.zshrc";
usegpg = "killall ssh-agent; export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) && gpgconf --launch gpg-agent";
usessh = "gpgconf --kill gpg-agent";
};
}; # end zsh
};
}

View file

@ -0,0 +1,174 @@
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"version": 2,
"final_space": true,
"palette": {
"line-connector": "#00ff00",
"hostname": "#62c0ff",
"pwd": "#ffff00",
"git-fg-clean": "#62c0ff",
"git-fg-changed": "#6287ff",
"git-fg-ahead-and-behind": "#7f62ff",
"git-fg-ahead": "#9962ff",
"git-fg-behind": "#c062ff",
"svn-fg-clean": "#62c0ff",
"svn-fg-changed": "#6287ff",
"kubectl-fg": "#62c0ff",
"kubectl-bg": "transparent",
"status-fg-okay": "#00ff00",
"status-fg-error": "#D81E5B",
"secondary-fg": "#00ff00",
"blue": "#4B95E9",
"orange": "#F07623",
"white": "#E0DEF4",
"yellow": "#F3AE35"
},
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "text",
"style": "plain",
"foreground": "p:line-connector",
"template": "\u2554"
},
{
"type": "text",
"style": "plain",
"template": " \u2615 "
},
{
"type": "session",
"style": "plain",
"foreground": "p:hostname",
"template": " {{ (split \".\" .HostName)._0 }}("
},
{
"type": "os",
"style": "plain",
"template": "{{ if .WSL }}WSL {{ end }}{{.Icon}}"
},
{
"type": "session",
"style": "plain",
"foreground": "p:hostname",
"template": "):"
},
{
"type": "path",
"style": "plain",
"foreground": "p:pwd",
"template": " \uea83 {{ path .Path .Location }}",
"properties": {
"folder_separator_icon": "/",
"style": "full"
}
},
{
"type": "kubectl",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "p:kubectl-fg",
"background": "p:kubectl-bg",
"template": " <#ff8800>(</>\uFD31 {{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}}<#ff8800>)</>"
},
{
"type": "git",
"style": "plain",
"foreground": "p:git-fg-clean",
"foreground_templates": [
"{{ if or (.Working.Changed) (.Staging.Changed) }}p:git-fg-changed{{ end }}",
"{{ if and (gt .Ahead 0) (gt .Behind 0) }}p:git-fg-ahead-and-behind{{ end }}",
"{{ if gt .Ahead 0 }}p:git-fg-ahead{{ end }}",
"{{ if gt .Behind 0 }}p:git-fg-behind{{ end }}"
],
"template": " <#ff8800>on</> {{ if .UpstreamURL }}{{ url .UpstreamIcon .UpstreamURL }} {{ end }}{{ url .HEAD .Kraken }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}",
"properties": {
"branch_max_length": 25,
"fetch_stash_count": true,
"fetch_status": true,
"fetch_upstream_icon": true
}
},
{
"type": "svn",
"style": "plain",
"foreground": "p:svn-fg-clean",
"foreground_templates": [
"{{ if (.Working.Changed) }}p:svn-fg-changed{{ end }}"
],
"template": " <#ff8800>on svn</> \ue0a0{{.Branch}} r{{.BaseRev}}{{ if .Working.Changed }} \uf044 {{.Working.String}}{{ end }}",
"properties": {
"fetch_status": true
}
},
{
"type": "status",
"style": "diamond",
"foreground": "p:status-fg-okay",
"foreground_templates": [
"{{ if gt .Code 0 }}p:status-fg-error{{ end }}"
],
"template": " (exit code {{ .Code }})",
"properties": {
"always_enabled": false
}
}
]
},
{
"type": "prompt",
"alignment": "left",
"newline": true,
"segments": [
{
"foreground": "p:line-connector",
"style": "plain",
"template": "\u255A\u1405",
"type": "text"
}
]
}
],
"tooltips": [
{
"type": "aws",
"tips": [
"aws"
],
"style": "diamond",
"foreground": "p:white",
"background": "p:orange",
"leading_diamond": "\ue0b0",
"trailing_diamond": "\ue0b4",
"template": " \ue7ad {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} ",
"properties": {
"display_default": true
}
},
{
"type": "az",
"tips": [
"az"
],
"style": "diamond",
"foreground": "p:white",
"background": "p:blue",
"leading_diamond": "\ue0b0",
"trailing_diamond": "\ue0b4",
"template": " \uebd8 {{ .Name }} ",
"properties": {
"display_default": true
}
}
],
"secondary_prompt": {
"foreground": "p:secondary-fg",
"template": " "
}
}