Skip to content

Commit

Permalink
Introduce lima in macOS (#913)
Browse files Browse the repository at this point in the history
* Use lima for macOS setup

* Update comment

* Don't depend on unstable channel in macOS as possible

* Fix priority of mkDefault

* Update lima default home directory

* Drop maccy in forked nix

* Drop notify action for now

* Load lima default instance for ssh-agent

* Clarify how to use container in lima

* Uninstall podman and docker-compose from macOS
  • Loading branch information
kachick authored Nov 5, 2024
1 parent 2a925b5 commit 9551003
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 154 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci-home.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ jobs:
zsh -c 'irb --version'
zsh -c 'ssh -V'
zsh -c 'hx --health'
- name: Make sure macos dependencies
if: runner.os == 'macOS'
run: |
zsh -c 'command -v maccy'
- name: Run homemade commands
run: |
zsh -c 'la ~; lat ~/.config'
Expand Down
60 changes: 0 additions & 60 deletions .github/workflows/notify-nixpkgs-news.yml

This file was deleted.

13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ echo '
systemd=true' | sudo tee /etc/wsl.conf
```

## macOS

Activate `kachick@macbook` as Linux and [manually setup some packages](https://github.com/kachick/dotfiles/wiki/macOS).

## Windows

After installing [WSL2](windows/WSL/README.md), you can activate home-manager and [NixOS-WSL](https://github.com/nix-community/NixOS-WSL).\
Expand All @@ -148,6 +144,15 @@ Read [Windows README](windows/README.md) and [CI](.github/workflows/windows.yml)

Check [traps](./windows/Multi-booting.md)

## macOS

I basically [give up to maintain macOS environment](https://github.com/kachick/dotfiles/issues/911). Use [lima](https://github.com/lima-vm/lima) for development tasks as use of WSL2 in Windows

1. Add minimum packages with home-manager. Apply home-manager with `kachick@macbook`
2. Manually setup [lima](https://github.com/kachick/dotfiles/issues/146#issuecomment-2453430154)(default Ubuntu guest) and [some packages](https://github.com/kachick/dotfiles/wiki/macOS) without Nix
3. In the lima as `limactl start`, apply home-manager with `kachick@lima`
4. You can run containers as `lima nerdctl run --rm hello-world`. You can also use podman after above `Podman on Ubuntu` setups

## How to setup secrets

Extracted to [wiki](https://github.com/kachick/dotfiles/wiki/Encryption)
Expand Down
11 changes: 11 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# - https://discourse.nixos.org/t/differences-between-nix-channels/13998
# How to update the revision
# - `nix flake update --commit-lock-file` # https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake-update.html
# TODO: Use nixpkgs-24.05-darwin only in macOS. See GH-910
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
edge-nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# https://github.com/nix-community/home-manager/blob/release-24.05/docs/manual/nix-flakes.md
Expand Down Expand Up @@ -249,6 +250,16 @@
x86-macOS // { modules = [ ./home-manager/kachick.nix ]; }
);

"kachick@lima" = home-manager.lib.homeManagerConfiguration (
x86-Linux
// {
modules = [
./home-manager/kachick.nix
./home-manager/lima.nix
];
}
);

"[email protected]" = home-manager.lib.homeManagerConfiguration (
x86-Linux
// {
Expand Down
5 changes: 1 addition & 4 deletions home-manager/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
];

# home.username = "<UPDATE_ME_IN_FLAKE>";
# TODO: How to cover lima? The default is /home/kachick.local
home.homeDirectory =
if pkgs.stdenv.isDarwin then "/Users/${config.home.username}" else "/home/${config.home.username}";

# https://github.com/nix-community/home-manager/blob/release-24.05/modules/misc/xdg.nix
xdg.enable = true;
Expand All @@ -53,7 +50,7 @@
# NOTE: Original comments in zsh
# - Mouse-wheel scrolling has been disabled by -X (disable screen clearing).
# - Remove -X and -F (exit if the content fits on one screen) to enable it.
#
#
# Don't add -S to enable wrap
LESS = "-F -g -i -M -R -w -X -z-4";

Expand Down
27 changes: 16 additions & 11 deletions home-manager/darwin.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
pkgs,
edge-pkgs,
homemade-pkgs,
# Don't depend on edge-pkgs as possible until realize https://github.com/NixOS/nixpkgs/issues/107466,
lib,
config,
...
Expand All @@ -11,9 +10,11 @@
lib.mkMerge [
(lib.mkIf pkgs.stdenv.isDarwin {
home = {
homeDirectory = "/Users/${config.home.username}";

sessionVariables = {
# * Do not specify Nix store path for zed and vscode in macOS
# * zed is broken https://github.com/NixOS/nixpkgs/blob/bba8dffd3135f35810e9112c40ee621f4ede7cca/pkgs/by-name/ze/zed-editor/package.nix#L217-L219
# * zed is fixed in https://github.com/NixOS/nixpkgs/pull/329653, however https://github.com/NixOS/nixpkgs/issues/107466 and GH-754 is the blocker with the build-time
# * vscode is unfree and heavy when no binary cache
# * `cli: install` action installs into this path in macOS
VISUAL = "code --wait";
Expand All @@ -28,6 +29,11 @@ lib.mkMerge [
];

packages = with pkgs; [
# for lima. However don't add lima in this dependencies.
# It should be installed without nix.
# See https://github.com/kachick/dotfiles/issues/146#issuecomment-2453430154
qemu

# https://github.com/NixOS/nixpkgs/issues/240819
pinentry_mac

Expand All @@ -49,17 +55,16 @@ lib.mkMerge [

source-han-code-jp # Includes many definitions, useful for fallback
inconsolata

# Don't add zed in macOS with nixpkgs
# https://github.com/NixOS/nixpkgs/blob/bba8dffd3135f35810e9112c40ee621f4ede7cca/pkgs/by-name/ze/zed-editor/package.nix#L217-L219
# edge-pkgs.zed-editor

edge-pkgs.podman-desktop # Useable since https://github.com/NixOS/nixpkgs/pull/343648

homemade-pkgs.maccy
];
};

programs.ssh.includes = [
# * lima does not support XDG spec. https://github.com/lima-vm/lima/discussions/2745#discussioncomment-10958677
# * adding this as `ssh -F` makes it possible to use ssh login, it is required for `ms-vscode-remote.remote-ssh`
# * the content of file will be changed for each instance creation
"${config.home.homeDirectory}/.lima/default/ssh.config"
];

xdg = {
configFile = {
"karabiner/assets" = {
Expand Down
6 changes: 6 additions & 0 deletions home-manager/lima.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ config, ... }:

{
# https://github.com/lima-vm/lima/blame/0d058b0eaa2d1bafc867298503a9239e89c202a8/templates/default.yaml#L295-L296
home.homeDirectory = "/home/${config.home.username}.linux";
}
42 changes: 28 additions & 14 deletions home-manager/linux.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
config,
pkgs,
lib,
edge-pkgs,
Expand All @@ -13,25 +14,38 @@ lib.mkMerge [
# https://github.com/nix-community/home-manager/blob/559856748982588a9eda6bfb668450ebcf006ccd/modules/targets/generic-linux.nix#L16
targets.genericLinux.enable = true;

home.packages = with pkgs; [
# Fix missing locales as `locale: Cannot set LC_CTYPE to default locale`
glibc
home = {
homeDirectory = lib.mkDefault "/home/${config.home.username}";

# https://github.com/nix-community/home-manager/blob/a8f8f48320c64bd4e3a266a850bbfde2c6fe3a04/modules/services/ssh-agent.nix#L37
openssh
packages = with pkgs; [
# Fix missing locales as `locale: Cannot set LC_CTYPE to default locale`
glibc

iputils # `ping` etc
# https://github.com/nix-community/home-manager/blob/a8f8f48320c64bd4e3a266a850bbfde2c6fe3a04/modules/services/ssh-agent.nix#L37
openssh

# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/by-name/iw/iw/package.nix
edge-pkgs.iw # replacement of wireless-tools(iwconfig)
iputils # `ping` etc

# Alt w3m
# Do not install in dawin yet: https://github.com/NixOS/nixpkgs/blob/b4b293ec6c61e846d69224ea0637411283e2ad39/pkgs/by-name/ch/chawan/package.nix#L82
# Keybindigs: https://git.sr.ht/~bptato/chawan/tree/master/item/res/config.toml
chawan # `cha`
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/by-name/iw/iw/package.nix
edge-pkgs.iw # replacement of wireless-tools(iwconfig)

homemade-pkgs.renmark # Depend on chawan
];
# - Enable special module for Nix OS.
# - Linux package does not contain podman-remote, you should install uidmap with apt and use this podman as actual engine
# https://github.com/NixOS/nixpkgs/blob/194846768975b7ad2c4988bdb82572c00222c0d7/pkgs/applications/virtualization/podman/default.nix#L112-L116
podman
podman-tui
docker-compose

edge-pkgs.jnv # interactive jq - Use unstable because it is a fresh tool

# Alt w3m
# Do not install in dawin yet: https://github.com/NixOS/nixpkgs/blob/b4b293ec6c61e846d69224ea0637411283e2ad39/pkgs/by-name/ch/chawan/package.nix#L82
# Keybindigs: https://git.sr.ht/~bptato/chawan/tree/master/item/res/config.toml
chawan # `cha`

homemade-pkgs.renmark # Depend on chawan
];
};

# xdg-user-dirs NixOS module does not work or is not enough for me to keep English dirs even in Japanese locale.
# Check your `~/.config/user-dirs.dirs` if you faced any trouble
Expand Down
10 changes: 1 addition & 9 deletions home-manager/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
dig # Alt and raw-data oriented nslookup. TODO: Consider another candidate: dug - https://eng-blog.iij.ad.jp/archives/27527

git
gh
# gh # Don't add gh here. Only use home-manager gh module to avoid https://github.com/cli/cli/pull/5378
ghq

edge-pkgs.sequoia-sq # Alt `gpg` - nixos-24.05 does not backport recent versions and the older requires to rebuild. https://github.com/NixOS/nixpkgs/pull/331099
Expand All @@ -66,7 +66,6 @@
curl
wget
jq
edge-pkgs.jnv # interactive jq - Use unstable because it is a fresh tool
ripgrep # `rg`
bat # alt cat
mdcat # pipe friendly markdown viewer rather than glow
Expand Down Expand Up @@ -100,13 +99,6 @@
# darwin: system_profiler SPFontsDataType
fontconfig # `fc-list`, `fc-cache`

# - Enable special module for Nix OS.
# - Linux package does not contain podman-remote, you should install uidmap with apt and use this podman as actual engine
# https://github.com/NixOS/nixpkgs/blob/194846768975b7ad2c4988bdb82572c00222c0d7/pkgs/applications/virtualization/podman/default.nix#L112-L116
podman
podman-tui
docker-compose

# `tldr` rust client, tealdeer is another candidate.
tlrc

Expand Down
1 change: 0 additions & 1 deletion pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

beedii = pkgs.callPackage ./beedii { };
cozette = pkgs.callPackage ./cozette { };
maccy = pkgs.callPackage ./maccy { };

posix_shared_functions = pkgs.callPackage ./posix_shared_functions { };

Expand Down
47 changes: 0 additions & 47 deletions pkgs/maccy/default.nix

This file was deleted.

0 comments on commit 9551003

Please sign in to comment.