-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
66 lines (60 loc) · 2.33 KB
/
flake.nix
File metadata and controls
66 lines (60 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{
description = "Nix for macOS configuration";
##################################################################################################################
#
# Want to know Nix in details? Looking for a beginner-friendly tutorial?
# Check out https://github.com/ryan4yin/nixos-and-flakes-book !
#
##################################################################################################################
# the nixConfig here only affects the flake itself, not the system configuration!
nixConfig = {
substituters = [
# Query the mirror of USTC first, and then the official cache.
# "https://mirrors.ustc.edu.cn/nix-channels/store"
"https://cache.nixos.org"
];
};
# This is the standard format for flake.nix. `inputs` are the dependencies of the flake,
# Each item in `inputs` will be passed as a parameter to the `outputs` function after being pulled and built.
inputs = {
nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-unstable";
darwin = {
url = "github:nix-darwin/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs-darwin";
};
};
# The `outputs` function will return all the build results of the flake.
# A flake can have many use cases and different types of outputs,
# parameters in `outputs` are defined in `inputs` and can be referenced by their names.
# However, `self` is an exception, this special parameter points to the `outputs` itself (self-reference)
# The `@` syntax here is used to alias the attribute set of the inputs's parameter, making it convenient to use inside the function.
outputs = inputs @ {
self,
nixpkgs,
darwin,
...
}: let
username = "aldo";
system = "aarch64-darwin"; # aarch64-darwin or x86_64-darwin
# Helper function to create host configuration
mkHost = hostname: darwin.lib.darwinSystem {
inherit system;
specialArgs = inputs // {
inherit username hostname;
};
modules = [
./modules/nix-core.nix
./modules/system.nix
./modules/apps.nix
./modules/host-users.nix
];
};
in {
# Mac Mini configuration
darwinConfigurations.min = mkHost "min";
# MacBook configuration
darwinConfigurations.book = mkHost "book";
# nix code formatter
formatter.${system} = nixpkgs.legacyPackages.${system}.alejandra;
};
}