Skip to content

Commit

Permalink
WIP nix-darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Oct 2, 2024
1 parent 3efaae8 commit 312cafd
Show file tree
Hide file tree
Showing 14 changed files with 295 additions and 177 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- main
- update_flake_lock_action
- nix-darwin
pull_request:
jobs:
nix:
Expand All @@ -20,4 +21,4 @@ jobs:
run: om ci --extra-access-tokens "github.com=${{ secrets.GITHUB_TOKEN }}" run --systems "${{ matrix.system }}"
- name: activate-test
if: matrix.system == 'x86_64-linux'
run: nix run .#test
run: nix run .#test-home-manager-config
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,23 @@ NOTE: These instructions do not apply if you use [NixOS](https://nixos.asia/en/n
```sh-session
mkdir ~/nixconfig && cd ~/nixconfig
nix --accept-flake-config run github:juspay/omnix -- \
init github:juspay/nix-dev-home -o .
init github:juspay/nix-dev-home/nix-darwin -o .
```
<img width="587" alt="image" src="https://github.com/user-attachments/assets/2c0d514e-2284-4b92-9b5b-036b1e4393b0">

- Optionally, you may edit `./modules/home/*.nix` to your liking.
1. Run `nix run`[^home-modify] to activate your configuration.
1. Run `nix run` (or the appropriate command printed by the above command) to activate your configuration.
- Does this fail to run? See the [Troubleshooting](#troubleshooting) section below.
1. Restart your terminal.

After steps 1-4, you should expect to see the [starship](https://starship.rs/) prompt:

<img width="236" alt="image" src="https://github.com/user-attachments/assets/bea3a7e5-b06a-483f-b76b-5c3865ce5e55">

Anytime you modify your home configuration in `./modules/home/*.nix`, re-run `nix run` to activate the new configuration.
Anytime you modify your configuration in `./modules/*/*.nix`, re-run `nix run` to activate the new configuration.

[^omnix]: We use [omnix](https://omnix.page/om/init.html) to initialize this repository template.

[^home-modify]: Executing this step will modify the contents of your `$HOME` directory. You will be [warned before overwriting](https://nix-community.github.io/home-manager/index.html#sec-usage-dotfiles), but not before creating links to newly created configuration files in the nix store. Since home-manager does not currently provide an integrated and automated feature to eliminate the links it creates, be aware that if you would like to reverse this operation, you will need to curate your home directory manually.

## Details

The configuration repo has `flake.nix` file in the current directory and some `./modules/home/*.nix` files containing the home-manager configuration that you can review. It also has a [justfile](https://github.com/casey/just), which provides a set of recipes analogous to Make targets to interact with the nix flake.
Expand Down
29 changes: 29 additions & 0 deletions configurations/darwin/example.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# See /modules/darwin/* for actual settings
# This file is just *top-level* configuration.
{ flake, ... }:

let
inherit (flake) inputs;
inherit (inputs) self;
in
{
imports = [
self.darwinModules.default
];

nixpkgs.hostPlatform = "aarch64-darwin";
networking.hostName = "example";

# For home-manager to work.
# https://github.com/nix-community/home-manager/issues/4026#issuecomment-1565487545
users.users."runner".home = "/Users/runner";

# Enable home-manager for "runner" user
home-manager.users."runner" = {
imports = [ (self + /configurations/home/runner.nix) ];
};

# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 4;
}
54 changes: 28 additions & 26 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
inputs = {
# Principle inputs (updated by `nix run .#update`)
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nix-darwin.url = "github:LnL7/nix-darwin";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts";
Expand All @@ -15,6 +17,7 @@
nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
nixvim.url = "github:nix-community/nixvim";
nixvim.inputs.nixpkgs.follows = "nixpkgs";
nixvim.inputs.flake-parts.follows = "flake-parts";
};

outputs = inputs:
Expand Down
4 changes: 0 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ check:
dev:
{{NIX}} develop

# Build nix flake
build: lint check
{{NIX}} build

# Remove build output link (no garbage collection)
clean:
rm -f ./result
Expand Down
44 changes: 44 additions & 0 deletions modules/darwin/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This is your nix-darwin configuration.
# For home configuration, see /modules/home/*
{ flake, pkgs, lib, ... }:

let
inherit (flake) inputs;
inherit (inputs) self;
in
{
# Use TouchID for `sudo` authentication
security.pam.enableSudoTouchIdAuth = true;

# These users can add Nix caches.
nix.settings.trusted-users = [ "root" "runner" ];

# Configure macOS system
# More examples => https://github.com/ryan4yin/nix-darwin-kickstarter/blob/main/rich-demo/modules/system.nix
system = {
defaults = {
dock = {
# autohide = true;
# customize Hot Corners
wvous-tl-corner = 2; # top-left - Mission Control
# wvous-tr-corner = 13; # top-right - Lock Screen
wvous-bl-corner = 3; # bottom-left - Application Windows
wvous-br-corner = 4; # bottom-right - Desktop
};

finder = {
_FXShowPosixPathInTitle = true; # show full path in finder title
AppleShowAllExtensions = true; # show all file extensions
FXEnableExtensionChangeWarning = false; # disable warning when changing file extension
QuitMenuItem = true; # enable quit menu item
ShowPathbar = true; # show path bar
ShowStatusBar = true; # show status bar
};
};

keyboard = {
# enableKeyMapping = true;
# remapCapsLockToControl = true;
};
};
}
15 changes: 15 additions & 0 deletions modules/flake-parts/activate-home.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
perSystem = { self', pkgs, lib, ... }: {
# Enables 'nix run' to activate home-manager config.
apps.default = {
inherit (self'.packages.activate) meta;
program = pkgs.writeShellApplication {
name = "activate-home";
text = ''
set -x
${lib.getExe self'.packages.activate} "$USER"@
'';
};
};
};
}
Loading

0 comments on commit 312cafd

Please sign in to comment.