-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
126 lines (107 loc) · 3.61 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
{
description = "Home Manager configuration of bryan";
inputs = {
/**
_private_ machine profiles
_not_ secret, might leak through /nix/store & cache!
machines = home-attrs.outputs = {
id = {
## machine's "profile"
system = ... ; ## required, for `nixpkgs.system`
username = ... ; ## required, for `home.username`
homeDirectory = ... ; ## optional, defaults to "/home/${username}"
hostname = ... ; ## optional, defaults to `id`
};
}
*/
home-attrs.url = "git+ssh://git@github.com/bryango/attrs.git";
/* cachix update:
nix eval --raw cheznix#cheznix.inputs.home-attrs.outPath \
| cachix push chezbryan
*/
## p13n nixpkgs with config
nixpkgs-config.url = "git+file:./nixpkgs-config";
system-manager = {
url = "github:numtide/system-manager";
inputs.nixpkgs.follows = "nixpkgs-config/nixpkgs";
};
};
outputs = { self, home-attrs, system-manager, ... }:
let
## consistent namings
nixpkgs-follows =
let
result = "nixpkgs-config";
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
assert lock.nodes.${result}.original.url == "file:./${result}";
result;
/* ^ refers to both the input _name_ & its _source_,
.. therefore these two must coincide! */
cheznix = self;
nixpkgs = self.inputs.${nixpkgs-follows};
inherit (nixpkgs) lib;
## upstream overrides: inputs.${nixpkgs-follows}
## home overlay:
overlay = final: prev: import ./overlay.nix final prev // (with final; {
inherit cheznix;
inherit (system-manager.packages.${system}) system-manager;
});
machines = home-attrs.outputs;
forMyMachines = f: lib.mapAttrs' f machines;
inherit (lib)
mySystems
forMySystems;
mkSystemPkgs = system: nixpkgs.legacyPackages.${system}.extend overlay;
updateHomeAttrs = id: profile:
profile // {
hostname = profile.hostname or id;
pkgs =
assert lib.elem profile.system mySystems;
mkSystemPkgs profile.system;
};
mkHomeConfig = id: profile:
let
attrs = updateHomeAttrs id profile;
home-manager = attrs.pkgs.home-manager.flake;
in
{
name = "${attrs.username}@${attrs.hostname}";
value = home-manager.lib.homeManagerConfiguration {
inherit (attrs) pkgs;
## specify your home configuration modules
modules = [ ./home.nix ];
## pass through arguments to home.nix
extraSpecialArgs = {
inherit attrs cheznix nixpkgs-follows;
};
};
};
mkSystemConfig = id: profile:
let
attrs = updateHomeAttrs id profile;
in
{
name = "${attrs.hostname}";
value = system-manager.lib.makeSystemConfig {
modules = [ ./system-modules ];
extraSpecialArgs = {
inherit attrs cheznix nixpkgs-follows;
inherit (attrs) pkgs;
## ^ add overlaid nixpkgs
## ^ override github:numtide/system-manager/main/nix/lib.nix
};
};
};
in
{
inherit lib;
homeConfigurations = forMyMachines mkHomeConfig;
systemConfigs = forMyMachines mkSystemConfig;
legacyPackages = forMySystems mkSystemPkgs;
packages = forMySystems (system: {
default = self.legacyPackages.${system}.home-manager;
});
overlays.default = overlay;
};
}