dotfiles.nix/flake.nix

350 lines
12 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";
# Flake helpers
flake-utils.url = "github:numtide/flake-utils";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
# 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";
home-manager.inputs.utils.follows = "flake-utils";
# Config "flag" for disabling homebrew
homebrew-enabled.url = "github:boolean-option/true";
# Module to workaround https://github.com/nix-community/home-manager/issues/1341
home-manager-atemu.url = "github:Atemu/home-manager/darwin-copy-apps-fully-wip";
home-manager-atemu.inputs.nixpkgs.follows = "nixpkgs-unstable";
# pre-commit and hooks
pre-commit.url = "github:cachix/pre-commit-hooks.nix";
pre-commit.inputs.flake-utils.follows = "flake-utils";
# 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;
ia-writer-family-src.url = "github:iaolo/iA-Fonts";
ia-writer-family-src.flake = false;
kitty-icon.url = "github:DinkDonk/kitty-icon";
kitty-icon.flake = false;
kitty-themes.url = "github:kovidgoyal/kitty-themes";
kitty-themes.flake = false;
fisher-src.url = "github:jorgebucaran/fisher";
fisher-src.flake = false;
};
outputs = { self, darwin, home-manager, flake-utils, pre-commit, ... }@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, ... }:
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;
homebrew.casks = [
# games
"gog-galaxy"
"origin"
"sony-ps-remote-play"
"steam"
];
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, lib, ... }: {
users.primaryUser = workUserInfo;
networking.knownNetworkServices = [
"Wi-Fi"
];
nix.settings.cores = 2;
nix.settings.max-jobs = 5;
homebrew.casks = [ "itsycal" ];
home-manager.sharedModules = [{
# TODO: how to remove this entirely?
home.file.".tarsnaprc" = lib.mkForce { text = ""; };
home.packages = builtins.attrValues { inherit (pkgs) yubiswitch; };
programs.ssh.matchBlocks.devbox = {
hostname = "csdev4";
forwardAgent = true;
serverAliveInterval = 120;
};
programs.fish.functions.devbox.body = ''
ssh -t devbox "agenttmux attach; or agenttmux new -s yelp"
'';
launchd.agents.tarsnap.enable = lib.mkForce false;
}];
})
];
};
};
# Build and activate on new system with:
# `nix build .#homeConfigurations.<name>.activationPackage; ./result/activate`
homeConfigurations = {
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 kitty-themes fisher-src;
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
primary-user = import ./modules/darwin/primary-user.nix;
};
# home manager configurations
homeManagerModules = {
# configs
configs-starship-symbols = import ./home/configs/starship-symbols.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;
helix = import ./home/helix.nix;
kitty = import ./home/kitty.nix;
programs = import ./home/programs.nix;
starship = import ./home/starship.nix;
install-apps = {
# fix app copying
imports = [ (import "${inputs.home-manager-atemu}/modules/targets/darwin.nix") ];
disabledModules = [ "targets/darwin/linkapps.nix" ];
darwin.installApps = true;
darwin.fullCopies = true;
};
# modules
programs-kakoune-extras = import ./modules/home/programs/kakoune/extras.nix; # currently unused
programs-helix-extras = import ./modules/home/programs/helix/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;
};
};
templates = {
rust = {
description = "A rust flake template based on flake.parts";
welcomeText = ''
welcome to a new rust project ()
run `direnv allow` and `cargo init` to start a new project
'';
path = ./templates/rust;
};
};
} // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import inputs.nixpkgs-unstable {
inherit system;
inherit (nixpkgsConfig) config;
overlays = with self.overlays; [
pkgs-master
pkgs-stable
colors
apple-silicon
patched
];
};
in
{
legacyPackages = pkgs;
checks.pre-commit = pre-commit.lib.${system}.run {
src = ./.;
hooks = {
deadnix.enable = true;
nix-linter.enable = true;
nixpkgs-fmt.enable = true;
statix.enable = true;
};
};
devShells.default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit) shellHook;
};
});
}