feat: refactor home-manager configs

This commit is contained in:
Iain Learmonth 2025-07-06 21:49:22 +01:00
parent 442c9051ba
commit fca82b60ce
13 changed files with 355 additions and 150 deletions

View file

@ -1,6 +1,5 @@
{
description = "I have no idea what I'm doing";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
apple-silicon = {
@ -27,26 +26,31 @@
};
outputs =
{
self,
nixpkgs,
apple-silicon,
flake-utils,
home-manager,
nix-darwin,
nixpkgs,
nur,
self,
sops-nix,
}@inputs:
let
homeRoles = [
"desktop"
"minimal"
"server"
];
outputs = inputs.self;
overlays = [
apple-silicon.overlays.apple-silicon-overlay
nur.overlays.default
];
supportedSystems = [
"x86_64-linux"
"aarch64-darwin"
"aarch64-linux"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
overlays = [
apple-silicon.overlays.apple-silicon-overlay
nur.overlays.default
];
in
{
nixosConfigurations = {
@ -69,31 +73,24 @@
specialArgs = inputs;
};
};
homeConfigurations = nixpkgs.lib.foldl' (
acc: system:
acc
// {
"irl-${system}" = home-manager.lib.homeManagerConfiguration {
homeManagerModules = import ./modules/home-manager;
homeConfigurations = nixpkgs.lib.foldl' (c: e:
c // {
"irl-${e.role}-${e.system}" = home-manager.lib.homeManagerConfiguration {
pkgs = import nixpkgs {
inherit system overlays;
inherit overlays;
system = e.system;
};
extraSpecialArgs = {
inherit outputs;
};
modules = [
./home/irl.nix
];
};
"irl-gui-${system}" = home-manager.lib.homeManagerConfiguration {
pkgs = import nixpkgs {
inherit system overlays;
};
modules = [
./home/irl.nix
{
irl.gui-packages = true;
}
./home-manager/irl.nix
{ role = "${e.role}"; }
];
};
}
) { } supportedSystems;
) { } (nixpkgs.lib.cartesianProduct { role = homeRoles; system = supportedSystems; });
}
// flake-utils.lib.eachSystem supportedSystems (system: {
formatter = nixpkgs.legacyPackages.${system}.nixfmt-tree;
@ -103,6 +100,7 @@
system = "aarch64-darwin";
modules = [
./darwin/common.nix
./darwin/irl-mac-mini.nix
];
};
};

40
home-manager/irl.nix Normal file
View file

@ -0,0 +1,40 @@
{
config,
lib,
outputs,
pkgs,
...
}:
{
imports = builtins.attrValues outputs.homeManagerModules;
options.role = lib.mkOption {
description = "Home role to set up";
default = "minimal";
type = with lib.types; enum ["desktop" "minimal" "server"];
};
config = {
feature.cli.enable = builtins.elem config.role ["desktop" "minimal" "server"];
feature.firefox.enable = config.role == "desktop";
feature.git.enable = builtins.elem config.role ["desktop" "server"];
feature.ops.enable = config.role == "desktop";
feature.tmux.enable = builtins.elem config.role ["desktop" "server"];
feature.vim.enable = builtins.elem config.role ["desktop" "minimal" "server"];
home.username = "irl";
home.homeDirectory =
if lib.strings.hasSuffix "darwin" pkgs.system then "/Users/irl" else "/home/irl";
home.packages = with pkgs; [
neofetch
];
home.shellAliases = {
hms =
"home-manager switch --flake ~/.config/nix-configs#irl-${config.role}-${pkgs.system}";
drs = "sudo darwin-rebuild switch --flake ~/.config/nix-configs";
};
home.stateVersion = "25.05";
programs.home-manager.enable = true;
};
}

View file

@ -1,123 +0,0 @@
{
config,
pkgs,
lib,
...
}:
let
cfg = config.irl;
in
{
options.irl.gui-packages = lib.mkEnableOption "GUI packages managed by home-manager";
config = {
home.username = "irl";
home.homeDirectory =
if lib.strings.hasSuffix "darwin" pkgs.system then "/Users/irl" else "/home/irl";
home.stateVersion = "25.05";
home.packages =
with pkgs;
[
age
fish
neofetch
nil
rust-analyzer
starship
tree
]
++ lib.optionals cfg.gui-packages [
element-desktop
];
home.shellAliases = {
hms =
"home-manager switch --flake ~/.config/nix-configs#irl"
+ (if cfg.gui-packages then "-gui" else "")
+ "-${pkgs.system}";
};
programs.bash = {
enable = true;
initExtra = ''
if [[ $(${pkgs.procps}/bin/ps --no-header --pid=$PPID --format=comm) != "fish" && -z ''${BASH_EXECUTION_STRING} ]]
then
shopt -q login_shell && LOGIN_OPTION='--login' || LOGIN_OPTION=""
exec ${pkgs.fish}/bin/fish $LOGIN_OPTION
fi
'';
};
programs.firefox = lib.mkIf cfg.gui-packages {
enable = true;
profiles.irl = {
extensions = {
force = true;
packages = with pkgs.nur.repos.rycee.firefox-addons; [
bitwarden
kagi-search
privacy-badger
recap
];
};
settings = {
"extensions.autoDisableScope" = 0;
};
};
};
programs.fish.enable = true;
programs.fzf = {
enable = true;
enableFishIntegration = true;
};
programs.git = {
delta.enable = true;
enable = true;
extraConfig = {
diff = {
algorithm = "histogram";
};
init = {
defaultBranch = "main";
};
rebase = {
autosquash = true;
autostash = true;
};
url = {
"git@github.com:".pushInsteadOf = "https://github.com/";
"git@gitlab.com:".pushInsteadOf = "https://gitlab.com/";
"git@guardianproject.dev:".pushInsteadOf = "https://guardianproject.dev/";
};
user = {
name = "irl";
email = "iain@learmonth.me";
};
};
};
programs.home-manager.enable = true;
programs.neovim = {
defaultEditor = true;
enable = true;
viAlias = true;
vimAlias = true;
vimdiffAlias = true;
plugins = with pkgs.vimPlugins; [
bufferline-nvim
lualine-nvim
nvim-lspconfig
nvim-web-devicons
];
extraLuaConfig = ''
vim.opt.termguicolors = true
require("bufferline").setup{}
require('lualine').setup{}
vim.lsp.enable("nil")
'';
};
programs.starship = {
enable = true;
enableFishIntegration = true;
enableInteractive = true;
enableTransience = true;
};
};
}

View file

@ -0,0 +1,70 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.feature.cli;
in
{
options.feature.cli = {
enable = lib.mkEnableOption "Set up the CLI";
};
config = lib.mkIf cfg.enable {
home.packages = with pkgs; [
starship
tree
];
programs.fish = {
enable = true;
functions.fish_greeting = "";
shellInitLast = lib.mkIf (lib.strings.hasSuffix "darwin" pkgs.system) ''
eval $(/opt/homebrew/bin/brew shellenv)
'';
};
programs.fzf = {
enable = true;
enableFishIntegration = true;
};
programs.zsh = lib.mkIf (lib.strings.hasSuffix "darwin" pkgs.system) {
enable = true;
# zsh is a POSIX compliant shell and a safe default, but if it's an interactive
# shell and fish is not in the parent processes (i.e. I'm not deliberately starting
# zsh to use interactively from fish) then just launch fish.
initContent = ''
[[ $- == *i* ]] || return
is_parent_fish() {
local ppid=$$
while [[ $ppid -ne 1 ]]; do
local ppname=$(ps -p $ppid -o comm=)
if [[ "$ppname" == *fish* ]]; then
return 1
fi
ppid=$(ps -o ppid= -p $ppid)
done
return 0
}
if is_parent_fish
then
exec fish -l
fi
'';
};
programs.starship = {
enable = true;
enableFishIntegration = true;
enableInteractive = true;
enableTransience = true;
settings = builtins.fromTOML (builtins.readFile ./starship.toml);
};
};
}

View file

@ -0,0 +1,9 @@
[shell]
disabled = false
format = '[$indicator]($style)'
fish_indicator = ''
zsh_indicator = 'z'
[sudo]
disabled = false

View file

@ -0,0 +1,8 @@
{
cli = import ./cli/cli.nix;
firefox = import ./firefox/firefox.nix;
git = import ./git/git.nix;
ops = import ./ops/ops.nix;
tmux = import ./tmux/tmux.nix;
vim = import ./vim/vim.nix;
}

View file

@ -0,0 +1,47 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.feature.firefox;
in
{
options.feature.firefox = {
enable = lib.mkEnableOption "Set up firefox";
};
config = lib.mkIf cfg.enable {
programs.firefox = {
enable = true;
# Firefox is expected to be installed as a system package
package = null;
profiles.irl = {
extensions = {
force = true;
packages = with pkgs.nur.repos.rycee.firefox-addons; [
bitwarden
kagi-search
privacy-badger
recap
];
};
settings = {
"browser.newtabpage.activity-stream.discoverystream.sendToPocket.enabled" = false;
"browser.newtabpage.activity-stream.feeds.section.topstories" = false;
"browser.newtabpage.activity-stream.showSponsored" = false;
"browser.newtabpage.activity-stream.showSponsoredCheckboxes" = false;
"browser.newtabpage.activity-stream.showSponsoredTopSites" = false;
"browser.search.suggest.enabled.private" = false;
"datareporting.policy.firstRunURL" = "https://irl.xyz/";
"extensions.autoDisableScope" = 0;
"extensions.pocket.enabled" = false;
"identity.fxaccounts.enabled" = false;
};
};
};
};
}

View file

@ -0,0 +1,41 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.feature.git;
in
{
options.feature.git.enable = lib.mkEnableOption "Set up git";
config = {
programs.git = {
delta.enable = true;
enable = true;
extraConfig = {
diff = {
algorithm = "histogram";
};
init = {
defaultBranch = "main";
};
rebase = {
autosquash = true;
autostash = true;
};
url = {
"git@github.com:".pushInsteadOf = "https://github.com/";
"git@gitlab.com:".pushInsteadOf = "https://gitlab.com/";
"git@guardianproject.dev:".pushInsteadOf = "https://guardianproject.dev/";
};
user = {
name = "irl";
email = "iain@learmonth.me";
};
};
};
};
}

View file

@ -0,0 +1,22 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.feature.ops;
in
{
options.feature.ops = {
enable = lib.mkEnableOption "Setup DevOps tools";
};
config = lib.mkIf cfg.enable {
home.packages = with pkgs; [
age
awscli2
opentofu
];
};
}

View file

View file

@ -0,0 +1,25 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.feature.tmux;
in
{
options.feature.tmux = {
enable = lib.mkEnableOption "Set up tmux";
};
config = lib.mkIf cfg.enable {
programs.tmux = {
enable = true;
baseIndex = 1;
plugins = with pkgs.tmuxPlugins; [
catppuccin
];
extraConfig = builtins.readFile ./tmux.conf;
};
};
}

View file

@ -0,0 +1,29 @@
-- Global settings
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.g.mapleader = " "
vim.opt.termguicolors = true
vim.opt.expandtab = true
vim.cmd.colorscheme "catppuccin"
-- Custom bindings
vim.keymap.set("n", "<leader>n", "<cmd>bn<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<leader>p", "<cmd>bp<CR>", { noremap = true, silent = true })
-- Bufferline (tabs)
require("bufferline").setup{}
-- Lualine (status line)
require("lualine").setup{}
-- Telescope (anything search)
vim.keymap.set("n", "<leader>b", "<cmd>Telescope buffers<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<leader>f", "<cmd>Telescope find_files<CR>", { noremap = true, silent = true })
-- lspconfig (LSPs)
vim.lsp.enable("nil")
vim.lsp.enable("pyright")
vim.lsp.enable("rust-analyzer")

View file

@ -0,0 +1,39 @@
{
config,
pkgs,
lib,
...
}:
let
cfg = config.feature.vim;
in
{
options.feature.vim = {
enable = lib.mkEnableOption "Set up neovim";
};
config = lib.mkIf cfg.enable {
home.packages = with pkgs; [
nil
pyright
rust-analyzer
];
programs.neovim = {
defaultEditor = true;
enable = true;
viAlias = true;
vimAlias = true;
vimdiffAlias = true;
plugins = with pkgs.vimPlugins; [
bufferline-nvim
catppuccin-nvim
lualine-nvim
nvim-lspconfig
telescope-nvim
nvim-web-devicons
];
extraLuaConfig = builtins.readFile ./init.lua;
};
};
}