More reorganizing

work
mat ess 2022-12-21 00:22:57 -05:00
parent 813efc75be
commit 8bf3fdae1c
8 changed files with 307 additions and 261 deletions

View File

@ -23,22 +23,24 @@
trusted-users = [
"@admin"
];
# TODO: remove and replace with a launchd job
# see https://github.com/NixOS/nix/issues/7273
auto-optimise-store = true;
experimental-features = [ "nix-command" "flakes" ];
extra-platforms = lib.mkIf (pkgs.system == "aarch64-darwin") [ "x86_64-darwin" "aarch64-darwin" ];
};
nix.configureBuildUsers = true;
# Auto upgrade nix package and the daemon service.
services.nix-daemon.enable = true;
# Make Fish the default shell
environment.shells = with pkgs; [
bashInteractive
fish
zsh
];
environment.shells = lib.mkForce (builtins.attrValues {
inherit (pkgs)
bashInteractive
fish
zsh;
});
programs.fish.enable = true;
programs.fish.useBabelfish = true;

View File

@ -1,4 +1,9 @@
{ config, pkgs, ... }: {
{ config, pkgs, lib, ... }:
let
inherit (config.users) primaryUser;
caskPresent = cask: lib.any (x: x.name == cask) config.homebrew.casks;
in
{
environment.shellInit = ''
eval "$(${config.homebrew.brewPrefix}/brew shellenv)"
'';
@ -73,6 +78,20 @@
# "zoom"
];
home-manager.users.${primaryUser.username} =
let
socket = "${primaryUser.homeDirectory}/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh";
in
lib.mkIf (caskPresent "secretive" && config ? home-manager) {
home.sessionVariables.SSH_AUTH_SOCKET = socket;
programs.ssh = {
enable = true;
matchBlocks."*".extraOptions = {
IdentityAgent = socket;
};
};
};
# For cli packages that aren't currently available for macOS in `nixpkgs`.Packages should be
# installed in `../home/programs.nix` whenever possible.
homebrew.brews = [

View File

@ -39,11 +39,11 @@
]
},
"locked": {
"lastModified": 1668784520,
"narHash": "sha256-gGgVAMwYPPmrfnvnoRi6OkEB5KRsNTb9uYzEceLdO/g=",
"lastModified": 1671196037,
"narHash": "sha256-2+J98SeczFWonbqFLMEAQC7vZEe6I2gM17XYvEmG52I=",
"owner": "lnl7",
"repo": "nix-darwin",
"rev": "6349b99bc2b96ded34d068a88c7c5ced406b7f7f",
"rev": "adb8ac0453c8b2c40f5bffb578453dbaee838952",
"type": "github"
},
"original": {
@ -244,11 +244,11 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1671493763,
"narHash": "sha256-xw8cemaLh9Nda9usE0z3sxeiDUuXZ1zDiO6md3i7XLg=",
"lastModified": 1671579194,
"narHash": "sha256-Cpm5tjSfBWOyAUvKcTRk6++U6n2ADkvro7jvfFJe3ps=",
"owner": "helix-editor",
"repo": "helix",
"rev": "bdeefbfb23077fcbbfe1e7df6c6ac88516244bbc",
"rev": "6ab8591715daf932d0dc45d0d5fb9e5a272f2fe1",
"type": "github"
},
"original": {
@ -267,11 +267,11 @@
]
},
"locked": {
"lastModified": 1670513770,
"narHash": "sha256-muL74fsbGA8K8WlZSPNWddOiuBnC54kAajncX6nXrh4=",
"lastModified": 1671578428,
"narHash": "sha256-YmbpBcPaGz9KE2bC4xPvSdgCSMk0BmS/L3ePvy9TR/M=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "054d9e3187ca00479e8036dc0e92900a384f30fd",
"rev": "0f8bf4f92efa3c6168705b49a6788abb3612033a",
"type": "github"
},
"original": {
@ -372,11 +372,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1671268780,
"narHash": "sha256-9Okbivo10bcXEGCtmAQNfJt1Zpk6B3tjkSQ2CIXmTCg=",
"lastModified": 1671458120,
"narHash": "sha256-2+k/OONN4OF21TeoNjKB5sXVZv6Zvm/uEyQIW9OYCg8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "80c24eeb9ff46aa99617844d0c4168659e35175f",
"rev": "e37ef84b478fa8da0ced96522adfd956fde9047a",
"type": "github"
},
"original": {
@ -406,11 +406,11 @@
},
"nixpkgs-master": {
"locked": {
"lastModified": 1670797596,
"narHash": "sha256-lc4b690J8iiYnNToc5j39N6gt3k9lQUDxe0D6Wzuj9k=",
"lastModified": 1671578743,
"narHash": "sha256-kNtZiBrKuaepKEtix+6mM6JJxF6iU+MAdqc/fmZS1aU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "fb83ee7d26bee200b2bd6b69df390c57dee4b6af",
"rev": "5b727aeb18b7896e852866be0abb9a9f5b10c9a3",
"type": "github"
},
"original": {
@ -422,48 +422,16 @@
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1659446231,
"narHash": "sha256-hekabNdTdgR/iLsgce5TGWmfIDZ86qjPhxDg/8TlzhE=",
"lastModified": 1671391912,
"narHash": "sha256-W8sbJuN/i+OZdRuIzDiIyKOqVB/G26zh9DQL1rfp2xk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "eabc38219184cc3e04a974fe31857d8e0eac098d",
"rev": "09e8ac77744dd036e58ab2284e6f5c03a6d6ed41",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-21.11-darwin",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-stable_2": {
"locked": {
"lastModified": 1668984258,
"narHash": "sha256-0gDMJ2T3qf58xgcSbYoXiRGUkPWmKyr5C3vcathWhKs=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "cf63ade6f74bbc9d2a017290f1b2e33e8fbfa70a",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-22.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1668994630,
"narHash": "sha256-1lqx6HLyw6fMNX/hXrrETG1vMvZRGm2XVC9O/Jt0T6c=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "af50806f7c6ab40df3e6b239099e8f8385f6c78b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"ref": "nixpkgs-22.11-darwin",
"repo": "nixpkgs",
"type": "github"
}
@ -475,15 +443,19 @@
"flake-utils"
],
"gitignore": "gitignore",
"nixpkgs": "nixpkgs_2",
"nixpkgs-stable": "nixpkgs-stable_2"
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": [
"nixpkgs-stable"
]
},
"locked": {
"lastModified": 1670413394,
"narHash": "sha256-M7sWqrKtOqUv9euX1t3HCxis8cPy9MNiZxQmUf0KF1o=",
"lastModified": 1671452357,
"narHash": "sha256-HqzXiQEegpRQ4VEl9pEPgHSIxhJrNJ27HfN1wOc7w2E=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "1303a1a76e9eb074075bfe566518c413f6fc104e",
"rev": "200790e9c77064c53eaf95805b013d96615ecc27",
"type": "github"
},
"original": {

227
flake.nix
View File

@ -4,7 +4,7 @@
inputs = {
# Package sets
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin";
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixpkgs-22.11-darwin";
nixpkgs-master.url = "github:NixOS/nixpkgs/master";
# Flake helpers
@ -22,6 +22,8 @@
# pre-commit and hooks
pre-commit.url = "github:cachix/pre-commit-hooks.nix";
pre-commit.inputs.nixpkgs.follows = "nixpkgs";
pre-commit.inputs.nixpkgs-stable.follows = "nixpkgs-stable";
pre-commit.inputs.flake-utils.follows = "flake-utils";
# Extra sources
@ -41,7 +43,6 @@
outputs =
{ self
, home-manager
, flake-utils
, pre-commit
, ...
@ -61,12 +62,10 @@
# Configuration for `nixpkgs`
nixpkgsConfig = {
config = { allowUnfree = true; };
overlays = attrValues self.overlays ++ [
(import ./pkgs { inherit inputs; })
];
overlays = attrValues self.overlays;
};
homeManagerStateVersion = "22.05";
homeStateVersion = "22.05";
primaryUserInfo = {
username = "mat";
@ -80,115 +79,96 @@
email = "mess@yelp.com";
};
# 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}";
darwin = "${inputs.darwin}";
};
# `home-manager` config
users.users.${primaryUser.username}.home = primaryUser.homeDirectory;
home-manager.useGlobalPkgs = true;
home-manager.users.${primaryUser.username} = {
imports = attrValues self.homeManagerModules;
home.stateVersion = homeManagerStateVersion;
home.primaryUser = primaryUser;
home.homeDirectory = primaryUser.homeDirectory;
home.enableNixpkgsReleaseCheck = true;
};
# Add a registry entry for this flake
nix.registry.my.flake = self;
}
)
];
# helper for defining nix-darwin systems
mkDarwinSystem =
{ modules ? [ ]
, homeModules ? [ ]
, ...
}@args: import ./lib/mkDarwinSystem.nix self inputs nixpkgsConfig (args // {
inherit homeStateVersion;
modules = attrValues self.darwinModules ++ modules;
homeModules = attrValues self.homeManagerModules ++ homeModules;
});
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; } ];
darwinConfigurations =
let
bootstrap-x86 = makeOverridable darwinSystem {
system = "x86_64-darwin";
modules = [ ./darwin/bootstrap.nix { nixpkgs = nixpkgsConfig; } ];
};
in
{
# Mininal configurations to bootstrap systems
inherit bootstrap-x86;
bootstrap-arm = bootstrap-x86.override { system = "aarch64-darwin"; };
# M1 MBP
matbook = mkDarwinSystem {
primaryUser = primaryUserInfo;
modules = [
({ pkgs, ... }: {
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 = mkDarwinSystem {
primaryUser = workUserInfo;
modules = [
({ 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 = [ 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;
}];
})
];
};
};
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;
}];
})
];
};
};
# Overlays --------------------------------------------------------------- {{{
@ -229,6 +209,8 @@
homebrew-enabled = _: prev: optionalAttrs prev.stdenv.isDarwin {
lib = prev.lib // { homebrew-enabled = inputs.homebrew-enabled.value; };
};
extra-pkgs = import ./pkgs { inherit inputs; };
};
# `nix-darwin` configs and modules
@ -263,24 +245,9 @@
home-primary-user = mkPrimaryUserModule "home";
};
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 (nixpkgsConfig // { inherit system; });
in
{
legacyPackages = pkgs;
templates = import ./templates;
} // flake-utils.lib.eachDefaultSystem (system: {
legacyPackages = import inputs.nixpkgs (nixpkgsConfig // { inherit system; });
checks.pre-commit = pre-commit.lib.${system}.run {
src = ./.;
@ -292,7 +259,7 @@
};
};
devShells = {
devShells = let pkgs = self.legacyPackages.${system}; in {
default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit) shellHook;
};

View File

@ -138,7 +138,6 @@
programs.fish.shellAliases =
let
inherit (config.home.primaryUser) nixConfigDirectory;
inherit (pkgs) bat bottom du-dust exa gitAndTools stdenv xh;
in
{
# Nix related
@ -170,18 +169,18 @@
# Other
".." = "cd ..";
":q" = "exit";
cat = "${bat}/bin/bat --style=plain --paging=never";
du = "${du-dust}/bin/dust";
g = "${gitAndTools.git}/bin/git";
ls = "${exa}/bin/exa";
cat = "${pkgs.bat}/bin/bat --style=plain --paging=never";
du = "${pkgs.du-dust}/bin/dust";
g = "${pkgs.gitAndTools.git}/bin/git";
ls = "${pkgs.exa}/bin/exa";
ll = "ls -l --time-style long-iso --icons";
la = "ll -a";
http = "${xh}/bin/xh";
https = "${xh}/bin/xhs";
top = "${bottom}/bin/btm";
htop = "${bottom}/bin/btm";
http = "${pkgs.xh}/bin/xh";
https = "${pkgs.xh}/bin/xhs";
top = "${pkgs.bottom}/bin/btm";
htop = "${pkgs.bottom}/bin/btm";
tb = "toggle-background";
} // lib.optionalAttrs stdenv.isDarwin {
} // lib.optionalAttrs pkgs.stdenv.isDarwin {
sb = "set-background-to-macOS";
conda-init = "eval /opt/homebrew/bin/conda 'shell.fish' 'hook' $argv | source";
};
@ -193,7 +192,7 @@
'';
programs.fish.interactiveShellInit = ''
set -g fish_greeting (set_color blue)"( ³) "(set_color red)"h"(set_color cyan)"e"(set_color yellow)"l"(set_color magenta)"l"(set_color green)"o "(set_color blue)"( ³)"(set_color normal)
set -g fish_greeting (set_color blue)"( ³) "(set_color cyan)"h"(set_color red)"e"(set_color yellow)"l"(set_color green)"l"(set_color magenta)"o "(set_color blue)"( ³)"(set_color normal)
fish_vi_key_bindings
set VIRTUAL_ENV_DISABLE_PROMPT true
bind -M insert ! __history_previous_command

View File

@ -1,13 +1,5 @@
{ config, pkgs, lib, ... }:
let
secretiveAuthSocket = "${config.home.homeDirectory}/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh";
in
{
{ pkgs, lib, ... }: {
# Programs + packages with configuration --------------------------------------------------------------- {{{
home.sessionVariables = lib.optionalAttrs pkgs.stdenv.isDarwin {
SSH_AUTH_SOCK = secretiveAuthSocket;
};
programs = {
# a nicer cat
# https://rycee.gitlab.io/home-manager/options.html#opt-programs.bat.enable
@ -33,7 +25,6 @@ in
matchBlocks."*".extraOptions = lib.optionalAttrs pkgs.stdenv.isDarwin {
UseKeychain = "yes";
AddKeysToAgent = "yes";
IdentityAgent = secretiveAuthSocket;
};
};
# vscode
@ -50,55 +41,84 @@ in
# Other packages ----------------------------------------------------------------------------- {{{
home.packages = with pkgs; [
# GUI apps
discord-ptb
element-desktop
lagrange
obsidian
slack
zoom-us
home.packages = builtins.attrValues ({
coreutils = pkgs.coreutils.override { withPrefix = true; singleBinary = "shebangs"; };
inherit (pkgs)
# GUI apps
discord-ptb
element-desktop
lagrange
obsidian
slack
zoom-us
# System
abduco # lightweight session management
atool # archive tool
bottom # fancy version of `top` with ASCII graphs
# do i need these?
# coreutils
curl
du-dust # fancy version of `du`
exa # fancy version of `ls`
fd # fancy version of `find`
mosh # wrapper for `ssh` that better at not dropping connections
procs # fancy version of `ps`
pv # pipe progress viewer
rage # command line file encryption
thefuck
unrar # extract RAR archives
wget
xz # extract XZ archives
# System
# lightweight session management
abduco
# archive tool
atool
# fancy version of `top` with ASCII graphs
bottom
curl
# fancy version of `du`
du-dust
# fancy version of `ls`
exa
# fancy version of `find`
fd
# wrapper for `ssh` that better at not dropping connections
mosh
# fancy version of `ps`
procs
# pipe progress viewer
pv
# command line file encryption
rage
thefuck
# extract RAR archives
unrar
wget
# extract XZ archives
xz
# Dev stuff
cloc # source code line counter
doctl # command line tools for digitalocean
flyctl # command line tools for fly.io
hyperfine # benchmarking tool
jq # json processor
pijul # alternative to `git`
ripgrep # better version of `grep`
tealdeer # rust implementation of `tldr`
xh # reimplementation of `httpie` in rust
# Dev stuff
# source code line counter
cloc
# command line tools for digitalocean
doctl
# command line tools for fly.io
flyctl
# benchmarking tool
hyperfine
# json processor
jq
# alternative to `git`
pijul
# better version of `grep`
ripgrep
# rust implementation of `tldr`
tealdeer
# reimplementation of `httpie` in rust
xh
# Useful nix related tools
cachix # adding/managing alternative binary caches hosted by Cachix
comma # run software from nixpkgs without installing it
nixpkgs-fmt
nix-prefetch-git
nix-tree
nil # nix language server
] ++ lib.optionals stdenv.isDarwin [
m-cli # useful macOS CLI commands
is-dark-mode # see /overlays/colors.nix
];
# Useful nix related tools
# adding/managing alternative binary caches hosted by Cachix
cachix
# run software from nixpkgs without installing it
comma
nixpkgs-fmt
nix-prefetch-git
nix-tree
# nix language server
nil
;
} // lib.optionalAttrs pkgs.stdenv.isDarwin {
inherit (pkgs)
# useful macOS CLI commands
m-cli
# see /overlays/colors.nix
is-dark-mode
;
});
# }}}
}

56
lib/mkDarwinSystem.nix Normal file
View File

@ -0,0 +1,56 @@
# taken from https://github.com/malob/nixpkgs/blob/27e04346555277687a60c0168969b3945c2b25ba/lib/mkDarwinSystem.nix
self: inputs: nixpkgs:
{ primaryUser
, system ? "aarch64-darwin"
# `nix-darwin` modules to include
, modules ? [ ]
# Additional `nix-darwin` modules to include, useful when reusing a configuration with
# `lib.makeOverridable`.
, extraModules ? [ ]
# Value for `home-manager`'s `home.stateVersion` option.
, homeStateVersion
# `home-manager` modules to include
, homeModules ? [ ]
# Additional `home-manager` modules to include, useful when reusing a configuration with
# `lib.makeOverridable`.
, extraHomeModules ? [ ]
}:
inputs.darwin.lib.darwinSystem {
inherit system;
modules = modules ++ extraModules ++ [
inputs.home-manager.darwinModules.home-manager
({ config, ... }:
let cfg = config.users.primaryUser; in
{
users.primaryUser = primaryUser;
inherit nixpkgs;
# Support legacy workflows that use `<nixpkgs>` etc.
nix.nixPath = {
nixpkgs = "${inputs.nixpkgs}";
darwin = "${inputs.darwin}";
};
# `home-manager` config
users.users.${cfg.username}.home = cfg.homeDirectory;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.${cfg.username} = {
imports = homeModules ++ extraHomeModules;
home.stateVersion = homeStateVersion;
home.primaryUser = primaryUser;
home.homeDirectory = cfg.homeDirectory;
home.enableNixpkgsReleaseCheck = true;
};
# Make sure nixpkgs#pkg refers to this nixpkgs
nix.registry.nixpkgs.flake = inputs.nixpkgs;
# Add this flake to the registry
nix.registry.my.flake = self;
})
];
}

11
templates/default.nix Normal file
View File

@ -0,0 +1,11 @@
{
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;
};
}