-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
138 lines (123 loc) · 3.81 KB
/
flake.nix
File metadata and controls
138 lines (123 loc) · 3.81 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
{
description = "🗿";
# the nixConfig here only affects the flake itself, not the system configuration!
nixConfig = {
substituters = [
# high priority since it's almost always used
"https://cache.nixos.org?priority=10"
];
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
];
};
# 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,
home-manager,
nix-index-database,
...
}: let
# TODO: replace with your own username, system and hostname
username = "shaurya";
system = "aarch64-darwin"; # aarch64-darwin or x86_64-darwin
hostname = "asuna";
specialArgs =
inputs
// {
inherit username hostname;
};
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forEachSupportedSystem = f:
inputs.nixpkgs.lib.genAttrs supportedSystems (
system:
f {
pkgs = import inputs.nixpkgs {inherit system;};
inherit system;
}
);
in {
darwinConfigurations."${hostname}" = darwin.lib.darwinSystem {
inherit system specialArgs;
modules = [
./modules/nix-core.nix
./modules/system.nix
./modules/apps.nix
./modules/host-users.nix
./modules/services.nix
nix-index-database.darwinModules.nix-index
home-manager.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = specialArgs;
home-manager.users.${username} = import ./home;
}
];
};
checks = forEachSupportedSystem ({
system,
pkgs,
}: {
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
alejandra.enable = true;
};
};
});
devShells = forEachSupportedSystem (
{
system,
pkgs,
}: {
default = pkgs.mkShell {
packages = [
pkgs.alejandra
pkgs.nixd
];
inherit (self.checks.${system}.pre-commit-check) shellHook;
buildInputs = self.checks.${system}.pre-commit-check.enabledPackages;
name = "dots";
DIRENV_LOG_FORMAT = "";
};
}
);
# nix code formatter
formatter.${system} = nixpkgs.legacyPackages.${system}.alejandra;
};
# 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 = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz"; # not darwin but still being on the edge
darwin = {
url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs-darwin";
};
# home-manager, used for managing user configuration
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs-darwin";
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs = {
nixpkgs.follows = "nixpkgs-darwin";
};
};
nix-index-database = {
url = "github:nix-community/nix-index-database";
inputs.nixpkgs.follows = "nixpkgs-darwin";
};
};
}