-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
138 lines (131 loc) · 3.8 KB
/
flake.nix
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 = "dotfiles of nokazn";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
# In nixpkgs-unstale all packages are built for supported platforms including darwin
# https://discourse.nixos.org/t/differences-between-nix-channels/13998/5
nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nix-darwin = {
url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs-darwin";
};
home-manager = {
url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
devshell.url = "github:numtide/devshell";
};
outputs =
{ nixpkgs
, nixpkgs-darwin
, nix-darwin
, home-manager
, flake-utils
, ...
}:
let
USER = "runner";
# this line is replaced by the real user name as fallback
user = {
# this line is replaced by the real user name as fallback
name = "${USER}";
};
# whether username is the one in GitHub Actions
isCi = user.name == "runner";
# this line is replaced by the real user name as fallback
HOST = "${HOST}";
nix = {
version = "24.05";
};
homeManagerConfigurations = (home: {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users = { ${user.name} = home; };
};
});
in
{
# For user environments
# - home-manager switch .#${USER}
# - home-manager switch .#${USER}-wsl
# For GitHub Actions
# - home-manager switch .#runner
# - home-manager switch .#runner-wsl
homeConfigurations =
let
generateConfiguration = ({ isWsl }:
{
name = user.name + (if isWsl then "-wsl" else "");
value = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [
./home/linux.nix
];
extraSpecialArgs = { inherit nix; meta = { inherit user isWsl isCi; }; };
};
}
);
in
nixpkgs.lib.listToAttrs
(builtins.map generateConfiguration [
{ isWsl = true; }
{ isWsl = false; }
]);
# For darwin
# - darwin-rebuild switch .#${system}-$(USER)
# For GitHub Actions
# - darwin-rebuild switch .#${system}-runner
darwinConfigurations =
let
system = "aarch64-darwin";
meta = {
inherit user isCi;
isWsl = false;
};
in
{
${HOST} = nix-darwin.lib.darwinSystem rec {
inherit system;
pkgs = nixpkgs-darwin.legacyPackages.${system};
modules = [
./hosts/darwin
home-manager.darwinModules.home-manager
(homeManagerConfigurations (import ./home/darwin.nix {
inherit pkgs nix meta;
lib = pkgs.lib;
}))
];
specialArgs = { inherit nix meta; };
};
};
} // (flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
devShells.default = pkgs.mkShell
{
buildInputs = with pkgs; [
gnumake
shellcheck
shfmt
nixfmt-rfc-style
yamlfmt
dprint
pre-commit
treefmt
];
};
}));
nixConfig = {
experimental-features = [ "nix-command" "flakes" ];
# https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-auto-optimise-store
auto-optimise-store = true;
eval-cache = true;
};
}