Compare commits
No commits in common. "d087e37f7cb133d618bf16df2d9e16c52ac8e307" and "3d6c3ab6524258f0f240e59026c5eb519b784293" have entirely different histories.
d087e37f7c
...
3d6c3ab652
24 changed files with 710 additions and 29 deletions
|
@ -1,4 +1,4 @@
|
||||||
# nixos config
|
# nix{os,-darwin} config
|
||||||
|
|
||||||
It just works™
|
It just works™
|
||||||
|
|
||||||
|
@ -6,9 +6,12 @@ It just works™
|
||||||
|
|
||||||
```
|
```
|
||||||
.
|
.
|
||||||
|
│ # Darwin configuration is not actively maintained and sometimes it might
|
||||||
|
│ # break.
|
||||||
├── home # <-- See here for dotfiles!
|
├── home # <-- See here for dotfiles!
|
||||||
|
├── darwin
|
||||||
├── nixos
|
├── nixos
|
||||||
│ ├── modules # nixos options
|
│ ├── modules
|
||||||
│ └── profiles
|
│ └── profiles
|
||||||
│
|
│
|
||||||
│ # Internal packages, please see github:Guanran928/nur-packages instead
|
│ # Internal packages, please see github:Guanran928/nur-packages instead
|
||||||
|
|
6
darwin/modules/default.nix
Normal file
6
darwin/modules/default.nix
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{...}: {
|
||||||
|
imports = [
|
||||||
|
./networking/proxy.nix
|
||||||
|
./services/mihomo.nix
|
||||||
|
];
|
||||||
|
}
|
138
darwin/modules/networking/proxy.nix
Normal file
138
darwin/modules/networking/proxy.nix
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
# Copy & pasted https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/config/networking.nix
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
with lib; let
|
||||||
|
cfg = config.networking;
|
||||||
|
opt = options.networking;
|
||||||
|
in {
|
||||||
|
options = {
|
||||||
|
networking.proxy = {
|
||||||
|
default = lib.mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
This option specifies the default value for httpProxy, httpsProxy, ftpProxy and rsyncProxy.
|
||||||
|
'';
|
||||||
|
example = "http://127.0.0.1:3128";
|
||||||
|
};
|
||||||
|
|
||||||
|
httpProxy = lib.mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
inherit (cfg.proxy) default;
|
||||||
|
defaultText = literalExpression "config.${opt.proxy.default}";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
This option specifies the http_proxy environment variable.
|
||||||
|
'';
|
||||||
|
example = "http://127.0.0.1:3128";
|
||||||
|
};
|
||||||
|
|
||||||
|
httpsProxy = lib.mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
inherit (cfg.proxy) default;
|
||||||
|
defaultText = literalExpression "config.${opt.proxy.default}";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
This option specifies the https_proxy environment variable.
|
||||||
|
'';
|
||||||
|
example = "http://127.0.0.1:3128";
|
||||||
|
};
|
||||||
|
|
||||||
|
ftpProxy = lib.mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
inherit (cfg.proxy) default;
|
||||||
|
defaultText = literalExpression "config.${opt.proxy.default}";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
This option specifies the ftp_proxy environment variable.
|
||||||
|
'';
|
||||||
|
example = "http://127.0.0.1:3128";
|
||||||
|
};
|
||||||
|
|
||||||
|
rsyncProxy = lib.mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
inherit (cfg.proxy) default;
|
||||||
|
defaultText = literalExpression "config.${opt.proxy.default}";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
This option specifies the rsync_proxy environment variable.
|
||||||
|
'';
|
||||||
|
example = "http://127.0.0.1:3128";
|
||||||
|
};
|
||||||
|
|
||||||
|
allProxy = lib.mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
inherit (cfg.proxy) default;
|
||||||
|
defaultText = literalExpression "config.${opt.proxy.default}";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
This option specifies the all_proxy environment variable.
|
||||||
|
'';
|
||||||
|
example = "http://127.0.0.1:3128";
|
||||||
|
};
|
||||||
|
|
||||||
|
noProxy = lib.mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
This option specifies the no_proxy environment variable.
|
||||||
|
If a default proxy is used and noProxy is null,
|
||||||
|
then noProxy will be set to 127.0.0.1,localhost.
|
||||||
|
'';
|
||||||
|
example = "127.0.0.1,localhost,.localdomain";
|
||||||
|
};
|
||||||
|
|
||||||
|
envVars = lib.mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
internal = true;
|
||||||
|
default = {};
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
Environment variables used for the network proxy.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
networking.proxy.envVars =
|
||||||
|
optionalAttrs (cfg.proxy.default != null) {
|
||||||
|
# other options already fallback to proxy.default
|
||||||
|
no_proxy = "127.0.0.1,localhost";
|
||||||
|
}
|
||||||
|
// optionalAttrs (cfg.proxy.httpProxy != null) {
|
||||||
|
http_proxy = cfg.proxy.httpProxy;
|
||||||
|
}
|
||||||
|
// optionalAttrs (cfg.proxy.httpsProxy != null) {
|
||||||
|
https_proxy = cfg.proxy.httpsProxy;
|
||||||
|
}
|
||||||
|
// optionalAttrs (cfg.proxy.rsyncProxy != null) {
|
||||||
|
rsync_proxy = cfg.proxy.rsyncProxy;
|
||||||
|
}
|
||||||
|
// optionalAttrs (cfg.proxy.ftpProxy != null) {
|
||||||
|
ftp_proxy = cfg.proxy.ftpProxy;
|
||||||
|
}
|
||||||
|
// optionalAttrs (cfg.proxy.allProxy != null) {
|
||||||
|
all_proxy = cfg.proxy.allProxy;
|
||||||
|
}
|
||||||
|
// optionalAttrs (cfg.proxy.noProxy != null) {
|
||||||
|
no_proxy = cfg.proxy.noProxy;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Install the proxy environment variables
|
||||||
|
environment.variables = cfg.proxy.envVars;
|
||||||
|
launchd.daemons."nix-daemon".environment = cfg.proxy.envVars;
|
||||||
|
|
||||||
|
# Set macOS's system level proxy setting
|
||||||
|
system.activationScripts."extraActivation".text = let
|
||||||
|
inherit (cfg) knownNetworkServices;
|
||||||
|
networksetup = /usr/sbin/networksetup;
|
||||||
|
|
||||||
|
# naive but works(tm)
|
||||||
|
# "http://127.0.0.1:1234/" -> "127.0.0.1 1234"
|
||||||
|
proxy = lib.replaceStrings ["http://" ":" "/"] ["" " " ""] cfg.proxy.httpProxy;
|
||||||
|
in
|
||||||
|
lib.concatMapStrings (x: ''
|
||||||
|
${networksetup} -setwebproxystate "${x}" on
|
||||||
|
${networksetup} -setwebproxy "${x}" ${proxy}
|
||||||
|
'')
|
||||||
|
knownNetworkServices;
|
||||||
|
};
|
||||||
|
}
|
51
darwin/modules/services/mihomo.nix
Normal file
51
darwin/modules/services/mihomo.nix
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
cfg = config.services.mihomo;
|
||||||
|
in {
|
||||||
|
options.services.mihomo = {
|
||||||
|
enable = lib.mkEnableOption "Whether to enable Mihomo, A rule-based proxy in Go.";
|
||||||
|
package = lib.mkPackageOption pkgs "mihomo" {};
|
||||||
|
webui = lib.mkOption {
|
||||||
|
default = null;
|
||||||
|
type = lib.types.nullOr lib.types.path;
|
||||||
|
description = ''
|
||||||
|
Local web interface to use.
|
||||||
|
|
||||||
|
- metacubexd:
|
||||||
|
- http://d.metacubex.one
|
||||||
|
- https://metacubex.github.io/metacubexd
|
||||||
|
- https://metacubexd.pages.dev
|
||||||
|
- yacd:
|
||||||
|
- https://yacd.haishan.me
|
||||||
|
- clash-dashboard:
|
||||||
|
- https://clash.razord.top
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
extraOpts = lib.mkOption {
|
||||||
|
default = null;
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
description = "Extra command line options to use.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
### launchd service
|
||||||
|
# TODO: not run as root user
|
||||||
|
launchd.daemons."mihomo" = {
|
||||||
|
command = lib.concatStringsSep " " [
|
||||||
|
(lib.getExe cfg.package)
|
||||||
|
"-d /etc/mihomo"
|
||||||
|
(lib.optionalString (cfg.webui != null) "-ext-ui ${cfg.webui}")
|
||||||
|
(lib.optionalString (cfg.extraOpts != null) cfg.extraOpts)
|
||||||
|
];
|
||||||
|
serviceConfig = {
|
||||||
|
RunAtLoad = true;
|
||||||
|
KeepAlive.NetworkState = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
7
darwin/profiles/common/core/anti-features.nix
Normal file
7
darwin/profiles/common/core/anti-features.nix
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{lib, ...}: {
|
||||||
|
# Allow unfree applications
|
||||||
|
nixpkgs.config.allowUnfreePredicate = pkg:
|
||||||
|
lib.elem (lib.getName pkg) [
|
||||||
|
"keka"
|
||||||
|
];
|
||||||
|
}
|
65
darwin/profiles/common/core/default.nix
Normal file
65
darwin/profiles/common/core/default.nix
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
{
|
||||||
|
inputs,
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
### Options
|
||||||
|
home-manager.users.guanranwang = import ./home;
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
./nix
|
||||||
|
./anti-features.nix
|
||||||
|
|
||||||
|
inputs.self.darwinModules.default
|
||||||
|
inputs.home-manager.darwinModules.home-manager
|
||||||
|
];
|
||||||
|
|
||||||
|
users = {
|
||||||
|
knownUsers = ["guanranwang"];
|
||||||
|
users."guanranwang" = {
|
||||||
|
createHome = true;
|
||||||
|
description = "Guanran Wang";
|
||||||
|
home = "/Users/guanranwang";
|
||||||
|
shell = pkgs.fish;
|
||||||
|
uid = 501;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
home-manager = {
|
||||||
|
useGlobalPkgs = true;
|
||||||
|
useUserPackages = true;
|
||||||
|
extraSpecialArgs = {inherit inputs;}; # ??? isnt specialArgs imported by default ???
|
||||||
|
};
|
||||||
|
|
||||||
|
# Create /etc/zshrc that loads the nix-darwin environment.
|
||||||
|
programs.zsh.enable = true; # default shell on catalina
|
||||||
|
programs.fish.enable = true;
|
||||||
|
|
||||||
|
# WORKAROUND: Fix $PATH orders when using Fish shell
|
||||||
|
# https://github.com/LnL7/nix-darwin/issues/122#issuecomment-1659465635
|
||||||
|
programs.fish.loginShellInit = let
|
||||||
|
# Double quotes instead of single quotes are necessary
|
||||||
|
# ["$HOME/.local" "/usr/local"] -> "\"$HOME/.local/bin' '/usr/local/bin\""
|
||||||
|
makePath = path: lib.concatMapStringsSep " " (path: "\"${path}/bin\"") path;
|
||||||
|
in ''
|
||||||
|
fish_add_path --move --prepend --path ${makePath config.environment.profiles}
|
||||||
|
set fish_user_paths $fish_user_paths
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Install more recent versions of some macOS tools.
|
||||||
|
# https://github.com/mathiasbynens/dotfiles/blob/master/brew.sh
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
bashInteractive
|
||||||
|
coreutils
|
||||||
|
findutils
|
||||||
|
git
|
||||||
|
gnugrep
|
||||||
|
gnused
|
||||||
|
openssh
|
||||||
|
screen
|
||||||
|
tree
|
||||||
|
vim
|
||||||
|
];
|
||||||
|
}
|
34
darwin/profiles/common/core/home/default.nix
Normal file
34
darwin/profiles/common/core/home/default.nix
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
{...}: {
|
||||||
|
imports = [
|
||||||
|
../../../../../home
|
||||||
|
];
|
||||||
|
|
||||||
|
# https://github.com/mathiasbynens/dotfiles/blob/main/.macos
|
||||||
|
targets.darwin.defaults = {
|
||||||
|
### Inputs
|
||||||
|
".GlobalPreferences"."com.apple.mouse.scaling" = "-1"; # Disable mouse acceleration
|
||||||
|
|
||||||
|
### .DS_Store
|
||||||
|
"com.apple.desktopservices" = {
|
||||||
|
DSDontWriteNetworkStores = true;
|
||||||
|
DSDontWriteUSBStores = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
### Dock
|
||||||
|
"com.apple.dock".autohide = true;
|
||||||
|
|
||||||
|
### Finder
|
||||||
|
"com.apple.finder" = {
|
||||||
|
_FXShowPosixPathInTitle = false;
|
||||||
|
AppleShowAllExtensions = true;
|
||||||
|
AppleShowAllFiles = true;
|
||||||
|
CreateDesktop = false;
|
||||||
|
FXDefaultSearchScope = "SCcf"; # Current folder
|
||||||
|
FXEnableExtensionChangeWarning = false;
|
||||||
|
FXPreferredViewStyle = "Nlsv"; # List view
|
||||||
|
QuitMenuItem = true;
|
||||||
|
ShowPathbar = true;
|
||||||
|
ShowStatusBar = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
7
darwin/profiles/common/core/nix/default.nix
Normal file
7
darwin/profiles/common/core/nix/default.nix
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{...}: {
|
||||||
|
imports = [
|
||||||
|
./flake.nix
|
||||||
|
./nix.nix
|
||||||
|
#./gc.nix # wtf is single user mode
|
||||||
|
];
|
||||||
|
}
|
17
darwin/profiles/common/core/nix/flake.nix
Normal file
17
darwin/profiles/common/core/nix/flake.nix
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
inputs,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
# Enable Flakes
|
||||||
|
nix.settings.experimental-features = ["nix-command" "flakes"];
|
||||||
|
|
||||||
|
# Disable flake-registry
|
||||||
|
# https://nixos-and-flakes.thiscute.world/best-practices/nix-path-and-flake-registry
|
||||||
|
nix.settings.flake-registry = "";
|
||||||
|
nix.registry.nixpkgs.flake = inputs.nixpkgs;
|
||||||
|
nix.registry.nixpkgs-stable.flake = inputs.nixpkgs-stable;
|
||||||
|
|
||||||
|
# Install Git
|
||||||
|
environment.systemPackages = [pkgs.git];
|
||||||
|
}
|
12
darwin/profiles/common/core/nix/gc.nix
Normal file
12
darwin/profiles/common/core/nix/gc.nix
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
nix = {
|
||||||
|
### Auto hard linking
|
||||||
|
settings.auto-optimise-store = true;
|
||||||
|
|
||||||
|
### Automatically delete older NixOS builds
|
||||||
|
gc = {
|
||||||
|
automatic = true;
|
||||||
|
options = "--delete-older-than 7d";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
30
darwin/profiles/common/core/nix/nix.nix
Normal file
30
darwin/profiles/common/core/nix/nix.nix
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
nix.settings = {
|
||||||
|
trusted-users = ["@admin"];
|
||||||
|
substituters =
|
||||||
|
(lib.optionals (config.time.timeZone == "Asia/Shanghai") [
|
||||||
|
"https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" # TUNA - 清华大学 Mirror
|
||||||
|
])
|
||||||
|
++ [
|
||||||
|
"https://nix-community.cachix.org"
|
||||||
|
"https://guanran928.cachix.org"
|
||||||
|
];
|
||||||
|
trusted-public-keys = [
|
||||||
|
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
|
||||||
|
"guanran928.cachix.org-1:BE/iBCj2/pqJXG908wHRrcaV0B2fC+KbFjHsXY6b91c="
|
||||||
|
];
|
||||||
|
use-xdg-base-directories = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Auto upgrade nix package and the daemon service.
|
||||||
|
services.nix-daemon.enable = true;
|
||||||
|
nix.package = pkgs.nix;
|
||||||
|
|
||||||
|
# Set Git commit hash for darwin-version.
|
||||||
|
#system.configurationRevision = self.rev or self.dirtyRev or null;
|
||||||
|
}
|
9
darwin/profiles/common/opt-in/mihomo.nix
Normal file
9
darwin/profiles/common/opt-in/mihomo.nix
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{pkgs, ...}: {
|
||||||
|
services.mihomo = {
|
||||||
|
enable = true;
|
||||||
|
webui = pkgs.metacubexd;
|
||||||
|
};
|
||||||
|
|
||||||
|
### System proxy settings
|
||||||
|
networking.proxy.default = "http://127.0.0.1:7890/";
|
||||||
|
}
|
8
darwin/profiles/desktop/default.nix
Normal file
8
darwin/profiles/desktop/default.nix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{...}: {
|
||||||
|
home-manager.users.guanranwang = import ./home;
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
../common/core
|
||||||
|
./packages
|
||||||
|
];
|
||||||
|
}
|
34
darwin/profiles/desktop/home/default.nix
Normal file
34
darwin/profiles/desktop/home/default.nix
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
imports = map (n: ../../../../home/applications/${n}) [
|
||||||
|
"go"
|
||||||
|
# "mpv"
|
||||||
|
"nix"
|
||||||
|
];
|
||||||
|
|
||||||
|
# Install MacOS applications to the user Applications folder. Also update Docked applications
|
||||||
|
# Modified version of: https://github.com/nix-community/home-manager/issues/1341#issuecomment-1870352014
|
||||||
|
home.file."Applications/Home Manager Apps".enable = false;
|
||||||
|
home.activation.trampolineApps = let
|
||||||
|
apps = pkgs.buildEnv {
|
||||||
|
name = "home-manager-applications";
|
||||||
|
paths = config.home.packages;
|
||||||
|
pathsToLink = "/Applications";
|
||||||
|
};
|
||||||
|
in
|
||||||
|
lib.hm.dag.entryAfter ["writeBoundary"] ''
|
||||||
|
${builtins.readFile ./trampoline-apps.sh}
|
||||||
|
fromDir="${apps}/Applications"
|
||||||
|
toDir="$HOME/Applications/Home Manager Trampolines"
|
||||||
|
sync_trampolines "$fromDir" "$toDir"
|
||||||
|
'';
|
||||||
|
home.extraActivationPath = with pkgs; [
|
||||||
|
rsync
|
||||||
|
dockutil
|
||||||
|
gawk
|
||||||
|
];
|
||||||
|
}
|
131
darwin/profiles/desktop/home/trampoline-apps.sh
Normal file
131
darwin/profiles/desktop/home/trampoline-apps.sh
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
# Utilities not in nixpkgs.
|
||||||
|
plutil="/usr/bin/plutil"
|
||||||
|
killall="/usr/bin/killall"
|
||||||
|
osacompile="/usr/bin/osacompile"
|
||||||
|
|
||||||
|
copyable_app_props=(
|
||||||
|
"CFBundleDevelopmentRegion"
|
||||||
|
"CFBundleDocumentTypes"
|
||||||
|
"CFBundleGetInfoString"
|
||||||
|
"CFBundleIconFile"
|
||||||
|
"CFBundleIdentifier"
|
||||||
|
"CFBundleInfoDictionaryVersion"
|
||||||
|
"CFBundleName"
|
||||||
|
"CFBundleShortVersionString"
|
||||||
|
"CFBundleURLTypes"
|
||||||
|
"NSAppleEventsUsageDescription"
|
||||||
|
"NSAppleScriptEnabled"
|
||||||
|
"NSDesktopFolderUsageDescription"
|
||||||
|
"NSDocumentsFolderUsageDescription"
|
||||||
|
"NSDownloadsFolderUsageDescription"
|
||||||
|
"NSPrincipalClass"
|
||||||
|
"NSRemovableVolumesUsageDescription"
|
||||||
|
"NSServices"
|
||||||
|
"UTExportedTypeDeclarations"
|
||||||
|
)
|
||||||
|
|
||||||
|
function sync_icons() {
|
||||||
|
local from="$1"
|
||||||
|
local to="$2"
|
||||||
|
from_resources="$from/Contents/Resources/"
|
||||||
|
to_resources="$to/Contents/Resources/"
|
||||||
|
|
||||||
|
find "$to_resources" -name "*.icns" -delete
|
||||||
|
rsync --include "*.icns" --exclude "*" --recursive "$from_resources" "$to_resources"
|
||||||
|
}
|
||||||
|
|
||||||
|
function copy_paths() {
|
||||||
|
local from="$1"
|
||||||
|
local to="$2"
|
||||||
|
local paths=("${@:3}")
|
||||||
|
|
||||||
|
keys=$(jq -n '$ARGS.positional' --args "${paths[@]}")
|
||||||
|
jqfilter='to_entries |[.[]| select(.key as $item| $keys | index($item) >= 0) ] | from_entries'
|
||||||
|
|
||||||
|
temp_dir=$(mktemp -d)
|
||||||
|
trap 'rm -rf "$temp_dir"' EXIT
|
||||||
|
|
||||||
|
pushd "$temp_dir" > /dev/null || exit
|
||||||
|
|
||||||
|
cp "$from" "orig"
|
||||||
|
chmod u+w "orig"
|
||||||
|
|
||||||
|
cp "$to" "bare-wrapper"
|
||||||
|
chmod u+w "bare-wrapper"
|
||||||
|
|
||||||
|
$plutil -convert json -- "orig"
|
||||||
|
$plutil -convert json -- "bare-wrapper"
|
||||||
|
jq --argjson keys "$keys" "$jqfilter" < "orig" > "filtered"
|
||||||
|
cat "bare-wrapper" "filtered" | jq -s add > "final"
|
||||||
|
$plutil -convert xml1 -- "final"
|
||||||
|
|
||||||
|
cp "final" "$to"
|
||||||
|
popd > /dev/null || exit
|
||||||
|
}
|
||||||
|
|
||||||
|
function sync_dock() {
|
||||||
|
# Make sure all environment variables are cleared that might affect dockutil
|
||||||
|
unset SUDO_USER
|
||||||
|
|
||||||
|
# Array of applications to sync
|
||||||
|
declare -a apps=("$@")
|
||||||
|
|
||||||
|
# Iterate through each provided app
|
||||||
|
for app_path in "${apps[@]}"; do
|
||||||
|
if [ -d "$app_path" ]; then
|
||||||
|
# Extract the name of the app from the path
|
||||||
|
app_name=$(basename "$app_path")
|
||||||
|
app_name=${app_name%.*} # Remove the '.app' extension
|
||||||
|
resolved_path=$(realpath "$app_path")
|
||||||
|
|
||||||
|
# Find the current Dock item for the app, if it exists
|
||||||
|
current_dock_item=$(dockutil --list --no-restart | grep "$app_name.app" | awk -F "\t" '{print $1}' || echo "")
|
||||||
|
|
||||||
|
if [ -n "$current_dock_item" ]; then
|
||||||
|
# The app is currently in the Dock, attempt to replace it
|
||||||
|
echo "Updating $app_name in Dock..."
|
||||||
|
dockutil --add "$resolved_path" --replacing "$current_dock_item" --no-restart
|
||||||
|
else
|
||||||
|
# The app is not in the Dock; you might choose to add it or do nothing
|
||||||
|
echo "$app_name is not currently in the Dock."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Warning: Provided path $app_path is not valid."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Restart the Dock to apply changes
|
||||||
|
$killall Dock
|
||||||
|
}
|
||||||
|
|
||||||
|
function mktrampoline() {
|
||||||
|
local app="$1"
|
||||||
|
local trampoline="$2"
|
||||||
|
|
||||||
|
if [[ ! -d $app ]]; then
|
||||||
|
echo "app path is not directory."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cmd="do shell script \"open '$app'\""
|
||||||
|
$osacompile -o "$trampoline" -e "$cmd"
|
||||||
|
sync_icons "$app" "$trampoline"
|
||||||
|
copy_paths "$(realpath "$app/Contents/Info.plist")" "$(realpath "$trampoline/Contents/Info.plist")" "${copyable_app_props[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function sync_trampolines() {
|
||||||
|
[[ ! -d $1 ]] && echo "Source directory does not exist" && return 1
|
||||||
|
|
||||||
|
if [[ -d $2 ]]; then
|
||||||
|
rm -rf "$2"
|
||||||
|
fi
|
||||||
|
mkdir -p "$2"
|
||||||
|
|
||||||
|
apps=("$1"/*.app)
|
||||||
|
|
||||||
|
for app in "${apps[@]}"; do
|
||||||
|
trampoline="$2/$(basename "$app")"
|
||||||
|
mktrampoline "$app" "$trampoline"
|
||||||
|
done
|
||||||
|
sync_dock "${apps[@]}"
|
||||||
|
}
|
6
darwin/profiles/desktop/packages/default.nix
Normal file
6
darwin/profiles/desktop/packages/default.nix
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{...}: {
|
||||||
|
imports = [
|
||||||
|
./fonts.nix
|
||||||
|
./window-manager.nix
|
||||||
|
];
|
||||||
|
}
|
5
darwin/profiles/desktop/packages/fonts.nix
Normal file
5
darwin/profiles/desktop/packages/fonts.nix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{pkgs, ...}: {
|
||||||
|
fonts.packages = with pkgs; [
|
||||||
|
(nerdfonts.override {fonts = ["JetBrainsMono"];})
|
||||||
|
];
|
||||||
|
}
|
41
darwin/profiles/desktop/packages/window-manager.nix
Normal file
41
darwin/profiles/desktop/packages/window-manager.nix
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
{pkgs, ...}: {
|
||||||
|
services = {
|
||||||
|
yabai = {
|
||||||
|
enable = true;
|
||||||
|
enableScriptingAddition = true;
|
||||||
|
config = {
|
||||||
|
layout = "bsp";
|
||||||
|
mouse_modifier = "fn";
|
||||||
|
|
||||||
|
# very broken on slow cpu
|
||||||
|
#focus_follows_mouse = "autoraise";
|
||||||
|
#mouse_follows_focus = "on";
|
||||||
|
|
||||||
|
top_padding = 10;
|
||||||
|
bottom_padding = 10;
|
||||||
|
left_padding = 10;
|
||||||
|
right_padding = 10;
|
||||||
|
window_gap = 4;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
skhd = {
|
||||||
|
enable = true;
|
||||||
|
skhdConfig = ''
|
||||||
|
# FIXME
|
||||||
|
cmd - return : open -n ${pkgs.alacritty}/Applications/Alacritty.app
|
||||||
|
|
||||||
|
cmd - 1 : yabai -m space --focus 1 # Focus space
|
||||||
|
cmd - 2 : yabai -m space --focus 2
|
||||||
|
cmd - 3 : yabai -m space --focus 3
|
||||||
|
cmd - 4 : yabai -m space --focus 4
|
||||||
|
cmd - 5 : yabai -m space --focus 5
|
||||||
|
|
||||||
|
shift + cmd - 1 : yabai -m window --space 1 # Send to space
|
||||||
|
shift + cmd - 2 : yabai -m window --space 2
|
||||||
|
shift + cmd - 3 : yabai -m window --space 3
|
||||||
|
shift + cmd - 4 : yabai -m window --space 4
|
||||||
|
shift + cmd - 5 : yabai -m window --space 5
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
21
flake.lock
21
flake.lock
|
@ -214,6 +214,26 @@
|
||||||
"url": "https://git.ny4.dev/nyancat/nvim"
|
"url": "https://git.ny4.dev/nyancat/nvim"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nix-darwin": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1724299755,
|
||||||
|
"narHash": "sha256-P5zMA17kD9tqiqMuNXwupkM7buM3gMNtoZ1VuJTRDE4=",
|
||||||
|
"owner": "LnL7",
|
||||||
|
"repo": "nix-darwin",
|
||||||
|
"rev": "a8968d88e5a537b0491f68ce910749cd870bdbef",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "LnL7",
|
||||||
|
"repo": "nix-darwin",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixos-hardware": {
|
"nixos-hardware": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1724067415,
|
"lastModified": 1724067415,
|
||||||
|
@ -286,6 +306,7 @@
|
||||||
"impermanence": "impermanence",
|
"impermanence": "impermanence",
|
||||||
"lanzaboote": "lanzaboote",
|
"lanzaboote": "lanzaboote",
|
||||||
"neovim": "neovim",
|
"neovim": "neovim",
|
||||||
|
"nix-darwin": "nix-darwin",
|
||||||
"nixos-hardware": "nixos-hardware",
|
"nixos-hardware": "nixos-hardware",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"pre-commit-hooks-nix": "pre-commit-hooks-nix",
|
"pre-commit-hooks-nix": "pre-commit-hooks-nix",
|
||||||
|
|
39
flake.nix
39
flake.nix
|
@ -40,6 +40,10 @@
|
||||||
inputs.treefmt-nix.follows = "treefmt-nix";
|
inputs.treefmt-nix.follows = "treefmt-nix";
|
||||||
inputs.systems.follows = "systems";
|
inputs.systems.follows = "systems";
|
||||||
};
|
};
|
||||||
|
nix-darwin = {
|
||||||
|
url = "github:LnL7/nix-darwin";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
nixos-hardware = {
|
nixos-hardware = {
|
||||||
url = "github:NixOS/nixos-hardware";
|
url = "github:NixOS/nixos-hardware";
|
||||||
};
|
};
|
||||||
|
@ -92,7 +96,7 @@
|
||||||
formatter = treefmtEval.config.build.wrapper;
|
formatter = treefmtEval.config.build.wrapper;
|
||||||
|
|
||||||
### nix flake check
|
### nix flake check
|
||||||
checks.formatting = treefmtEval.config.build.check inputs.self;
|
checks = {formatting = treefmtEval.config.build.check inputs.self;};
|
||||||
|
|
||||||
### nix {run,shell,build}
|
### nix {run,shell,build}
|
||||||
legacyPackages = import ./pkgs pkgs;
|
legacyPackages = import ./pkgs pkgs;
|
||||||
|
@ -105,22 +109,37 @@
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
// {
|
// (let
|
||||||
|
mkNixOS = system: modules:
|
||||||
|
inputs.nixpkgs.lib.nixosSystem {
|
||||||
|
inherit system;
|
||||||
|
modules = [./nixos/profiles/core] ++ modules;
|
||||||
|
specialArgs = {inherit inputs;};
|
||||||
|
};
|
||||||
|
|
||||||
|
mkDarwin = system: modules:
|
||||||
|
inputs.nix-darwin.lib.darwinSystem {
|
||||||
|
inherit system modules;
|
||||||
|
specialArgs = {inherit inputs;};
|
||||||
|
};
|
||||||
|
in {
|
||||||
### imports = [];
|
### imports = [];
|
||||||
nixosModules.default = ./nixos/modules;
|
nixosModules.default = ./nixos/modules;
|
||||||
|
darwinModules.default = ./darwin/modules;
|
||||||
homeManagerModules.default = ./home/modules;
|
homeManagerModules.default = ./home/modules;
|
||||||
|
|
||||||
### nixpkgs.overlays = [];
|
### nixpkgs.overlays = [];
|
||||||
overlays = import ./overlays;
|
overlays = import ./overlays;
|
||||||
|
|
||||||
### NixOS
|
### NixOS
|
||||||
nixosConfigurations."dust" = inputs.nixpkgs.lib.nixosSystem {
|
nixosConfigurations = {
|
||||||
system = "x86_64-linux";
|
"dust" = mkNixOS "x86_64-linux" [./hosts/dust];
|
||||||
modules = [
|
};
|
||||||
./nixos/profiles/core
|
|
||||||
./hosts/dust
|
### Darwin
|
||||||
];
|
darwinConfigurations = {
|
||||||
specialArgs = {inherit inputs;};
|
"plato" = mkDarwin "x86_64-darwin" [./hosts/plato];
|
||||||
|
"whitesteel" = mkDarwin "x86_64-darwin" [./hosts/whitesteel];
|
||||||
};
|
};
|
||||||
|
|
||||||
colmena = {
|
colmena = {
|
||||||
|
@ -146,5 +165,5 @@
|
||||||
deployment.targetHost = "blacksteel"; # thru tailscale
|
deployment.targetHost = "blacksteel"; # thru tailscale
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,31 @@
|
||||||
{
|
{
|
||||||
lib,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
home = {
|
home = {
|
||||||
username = "guanranwang";
|
username = "guanranwang";
|
||||||
homeDirectory = "/home/guanranwang";
|
homeDirectory =
|
||||||
|
if pkgs.stdenv.hostPlatform.isDarwin
|
||||||
|
then "/Users/${config.home.username}"
|
||||||
|
else "/home/${config.home.username}";
|
||||||
|
|
||||||
|
# This value determines the Home Manager release that your
|
||||||
|
# configuration is compatible with. This helps avoid breakage
|
||||||
|
# when a new Home Manager release introduces backwards
|
||||||
|
# incompatible changes.
|
||||||
|
#
|
||||||
|
# You can update Home Manager without changing this value. See
|
||||||
|
# the Home Manager release notes for a list of state version
|
||||||
|
# changes in each release.
|
||||||
stateVersion = "23.05";
|
stateVersion = "23.05";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Let Home Manager install and manage itself.
|
||||||
|
programs.home-manager.enable = true;
|
||||||
|
|
||||||
|
# Default applications
|
||||||
imports = [
|
imports = [
|
||||||
./applications/atuin
|
./applications/atuin
|
||||||
./applications/bash
|
./applications/bash
|
||||||
|
@ -28,10 +45,14 @@
|
||||||
programs.ripgrep.enable = true;
|
programs.ripgrep.enable = true;
|
||||||
programs.skim.enable = true;
|
programs.skim.enable = true;
|
||||||
programs.zoxide.enable = true;
|
programs.zoxide.enable = true;
|
||||||
home.packages = with pkgs; [
|
home.packages =
|
||||||
fastfetch
|
(with pkgs; [
|
||||||
fd
|
fd
|
||||||
];
|
fastfetch
|
||||||
|
])
|
||||||
|
++ lib.optionals pkgs.stdenv.hostPlatform.isLinux (with pkgs; [
|
||||||
|
trashy
|
||||||
|
]);
|
||||||
|
|
||||||
programs.fish.functions = let
|
programs.fish.functions = let
|
||||||
jq = lib.getExe pkgs.jq;
|
jq = lib.getExe pkgs.jq;
|
||||||
|
|
12
hosts/plato/default.nix
Normal file
12
hosts/plato/default.nix
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# iMac 18,3 (2017)
|
||||||
|
{...}: {
|
||||||
|
imports = [
|
||||||
|
../../darwin/profiles/desktop
|
||||||
|
../../darwin/profiles/common/opt-in/mihomo.nix
|
||||||
|
];
|
||||||
|
|
||||||
|
networking.hostName = "plato";
|
||||||
|
time.timeZone = "Asia/Shanghai";
|
||||||
|
system.stateVersion = 4;
|
||||||
|
nixpkgs.hostPlatform = "x86_64-darwin";
|
||||||
|
}
|
11
hosts/whitesteel/default.nix
Normal file
11
hosts/whitesteel/default.nix
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{...}: {
|
||||||
|
imports = [
|
||||||
|
../../darwin/profiles/desktop
|
||||||
|
../../darwin/profiles/common/opt-in/mihomo.nix
|
||||||
|
];
|
||||||
|
|
||||||
|
networking.hostName = "whitesteel";
|
||||||
|
time.timeZone = "Asia/Shanghai";
|
||||||
|
system.stateVersion = 4;
|
||||||
|
nixpkgs.hostPlatform = "x86_64-darwin";
|
||||||
|
}
|
|
@ -6,10 +6,6 @@
|
||||||
services.sing-box = {
|
services.sing-box = {
|
||||||
enable = true;
|
enable = true;
|
||||||
settings = {
|
settings = {
|
||||||
log = {
|
|
||||||
level = "info";
|
|
||||||
};
|
|
||||||
|
|
||||||
inbounds = [
|
inbounds = [
|
||||||
{
|
{
|
||||||
type = "http";
|
type = "http";
|
||||||
|
@ -71,15 +67,12 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
### System proxy settings
|
### System proxy settings
|
||||||
networking.proxy = {
|
networking.proxy.default = "http://127.0.0.1:1080/";
|
||||||
httpProxy = "http://127.0.0.1:1080/";
|
|
||||||
httpsProxy = "http://127.0.0.1:1080/";
|
|
||||||
};
|
|
||||||
environment.shellAliases = let
|
environment.shellAliases = let
|
||||||
inherit (config.networking.proxy) httpProxy httpsProxy;
|
inherit (config.networking) proxy;
|
||||||
in {
|
in {
|
||||||
"setproxy" = "export http_proxy=${httpProxy} https_proxy=${httpsProxy}";
|
"setproxy" = "export http_proxy=${proxy.httpProxy} https_proxy=${proxy.httpsProxy} all_proxy=${proxy.allProxy} ftp_proxy=${proxy.ftpProxy} rsync_proxy=${proxy.rsyncProxy}";
|
||||||
"unsetproxy" = "set -e http_proxy https_proxy";
|
"unsetproxy" = "set -e http_proxy https_proxy all_proxy ftp_proxy rsync_proxy";
|
||||||
};
|
};
|
||||||
|
|
||||||
### sops-nix
|
### sops-nix
|
||||||
|
|
Loading…
Reference in a new issue