Merge pull request #1 from ryan4yin/darwin

feat: add support for darwin, redesign the project structure.
This commit is contained in:
Ryan Yin
2023-05-26 03:10:54 -06:00
committed by GitHub
25 changed files with 404 additions and 74 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
result
result/

View File

@@ -1,8 +1,11 @@
deploy:
sudo nixos-rebuild switch --flake .
sudo nixos-rebuild switch --flake . \
--extra-experimental-features 'nix-command flakes'
debug:
sudo nixos-rebuild switch --flake . --show-trace --verbose
sudo nixos-rebuild switch --flake . \
--show-trace --verbose \
--extra-experimental-features 'nix-command flakes'
update:
nix flake update
@@ -13,3 +16,23 @@ history:
gc:
sudo nix-collect-garbage --delete-older-than 14d
darwin-set-proxy:
# set proxy for nix-daemon to speed up downloads
# https://github.com/NixOS/nix/issues/1472#issuecomment-1532955973
sudo python3 scripts/darwin_set_proxy.py
darwin: darwin-set-proxy
nix build .#darwinConfigurations.harmonica.system \
--extra-experimental-features 'nix-command flakes'
./result/sw/bin/darwin-rebuild switch --flake .
darwin-debug: darwin-set-proxy
nix build .#darwinConfigurations.harmonica.system \
--show-trace --verbose \
--extra-experimental-features 'nix-command flakes'
./result/sw/bin/darwin-rebuild switch --flake . --show-trace --verbose
.PHONY: clean
clean:
-rm -rf result

View File

@@ -11,6 +11,8 @@ This repository is home to the nix code that builds my systems.
- enable disk encryption to enhance data security
- make fcitx5-rime work in vscode/chrome on wayland
- auto unlock with `ssh-agent` after login
- [People using ssh-agent, how do you unlock it on login? - reddit](https://www.reddit.com/r/NixOS/comments/lsbo9a/people_using_sshagent_how_do_you_unlock_it_on/)
## Why Nix?
@@ -22,7 +24,9 @@ Want to know Nix in details? Looking for a beginner-friendly tutorial? Check out
>Note: you should NOT deploy this flake directly on your machine, it contains my hardware information and personal information which is not suitable for you. You may use this repo as a reference to build your own configuration.
After installed NixOS with `nix-command` & `flake` enabled, you can deploy this flake with the following command:
After installed NixOS with `nix-command` & `flake` enabled, flow the steps below to deploy this flake.
For NixOS, use the following commands:
```bash
# deploy my test configuration
@@ -39,6 +43,17 @@ sudo nixos-rebuild switch
make deploy
```
For MacOS, use the following commands:
```bash
# set proxy for nix-daemon to speed up downloads
# https://github.com/NixOS/nix/issues/1472#issuecomment-1532955973
make darwin-set-proxy
# or just deploy using make, which is defined in Makefile
make darwin
```
## Install Apps from Flatpak
We can install apps from flathub, which has a lot of apps that are not supported well in nixpkgs.

99
flake.lock generated
View File

@@ -29,11 +29,32 @@
]
},
"locked": {
"lastModified": 1684343812,
"narHash": "sha256-ZTEjiC8PDKeP8JRchuwcFXUNlMcyQ4U+DpyVZ3pB6Q4=",
"lastModified": 1673295039,
"narHash": "sha256-AsdYgE8/GPwcelGgrntlijMg4t3hLFJFCRF3tL5WVjA=",
"owner": "lnl7",
"repo": "nix-darwin",
"rev": "dfbdabbb3e797334172094d4f6c0ffca8c791281",
"rev": "87b9d090ad39b25b2400029c64825fc2a8868943",
"type": "github"
},
"original": {
"owner": "lnl7",
"ref": "master",
"repo": "nix-darwin",
"type": "github"
}
},
"darwin_2": {
"inputs": {
"nixpkgs": [
"nixpkgs-darwin"
]
},
"locked": {
"lastModified": 1684774948,
"narHash": "sha256-hJTaw4dYzcB+lsasKejnafq0CxPsVetn9RLXrcL+4jE=",
"owner": "lnl7",
"repo": "nix-darwin",
"rev": "b8c286c82c6b47826a6c0377e7017052ad91353c",
"type": "github"
},
"original": {
@@ -199,11 +220,11 @@
]
},
"locked": {
"lastModified": 1684596126,
"narHash": "sha256-4RZZmygeEXpuBqEXGs38ZAcWjWKGwu13Iqbxub6wuJk=",
"lastModified": 1682203081,
"narHash": "sha256-kRL4ejWDhi0zph/FpebFYhzqlOBrk0Pl3dzGEKSAlEw=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "27ef11f0218d9018ebb2948d40133df2b1de622d",
"rev": "32d3e39c491e2f91152c84f8ad8b003420eab0a1",
"type": "github"
},
"original": {
@@ -219,11 +240,11 @@
]
},
"locked": {
"lastModified": 1684484967,
"narHash": "sha256-P3ftCqeJmDYS9LSr2gGC4XGGcp5vv8TOasJX6fVHWsw=",
"lastModified": 1685019994,
"narHash": "sha256-81o6SKZPALvib21hIOMx2lIhFSs0mRy0PfPvg0zsfTk=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "b9a52ad20e58ebd003444915e35e3dd2c18fc715",
"rev": "d1f04b0f365a34896a37d9015637796537ec88a3",
"type": "github"
},
"original": {
@@ -397,11 +418,11 @@
]
},
"locked": {
"lastModified": 1683530131,
"narHash": "sha256-R0RSqj6JdZfru2x/cM19KJMHsU52OjtyxI5cccd+uFc=",
"lastModified": 1685000237,
"narHash": "sha256-pm+2xP9g9sh6wapk1ulg7/1DdENkTNDB7Kx+6lwGs/k=",
"owner": "nix-community",
"repo": "nixos-generators",
"rev": "10079333313ff62446e6f2b0e7c5231c7431d269",
"rev": "05bef004794f352ea12475a89f3f55b4102c0728",
"type": "github"
},
"original": {
@@ -412,11 +433,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1684570954,
"narHash": "sha256-FX5y4Sm87RWwfu9PI71XFvuRpZLowh00FQpIJ1WfXqE=",
"lastModified": 1677676435,
"narHash": "sha256-6FxdcmQr5JeZqsQvfinIMr0XcTyTuR7EXX0H3ANShpQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3005f20ce0aaa58169cdee57c8aa12e5f1b6e1b3",
"rev": "a08d6979dd7c82c4cef0dcc6ac45ab16051c1169",
"type": "github"
},
"original": {
@@ -426,6 +447,22 @@
"type": "github"
}
},
"nixpkgs-darwin": {
"locked": {
"lastModified": 1684968804,
"narHash": "sha256-y78lDeiJC/MSOM6HBe1VI5G2lrrmJMkWigRuOrf20uA=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "f69907854223d6d49f75b1ae52b2f6567f711d90",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-23.05-darwin",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1681001314,
@@ -475,11 +512,11 @@
},
"nixpkgs-stable_2": {
"locked": {
"lastModified": 1684782344,
"narHash": "sha256-SHN8hPYYSX0thDrMLMWPWYulK3YFgASOrCsIL3AJ78g=",
"lastModified": 1685004253,
"narHash": "sha256-AbVL1nN/TDicUQ5wXZ8xdLERxz/eJr7+o8lqkIOVuaE=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "8966c43feba2c701ed624302b6a935f97bcbdf88",
"rev": "3e01645c40b92d29f3ae76344a6d654986a91a91",
"type": "github"
},
"original": {
@@ -497,11 +534,11 @@
"nixpkgs": "nixpkgs_7"
},
"locked": {
"lastModified": 1684592015,
"narHash": "sha256-6gFt1LE/stVQFeGI263pU6O5EAeY1TPTGee1vvbkwZo=",
"lastModified": 1685045766,
"narHash": "sha256-MK128KJnrf0PqfdnL40KN57ZSpHPtru19TH+Ok0A0TU=",
"owner": "nix-community",
"repo": "nixpkgs-wayland",
"rev": "aeb1b88206756e867e398d18e2856b60fc803e12",
"rev": "38c86d9ff0a4cff1e229214031f7eaaab34e10f1",
"type": "github"
},
"original": {
@@ -560,11 +597,11 @@
},
"nixpkgs_5": {
"locked": {
"lastModified": 1684570954,
"narHash": "sha256-FX5y4Sm87RWwfu9PI71XFvuRpZLowh00FQpIJ1WfXqE=",
"lastModified": 1684935479,
"narHash": "sha256-6QMMsXMr2nhmOPHdti2j3KRHt+bai2zw+LJfdCl97Mk=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "3005f20ce0aaa58169cdee57c8aa12e5f1b6e1b3",
"rev": "f91ee3065de91a3531329a674a45ddcb3467a650",
"type": "github"
},
"original": {
@@ -592,11 +629,11 @@
},
"nixpkgs_7": {
"locked": {
"lastModified": 1684570954,
"narHash": "sha256-FX5y4Sm87RWwfu9PI71XFvuRpZLowh00FQpIJ1WfXqE=",
"lastModified": 1684935479,
"narHash": "sha256-6QMMsXMr2nhmOPHdti2j3KRHt+bai2zw+LJfdCl97Mk=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "3005f20ce0aaa58169cdee57c8aa12e5f1b6e1b3",
"rev": "f91ee3065de91a3531329a674a45ddcb3467a650",
"type": "github"
},
"original": {
@@ -608,11 +645,11 @@
},
"nur": {
"locked": {
"lastModified": 1684585623,
"narHash": "sha256-28XEOYjrpzlVDt11Elz7db8R3HwY/4B6EspFscSRsfk=",
"lastModified": 1685061478,
"narHash": "sha256-fNCFmOOfTmtWCV4WEoAnwwyjjB4NRAzucTKdt0w5zvg=",
"owner": "nix-community",
"repo": "NUR",
"rev": "4e959da0346280293e4008150d48b82fe055a311",
"rev": "82f3aa5c5a85a9f2a1e72eaf0eec30c8ab8fdf2c",
"type": "github"
},
"original": {
@@ -652,12 +689,14 @@
"root": {
"inputs": {
"agenix": "agenix",
"darwin": "darwin_2",
"devenv": "devenv",
"home-manager": "home-manager_2",
"hyprland": "hyprland",
"nil": "nil",
"nixos-generators": "nixos-generators",
"nixpkgs": "nixpkgs_5",
"nixpkgs-darwin": "nixpkgs-darwin",
"nixpkgs-stable": "nixpkgs-stable_2",
"nixpkgs-wayland": "nixpkgs-wayland",
"nur": "nur"

View File

@@ -9,10 +9,12 @@
# sudo ip route del default via 192.168.5.201
nixConfig = {
experimental-features = [ "nix-command" "flakes" ];
substituters = [
# replace official cache with a mirror located in China
"https://mirrors.bfsu.edu.cn/nix-channels/store"
"https://cache.nixos.org/"
"https://mirrors.ustc.edu.cn/nix-channels/store"
"https://cache.nixos.org"
];
# nix community's cache server
@@ -37,6 +39,13 @@
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # 使用 nixos-unstable 分支 for nix flakes
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.05"; # unstable branch may be broken sometimes, use stable branch when necessary
# for macos
nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-23.05-darwin";
darwin = {
url = "github:lnl7/nix-darwin/master";
inputs.nixpkgs.follows = "nixpkgs-darwin";
};
# nix users repository
# used to install some packages not in nixpkgs
# e.g. wechat-uos/qqmusic/dingtalk
@@ -74,6 +83,7 @@
outputs = inputs@{
self,
nixpkgs,
darwin,
home-manager,
...
}: {
@@ -94,7 +104,7 @@
# 使用 home-manager.extraSpecialArgs 自定义传递给 ./home 的参数
home-manager.extraSpecialArgs = inputs;
home-manager.users.ryan = import ./home;
home-manager.users.ryan = import ./home/home-x11.nix;
}
];
};
@@ -115,12 +125,33 @@
# 使用 home-manager.extraSpecialArgs 自定义传递给 ./home 的参数
home-manager.extraSpecialArgs = inputs;
home-manager.users.ryan = import ./home;
home-manager.users.ryan = import ./home/home-wayland.nix;
}
];
};
};
darwinConfigurations."harmonica" = darwin.lib.darwinSystem {
system = "x86_64-darwin";
specialArgs = inputs;
modules = [
./hosts/harmonica
# home-manager 作为 nixos 的一个 module
# 这样在 nixos-rebuild switch 时home-manager 也会被自动部署,不需要额外执行 home-manager switch 命令
home-manager.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
# 使用 home-manager.extraSpecialArgs 自定义传递给 ./home 的参数
home-manager.extraSpecialArgs = inputs;
home-manager.users.admin = import ./home/home-darwin.nix;
}
];
};
# generate qcow2 & iso image from nixos configuration
# https://github.com/nix-community/nixos-generators
# packages.x86_64-linux = {

10
home/darwin/default.nix Normal file
View File

@@ -0,0 +1,10 @@
{pkgs, ...}:
{
home.packages = with pkgs; [
docker-compose
kubectl
kubernetes-helm
terraform
pulumi
];
}

28
home/home-darwin.nix Normal file
View File

@@ -0,0 +1,28 @@
{ pkgs, ... }:
{
imports = [
./darwin
];
# Home Manager needs a bit of information about you and the
# paths it should manage.
home = {
username = "admin";
# set homeDirectory make build fail
# homeDirectory = "/Users/admin";
# 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 = "22.11";
};
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
}

View File

@@ -1,13 +1,10 @@
{ config, pkgs, ... }:
{
imports = [
./fcitx5
./hyprland
# ./i3
./programs
./rofi
./shell
];

31
home/home-x11.nix Normal file
View File

@@ -0,0 +1,31 @@
{ config, pkgs, ... }:
{
imports = [
./fcitx5
./i3
./programs
./rofi
./shell
];
# Home Manager needs a bit of information about you and the
# paths it should manage.
home = {
username = "ryan";
homeDirectory = "/home/ryan";
# 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 = "22.11";
};
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
}

View File

@@ -4,6 +4,10 @@
lib,
...
}: {
imports = [
./wayland-apps.nix
];
# hyprland configs, based on https://github.com/notwidow/hyprland
home.file.".config/hypr" = {
source = ./hypr-conf;

View File

@@ -2,7 +2,6 @@
pkgs,
nixpkgs-stable,
config,
nil,
...
}: let
pkgs-stable = import nixpkgs-stable {
@@ -12,9 +11,7 @@
in {
home.packages = with pkgs-stable; [
firefox-wayland # firefox with wayland support
# firefox
nil.packages."${pkgs.system}".default # nix language server
wineWowPackages.wayland
];

View File

@@ -7,6 +7,10 @@
# i3 配置,基于 https://github.com/endeavouros-team/endeavouros-i3wm-setup
# 直接从当前文件夹中读取配置文件作为配置内容
imports = [
./x11-apps.nix
];
# wallpaper, binary file
home.file.".config/i3/wallpaper.png".source = ../wallpapers/wallpaper.png;
home.file.".config/i3/config".source = ./config;

37
home/i3/x11-apps.nix Normal file
View File

@@ -0,0 +1,37 @@
{
pkgs,
...
}: {
home.packages = with pkgs; [
firefox
];
# TODO vscode & chrome both have wayland support, but they don't work with fcitx5, need to fix it.
programs = {
# source code: https://github.com/nix-community/home-manager/blob/master/modules/programs/chromium.nix
google-chrome = {
enable = true;
# chrome wayland support was broken on nixos-unstable branch, so fallback to stable branch for now
# https://github.com/swaywm/sway/issues/7562
package = pkgs.google-chrome;
# commandLineArgs = [
# ];
};
vscode = {
enable = true;
# use the stable version
# package = pkgs.vscode.override {
# commandLineArgs = [
# ];
# };
# let vscode sync and update its configuration & extensions across devices, using github account.
# userSettings = {};
};
};
}

View File

@@ -1,4 +1,4 @@
{pkgs, config, ...}:
{pkgs, config, nil, ...}:
{
@@ -22,13 +22,14 @@
# misc
libnotify
wineWowPackages.wayland
xdg-utils
# productivity
obsidian
hugo
nil.packages."${pkgs.system}".default # nix language server
# IDE
insomnia
jetbrains.pycharm-community
@@ -104,6 +105,9 @@
ltrace # library call monitoring
lsof
mtr
# A tool to create bootable live USB drives from ISO images
unetbootin
];
programs = {

View File

@@ -4,7 +4,6 @@
...
}: {
imports = [
./browsers.nix
./common.nix
./git.nix
./media.nix

View File

@@ -10,13 +10,13 @@
# all my ssh private key are generated by `ssh-keygen -t ed25519 -C "ryan@nickname"`
# the config's format:
# Host — the nickname youll use for the host.
# HostName — the IP address or domain of the remote server.
# User — the username associated with the remote account.
# Host — given the pattern used to match against the host name given on the command line.
# HostName — specify nickname or abbreviation for host
# IdentityFile — the location of your SSH key authentication file for the account.
# format in details:
# https://www.ssh.com/academy/ssh/config
extraConfig = ''
Host Homelab
Hostname 192.168.*
Host 192.168.*
# allow to securely use local SSH agent to authenticate on the remote machine.
# It has the same effect as adding cli option `ssh -A user@host`
ForwardAgent yes
@@ -26,8 +26,7 @@
# required to prevent sending default identity files first.
IdentitiesOnly yes
Host GitHub
Hostname github.com
Host github.com
# github is controlled by gluttony~
IdentityFile ~/.ssh/gluttony
# Specifies that ssh should only use the identity file explicitly configured above
@@ -38,6 +37,7 @@
# use ssh-agent so we only need to input passphrase once
# run `ssh-add /path/to/key` for every identity file
# check imported keys by `ssh-add -l`
# TODO `ssh-add` can only add keys temporary, use gnome-keyring to unlock all keys after login.
};
programs.git = {

View File

@@ -11,7 +11,6 @@
"application/xhtml+xml" = browser;
"text/html" = browser;
"x-scheme-handler/about" = browser;
# "x-scheme-handler/chrome" = ["chromium-browser.desktop"];
"x-scheme-handler/ftp" = browser;
"x-scheme-handler/http" = browser;
"x-scheme-handler/https" = browser;
@@ -21,9 +20,8 @@
"video/*" = ["mpv.dekstop"];
"image/*" = ["imv.desktop"];
"application/json" = browser;
"application/pdf" = ["org.pwmt.zathura.desktop.desktop"]; # TODO: pdf viewer
"application/pdf" = browser; # TODO: pdf viewer
"x-scheme-handler/discord" = ["discord.desktop"];
"x-scheme-handler/spotify" = ["spotify.desktop"];
"x-scheme-handler/tg" = ["telegramdesktop.desktop"];
};
in {

View File

@@ -24,7 +24,11 @@ in rec {
LESSHISTFILE = cache + "/less/history";
LESSKEY = c + "/less/lesskey";
WINEPREFIX = d + "/wine";
XAUTHORITY = "$XDG_RUNTIME_DIR/Xauthority";
# set this variable make i3 failed to start
# related issue:
# https://github.com/sddm/sddm/issues/871
# XAUTHORITY = "$XDG_RUNTIME_DIR/Xauthority";
# set default applications
BROWSER = "firefox";

View File

@@ -0,0 +1,33 @@
# My MacBook Pro - Computer for Business
{ pkgs, ... } @ args:
{
imports = [
../../modules/darwin/common.nix
];
# # enable flakes globally
nix.settings.experimental-features = [ "nix-command" "flakes" ];
# Auto upgrade nix package and the daemon service.
services.nix-daemon.enable = true;
# Use this instead of services.nix-daemon.enable if you
# don't wan't the daemon service to be managed for you.
# nix.useDaemon = true;
nix.package = pkgs.nix;
programs.nix-index.enable = true;
# Add ability to used TouchID for sudo authentication
security.pam.enableSudoTouchIdAuth = true;
# Keyboard
system.keyboard.enableKeyMapping = true;
system.keyboard.remapCapsLockToEscape = true;
# Set your time zone.
time.timeZone = "Asia/Shanghai";
}

View File

@@ -16,8 +16,8 @@
./hardware-configuration.nix
../../modules/fhs-fonts.nix
../../modules/hyprland.nix
#../../modules/i3.nix
# ../../modules/hyprland.nix
../../modules/i3.nix
../../modules/nur-packages.nix
../../modules/system.nix
../../modules/user_group.nix

View File

@@ -53,6 +53,10 @@
} ];
};
defaultGateway = "192.168.5.201";
nameservers = [
"119.29.29.29" # DNSPod
"223.5.5.5" # AliDNS
];
};
# This value determines the NixOS release from which the default

41
modules/darwin/common.nix Normal file
View File

@@ -0,0 +1,41 @@
{ pkgs, lib, ... }:
{
# Create /etc/zshrc that loads the nix-darwin environment.
programs.zsh.enable = true;
# Apps
# `home-manager` currently has issues adding them to `~/Applications`
# Issue: https://github.com/nix-community/home-manager/issues/1341
environment.systemPackages = with pkgs; [
alacritty
jq
bat
];
# Fonts
fonts = {
# use fonts specified by user rather than default ones
fontDir.enable = true;
fonts = with pkgs; [
# icon fonts
material-design-icons
font-awesome
# Noto 系列字体是 Google 主导的名字的含义是「没有豆腐」no tofu因为缺字时显示的方框或者方框被叫作 tofu
# Noto 系列字族名只支持英文,命名规则是 Noto + Sans 或 Serif + 文字名称。
# 其中汉字部分叫 Noto Sans/Serif CJK SC/TC/HK/JP/KR最后一个词是地区变种。
noto-fonts # 大部分文字的常见样式,不包含汉字
noto-fonts-cjk # 汉字部分
noto-fonts-emoji # 彩色的表情符号字体
noto-fonts-extra # 提供额外的字重和宽度变种
# 思源系列字体是 Adobe 主导的。其中汉字部分被称为「思源黑体」和「思源宋体」,是由 Adobe + Google 共同开发的
source-sans # 无衬线字体,不含汉字。字族名叫 Source Sans 3 和 Source Sans Pro以及带字重的变体加上 Source Sans 3 VF
source-serif # 衬线字体,不含汉字。字族名叫 Source Code Pro以及带字重的变体
source-han-sans # 思源黑体
source-han-serif # 思源宋体
];
};
}

View File

@@ -71,19 +71,4 @@
ncmpcpp # a mpd client with a UI
networkmanagerapplet # provide GUI app: nm-connection-editor
];
xdg.portal = {
enable = true;
wlr.enable = true;
xdgOpenUsePortal = true;
extraPortals = with pkgs; [
xdg-desktop-portal-wlr # for wlroots based compositors
xdg-desktop-portal-gtk # for gtk
# xdg-desktop-portal-kde # for kde
];
};
# for power management
services.upower.enable = true;
}

View File

@@ -220,4 +220,19 @@
# android development tools, this will install adb/fastboot and other android tools and udev rules
# see https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/programs/adb.nix
programs.adb.enable = true;
xdg.portal = {
enable = true;
wlr.enable = true;
xdgOpenUsePortal = true;
extraPortals = with pkgs; [
xdg-desktop-portal-wlr # for wlroots based compositors
xdg-desktop-portal-gtk # for gtk
# xdg-desktop-portal-kde # for kde
];
};
# for power management
services.upower.enable = true;
}

View File

@@ -0,0 +1,29 @@
import os
import plistlib
import shlex
import subprocess
from pathlib import Path
NIX_DAEMON_PLIST = Path("/Library/LaunchDaemons/org.nixos.nix-daemon.plist")
NIX_DAEMON_NAME = "org.nixos.nix-daemon"
# http proxy provided by clash
HTTP_PROXY = "http://127.0.0.1:7890"
pl = plistlib.loads(NIX_DAEMON_PLIST.read_bytes())
# set http proxy
pl["EnvironmentVariables"]["HTTP_PROXY"] = HTTP_PROXY
pl["EnvironmentVariables"]["HTTPS_PROXY"] = HTTP_PROXY
os.chmod(NIX_DAEMON_PLIST, 0o644)
NIX_DAEMON_PLIST.write_bytes(plistlib.dumps(pl))
os.chmod(NIX_DAEMON_PLIST, 0o444)
# reload the plist
for cmd in (
f"launchctl unload {NIX_DAEMON_NAME}",
f"launchctl load {NIX_DAEMON_NAME}",
):
subprocess.run(shlex.split(cmd))