dotfiles.nix/flake.nix

311 lines
10 KiB
Nix

{
description = "mat's nix configs";
inputs = {
# Package sets
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixpkgs-master.url = "github:NixOS/nixpkgs/master";
# Environment/system management
darwin.url = "github:lnl7/nix-darwin/master";
darwin.inputs.nixpkgs.follows = "nixpkgs-unstable";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs-unstable";
# Config "flag" for disabling homebrew
homebrew-enabled.url = "github:boolean-option/true";
# Flake helpers
flake-utils.url = "github:numtide/flake-utils";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
# Extra sources
helix.url = "github:helix-editor/helix";
helix.inputs.nixpkgs.follows = "nixpkgs-unstable";
dark-mode-notify-src.url = "github:bouk/dark-mode-notify";
dark-mode-notify-src.flake = false;
kitty-icon.url = "github:DinkDonk/kitty-icon";
kitty-icon.flake = false;
};
outputs = { self, darwin, home-manager, flake-utils, ... }@inputs:
let
inherit (darwin.lib) darwinSystem;
inherit (inputs.nixpkgs-unstable.lib)
attrValues
makeOverridable
optionalAttrs;
# Configuration for `nixpkgs`
nixpkgsConfig = {
config = { allowUnfree = true; };
overlays = attrValues self.overlays ++ [
(final: prev:
import ./pkgs {
inherit inputs;
inherit (final) callPackage;
inherit (final.stdenv) system;
})
(final: prev: optionalAttrs (prev.stdenv.system == "aarch64-darwin")
{
# Sub in x86 version of packages that don't build on Apple Silicon yet
inherit (final.pkgs-x86);
})
];
};
homeManagerStateVersion = "22.05";
primaryUserInfo = {
username = "mat";
fullName = "mat ess";
email = "mat@mat.services";
nixConfigDirectory = "/Users/mat/dotfiles.nix";
};
workUserInfo = {
username = "mess";
fullName = "Matthew Ess";
email = "mess@yelp.com";
nixConfigDirectory = "/Users/mess/dotfiles.nix";
};
# Modules shared by most `nix-darwin` personal configurations.
nixDarwinCommonModules = attrValues self.darwinModules ++ [
# `home-manager` module
home-manager.darwinModules.home-manager
(
{ config, lib, pkgs, ... }:
let
inherit (config.users) primaryUser;
in
{
nixpkgs = nixpkgsConfig;
# Hack to support legacy worklows that use `<nixpkgs>`, darwin-option, etc.
nix.nixPath = {
nixpkgs = "${inputs.nixpkgs-unstable}";
darwin = "${inputs.darwin}";
};
# `home-manager` config
users.users.${primaryUser.username}.home = "/Users/${primaryUser.username}";
home-manager.useGlobalPkgs = true;
home-manager.users.${primaryUser.username} = {
imports = attrValues self.homeManagerModules;
home.stateVersion = homeManagerStateVersion;
home.primaryUser = primaryUser;
home.enableNixpkgsReleaseCheck = true;
};
# Add a registry entry for this flake
nix.registry.my.flake = self;
}
)
];
in
{
# `nix-darwin` configs
darwinConfigurations = rec {
# Mininal configurations to bootstrap systems
bootstrap-x86 = makeOverridable darwinSystem {
system = "x86_64-darwin";
modules = [ ./darwin/bootstrap.nix { nixpkgs = nixpkgsConfig; } ];
};
bootstrap-arm = bootstrap-x86.override { system = "aarch64-darwin"; };
# M1 MBP
matbook = darwinSystem {
system = "aarch64-darwin";
modules = nixDarwinCommonModules ++ [
({ pkgs, ... }: {
users.primaryUser = primaryUserInfo;
networking.computerName = "matbook pro m1";
networking.hostName = "matbook";
networking.knownNetworkServices = [
"Wi-Fi"
];
nix.settings.cores = 2;
nix.settings.max-jobs = 4;
environment.systemPackages = with pkgs; [
vscodium
];
games.enable = true;
home-manager.sharedModules = [{
programs.fish.shellAliases = {
code = "${pkgs.vscodium}/bin/codium";
};
programs.ssh.matchBlocks.remarkable = {
hostname = "10.11.99.1";
user = "root";
port = 22;
};
programs.vscode.package = pkgs.vscodium;
}];
})
];
};
yelpbook-m1 = darwinSystem {
system = "aarch64-darwin";
modules = nixDarwinCommonModules ++ [
({ pkgs, ... }: {
users.primaryUser = workUserInfo;
networking.knownNetworkServices = [
"Wi-Fi"
];
nix.settings.cores = 2;
nix.settings.max-jobs = 5;
games.enable = false;
environment.systemPackages = with pkgs; [
yubiswitch
vscode
];
homebrew.casks = [ "itsycal" ];
home-manager.sharedModules = [{
programs.ssh.matchBlocks.devbox = {
hostname = "amp1";
forwardAgent = true;
serverAliveInterval = 120;
};
programs.fish.functions.devbox.body = ''
ssh -t devbox "agenttmux attach; or agenttmux new -s yelp"
'';
}];
})
];
};
# Config with small modifications needed/desired for CI with GitHub workflow
githubCI = darwinSystem {
system = "x86_64-darwin";
modules = nixDarwinCommonModules ++ [
({ lib, ... }: {
users.primaryUser = primaryUserInfo // {
username = "runner";
nixConfigDirectory = "/Users/runner/work/nixpkgs/nixpkgs";
};
homebrew.enable = lib.mkForce false;
})
];
};
};
# Build and activate on new system with:
# `nix build .#homeConfigurations.<name>.activationPackage; ./result/activate`
homeConfigurations = rec {
cloudVM = home-manager.lib.homeManagerConfiguration {
pkgs = import inputs.nixpkgs-unstable {
system = "x86_64-linux";
inherit (nixpkgsConfig) config overlays;
};
modules = attrValues self.homeManagerModules ++ [
({ config, ... }: {
home.username = config.home.primaryUser.username;
home.homeDirectory = "/home/${config.home.username}";
home.stateVersion = homeManagerStateVersion;
home.primaryUser = primaryUserInfo // {
nixConfigDirectory = "${config.home.homeDirectory}/dotfiles.nix";
};
})
];
};
};
# Overlays --------------------------------------------------------------- {{{
overlays = {
# nixpkgs overlays
pkgs-stable = final: prev: {
pkgs-stable = import inputs.nixpkgs {
inherit (prev.stdenv) system;
inherit (nixpkgsConfig) config;
};
};
pkgs-unstable = final: prev: {
pkgs-unstable = import inputs.nixpkgs-unstable {
inherit (prev.stdenv) system;
inherit (nixpkgsConfig) config;
};
};
pkgs-master = final: prev: {
pkgs-master = import inputs.nixpkgs-master {
inherit (prev.stdenv) system;
inherit (nixpkgsConfig) config;
};
};
colors = import ./overlays/colors.nix;
# Overlay useful on Macs with Apple Silicon
apple-silicon = final: prev: optionalAttrs (prev.stdenv.system == "aarch64-darwin") {
# Add access to x86 packages system is running Apple Silicon
pkgs-x86 = import inputs.nixpkgs-unstable {
system = "x86_64-darwin";
inherit (nixpkgsConfig) config;
};
};
patched = final: prev: optionalAttrs prev.stdenv.isDarwin {
inherit (inputs) kitty-icon;
lib = prev.lib // { homebrew-enabled = inputs.homebrew-enabled.value; };
};
};
# `nix-darwin` configs and modules
darwinModules = {
# configs
bootstrap = import ./darwin/bootstrap.nix;
defaults = import ./darwin/defaults.nix;
general = import ./darwin/general.nix;
homebrew = import ./darwin/homebrew.nix;
# modules
games = import ./modules/darwin/games.nix;
primary-user = import ./modules/darwin/primary-user.nix;
};
# home manager configurations
homeManagerModules = {
# configs
configs-starship-symbols = import ./home/configs/starship-symbols.nix;
copyApplications = import ./home/copyApplications.nix;
# services
dark-mode-notify-service = import ./home/services/dark-mode-notify.nix;
tarsnap-service = import ./home/services/tarsnap.nix;
# etc
files = import ./home/files.nix;
fish = import ./home/fish.nix;
git = import ./home/git.nix;
kitty = import ./home/kitty.nix;
programs = import ./home/programs.nix;
starship = import ./home/starship.nix;
# modules
# TODO: migrate to helix
# programs-kakoune-extras = import ./modules/home/programs/kakoune/extras.nix;
programs-kitty-extras = import ./modules/home/programs/kitty/extras.nix;
home-primary-user = { lib, ... }: {
options.home.primaryUser =
(self.darwinModules.primary-user { inherit lib; }).options.users.primaryUser;
};
};
} // flake-utils.lib.eachDefaultSystem (system: {
legacyPackages = import inputs.nixpkgs-unstable {
inherit system;
inherit (nixpkgsConfig) config;
overlays = with self.overlays; [
pkgs-master
pkgs-stable
colors
apple-silicon
patched
];
};
});
}