forked from hlissner/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
141 lines (122 loc) · 4.25 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
139
140
141
# flake.nix --- the heart of my dotfiles
#
# Author: Nopanun Laochunhanun <[email protected]> github.com/thaenalpha/dotfiles
# Acknowledgements: Henrik Lissner, Seong Yong-ju
# URLs: (gh hlissner/dotfiles sei40kr/dotfiles)
# License: MIT
#
# Welcome to ground zero. Where the whole flake gets set up and all its modules
# are loaded.
{
description = "A grossly incandescent nixos config.";
inputs =
{
# Core dependencies.
nixpkgs.url = "nixpkgs/nixos-unstable"; # primary nixpkgs
nixpkgs-unstable.url = "nixpkgs/master"; # for packages on the edge
darwin = {
url = "github:LnL7/nix-darwin/master";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager.url = "github:nix-community/home-manager/master";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
agenix.url = "github:ryantm/agenix";
agenix.inputs.nixpkgs.follows = "nixpkgs";
# Extras
emacs-overlay.url = "github:nix-community/emacs-overlay";
nixos-hardware.url = "github:nixos/nixos-hardware";
};
outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, darwin, ... }:
let
inherit (builtins) removeAttrs;
inherit (lib) attrValues elem genAttrs hasSuffix mkDefault nixosSystem
optionalAttrs removeSuffix;
inherit (darwin.lib) darwinSystem;
inherit (lib.my) mapModules mapModulesRec mapModulesRec';
lib = nixpkgs.lib.extend (lib: _: {
my = import ./lib { inherit inputs lib; };
});
systems = [ "aarch64-darwin" "x86_64-linux" ];
mkPkgs = pkgs: extraOverlays: system: import pkgs {
inherit system;
config.allowUnfree = true; # forgive me Stallman senpai
overlays = extraOverlays ++ (attrValues self.overlays);
};
pkgs = genAttrs systems (mkPkgs nixpkgs [ self.overlay ]);
pkgs' = genAttrs systems (mkPkgs nixpkgs-unstable []);
isLinux = hasSuffix "-linux";
isDarwin = hasSuffix "-darwin";
mkHost = path:
let
hostCfg = (import path) { inherit inputs lib pkgs'; };
inherit (hostCfg) system;
specialArgs = {
inherit inputs lib;
pkgs = pkgs.${system};
};
modules = [
{
networking.hostName = mkDefault
(removeSuffix ".nix" (baseNameOf path));
}
./modules
(removeAttrs hostCfg [ "system" "stateVersion" ])
];
in
if isLinux system then
(nixosSystem {
inherit system specialArgs;
modules = modules ++ [
{
system = { inherit (hostCfg) stateVersion; };
home-manager.users.${hostCfg.user.name}.home = {
inherit (hostCfg) stateVersion;
};
}
nixos/modules
];
})
else if isDarwin system then
(darwinSystem {
inherit specialArgs;
modules = modules ++ [
{
home-manager.users.${hostCfg.user.name}.home = {
inherit (hostCfg) stateVersion;
};
}
darwin/modules
];
})
else abort "[mkHost] Unknown system architecture: ${system}";
in
{
lib = lib.my;
overlay = _: { system, ... }:
{ unstable = pkgs'.${system}; my = self.packages.${system}; };
overlays = mapModules ./overlays import;
packages = genAttrs systems (system: import ./packages {
pkgs = pkgs.${system};
});
nixosModules = mapModulesRec ./modules import
// (mapModulesRec nixos/modules import);
nixosConfigurations = mapModules nixos/hosts mkHost;
darwinModules = mapModulesRec ./modules import
// (mapModulesRec darwin/modules import);
darwinConfigurations = mapModules darwin/hosts mkHost;
devShells = genAttrs systems (system: import ./shell.nix {
pkgs = pkgs.${system};
});
templates = {
full = {
path = ./.;
description = "A grossly incandescent nixos config";
};
} // import ./templates;
defaultTemplate = self.templates.full;
defaultApp.x86_64-linux = {
type = "app";
program = bin/hey;
};
};
}