Skip to content

Instantly share code, notes, and snippets.

@bsag
Last active July 12, 2023 19:38
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsag/552a68a198df04ddbc9ddb7b16b170bf to your computer and use it in GitHub Desktop.
Save bsag/552a68a198df04ddbc9ddb7b16b170bf to your computer and use it in GitHub Desktop.
Selected files from my standalone Nix/Home Manager set up on macOS to illustrate the general approach

These files illustrate the way that I have set up Nix and Home Manager for standalone use on macOS on both an Intel and Apple Silicon machine, in case the examples are useful to anyone. Some of the configuration is separated out into separate files in configs/ which get imported in home.nix. Some of my existing dotfiles are placed in dotfiles/ and then symlinked in by Nix to the location that that the system expects to find them.

It is a work in progress so currently I am handling installation of R separately.

# flake.nix
{
description = "My Home Manager flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
nix-colors.url = "github:misterio77/nix-colors";
};
outputs = { home-manager, nix-colors, ... }:
let
username = "myusername";
config = {
configuration = import ./home.nix;
inherit username;
homeDirectory = "/Users/${username}";
# Update the state version as needed.
# See the changelog here:
# https://nix-community.github.io/home-manager/release-notes.html#sec-release-21.05
stateVersion = "22.05";
# Optionally use extraSpecialArgs
# to pass through arguments to home.nix
extraSpecialArgs = {
inherit nix-colors;
};
};
in {
homeConfigurations."${username}@host1" = home-manager.lib.homeManagerConfiguration (config // {system = "x86_64-darwin";});
homeConfigurations."${username}@host2" = home-manager.lib.homeManagerConfiguration (config // {system = "aarch64-darwin";});
};
}
{ config, pkgs, lib, nix-colors, ... }:
{
### Import modular *.nix files ###
imports = [
nix-colors.homeManagerModule
./configs/git.nix
./configs/fish.nix
./configs/zsh.nix
./configs/neovim.nix
];
# Set chosen base16 color scheme
colorscheme = nix-colors.colorSchemes.material;
# set up path and env variables for shells
home.sessionPath =
[ "$HOME/.emacs.d/bin" "$HOME/.local/bin" "$HOME/go/bin" "$PYENV_ROOT/bin" ];
home.sessionVariables = {
PAGER = "most";
MANPAGER = "most";
LANG = "en_GB.UTF-8";
BROWSER = "open";
EDITOR = "nvim";
VISUAL = "emacs";
PYENV_ROOT = "$HOME/.pyenv";
BASE16_SHELL = "$HOME/.config/base16-shell/";
FZF_DEFAULT_OPTS = '' --color=bg+:"#${config.colorscheme.colors.base01}",bg:"#${config.colorscheme.colors.base00}",spinner:"#${config.colorscheme.colors.base0C}",hl:"#${config.colorscheme.colors.base0D}" --color=fg:"#${config.colorscheme.colors.base04}",header:"#${config.colorscheme.colors.base0D}",info:"#${config.colorscheme.colors.base0A}",pointer:"#${config.colorscheme.colors.base0C}" --color=marker:"#${config.colorscheme.colors.base0C}",fg+:"#${config.colorscheme.colors.base06}",prompt:"#${config.colorscheme.colors.base0A}",hl+:"#${config.colorscheme.colors.base0D}"'';
# For hunspell in Emacs
DICPATH = "$HOME/.nix-profile/share/hunspell";
};
home.shellAliases = {
ls = "lsd";
ll = "lsd -l";
lla = "lsd -la";
ld = "lsd --tree d";
hms = "home-manager switch";
};
# https://search.nixos.org/packages?channel=unstable
home.packages = with pkgs; [
# pkgs is the set of all packages in the default home.nix implementation
# tools for nix itself
nix
nixfmt
## shell tools
lsd # nicer, more modern ls command
most # pager
tree
jq # pretty print JSON
fd # fd, a nicer find
wget
rsync
# searching
(ripgrep.override { withPCRE2 = true; })
# tools for editors etc.
aspell
emacs-all-the-icons-fonts
hunspell
hunspellDicts.en-gb-large
languagetool
sdcv
gnuplot
# fonts
nerdfonts
# langs
nodejs
# node packages for linting JS/HTML/CSS in Doom
nodePackages.stylelint
nodePackages.js-beautify
sass
(python39.withPackages(ps: with ps; [
setuptools
flake8
pylint
proselint
ipython
pytest
nose
]))
# for project R directories, copy r-flake.nix
# (rWrapper.override {
# packages = with rPackages; [
# knitr
# rlang
# tinytex
# rmarkdown
# devtools
# renv];})
#
#hugo # temp broken
pandoc-eqnos
pandoc-fignos
pandoc-secnos
pandoc-tablenos
texlive.combined.scheme-full
];
### Programs needing configuration ###
# bat, a better cat ;-)
programs.bat = {
enable = true;
config = {
theme = "base16";
# Show line numbers, Git modifications and file header (but no grid)
style = "numbers,changes,header,grid";
italic-text = "always";
# Add mouse scrolling support in less (does not work with older
# versions of "less")
pager = "less -FR";
};
};
# fzf
programs.fzf = {
enable = true;
enableZshIntegration = true;
};
programs.zoxide = {
enable = true;
enableFishIntegration = true;
enableZshIntegration = true;
};
# direnv
programs.direnv = {
enable = true;
nix-direnv.enable = true;
enableZshIntegration = true;
stdlib = ''
# Usage: in .envrc, `use python 3.7.2`
use_python() {
local python_root=$(pyenv root)/versions/$1
load_prefix "$python_root"
if [[ -x "$python_root/bin/python" ]]; then
layout python "$python_root/bin/python"
else
echo "Error: $python_root/bin/python can't be executed."
exit
fi
};
'';
};
programs.starship = {
enable = true;
enableFishIntegration = true;
enableZshIntegration = true;
settings = {
shell = { disabled = false; };
rlang = { detect_files = [ ]; };
python = { disabled = true; };
};
};
programs.go = {
enable = true;
goPath = "go";
goBin = "go/bin";
};
programs.emacs = {
enable = true;
package = pkgs.emacs28NativeComp;
};
programs.pandoc = {
enable = true;
};
### Configuration for packages which do not have nix configuration ###
### built in. ###
# or :
## Install the gitconfig file, as .gitconfig in the home directory
# home.file.".gitconfig".source = ./gitconfig;
# Doom private config
xdg.configFile."doom".source = ./dotfiles/doom;
xdg.configFile."pandoc".source = ./dotfiles/pandoc;
# lsd configs
xdg.dataFile."lsd/config.yaml".source = ./dotfiles/lsd/config.yaml;
# import the base16 configs
xdg.configFile."base16-shell".source = ./dotfiles/base16-shell;
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
}
# ./configs/neovim.nix
{config, pkgs, lib, nix-colors, ...}:
with nix-colors.lib { inherit pkgs; };
{
programs.neovim = {
enable = true;
vimAlias = true;
extraConfig = ''
" Simple config: https://github.com/trirpi/simple-nvim-config/blob/master/init.vim
" set backgrounds
set background=dark
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
set termguicolors
"colorscheme onedark
" enable line numbers
set number
" go to different screen with ctrl JKLH
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" autoclose the preview window
let g:ycm_autoclose_preview_window_after_insertion = 1
let g:ycm_autoclose_preview_window_after_completion = 1
" all extra windows pop up at the bottom
set splitbelow
" persistent undo
set undodir=~/.config/nvim/undodir
set undofile
" set tab as 4 spaces
set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
'';
plugins = with pkgs.vimPlugins; [
vim-sensible
vim-nix
vim-fish
{ plugin = vim-airline;
config = "let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1";
}
{ plugin = vim-airline-themes;
config = "let g:airline_theme='tomorrow'";
}
# nix-colors: sets colorscheme from base16 in home.nix
{ plugin = vimThemeFromScheme { scheme = config.colorscheme; };
config = "colorscheme nix-${config.colorscheme.slug}";
}
vim-polyglot
YouCompleteMe
syntastic
ctrlp
delimitMate
];
};
}
@aotarola
Copy link

I'm facing this issue when doing home-manager switch :

error: flake 'path:/Users/aotarola/.config/nixpkgs' does not provide attribute 'packages.aarch64-darwin.homeConfigurations.aotarola.activationPackage', 'legacyPackages.aarch64-darwin.homeConfigurations.aotarola.activationPackage' or 'homeConfigurations.aotarola.activationPackage'

I'm fairly new to home-manager, and super new to flake, so I'm probably missing some steps (?) 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment