-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
193 lines (178 loc) · 7.99 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
{
description = "NixOS configuration";
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-24.05;
unstable.url = github:NixOS/nixpkgs/nixos-24.05;
#unstable.url = github:NixOS/nixpkgs/nixos-unstable;
nix.url = github:NixOS/nix;
home-manager.url = github:rycee/home-manager/release-24.05;
home-manager.inputs.nixpkgs.follows = "nixpkgs";
nixos-hardware.url = github:NixOS/nixos-hardware;
nofib.url = git+https://gitlab.haskell.org/ghc/nofib?ref=wip/input-utf8;
nofib.flake = false;
nix-doom-emacs.url = "github:nix-community/nix-doom-emacs";
};
# Taken from https://github.com/davidtwco/veritas/blob/master/flake.nix
outputs = { self, ... }@inputs:
with inputs.nixpkgs.lib;
let
username = "sgraf";
forEachSystem = genAttrs [ "x86_64-linux" ];
pkgsBySystem = forEachSystem (system:
import inputs.nixpkgs {
inherit system;
config = import ./nixpkgs/config.nix;
# Overlays consumed by the home-manager/NixOS configuration.
overlays = [
(import ./nixpkgs/overlays/kak-git-mode.nix)
(import ./nixpkgs/overlays/kak-lsp.nix)
(import ./nixpkgs/overlays/nofib-analyse.nix inputs.nofib)
];
}
);
unstableBySystem = forEachSystem (system:
import inputs.unstable {
inherit system;
config = import ./nixpkgs/config.nix;
}
);
# mkHomeManagerConfiguration could just be
# nameValuePair hostname config
# But the nix/registry.json settings need access to inputs.
# Since the other stuff belongs with those settings, it makes
# sense to have this function. Although we could have solved this through passing inputs as extraSpecialArgs.
mkHomeManagerConfiguration = hostname: { system, config }:
nameValuePair hostname ({ ... }: {
imports = [
inputs.nix-doom-emacs.hmModule
(import config)
];
# Use the same Nix configuration throughout the system.
# We really need to set ~/.config/nixpkgs/config.nix as well as import
# it in home-manager's nixpkgs.config; see the manpage.
xdg.configFile."nixpkgs/config.nix".source = ./nixpkgs/config.nix;
nixpkgs.config = import ./nixpkgs/config.nix;
xdg.configFile."nix/nix.conf".source = ./nix/nix.conf;
# Re-expose self, nixpkgs and unsable as flakes. For use in nix-search, for example
nix = {
#settings = {
# experimental-features = [ "nix-command" "flakes" ];
#};
# Re-expose self, nixpkgs and unstable as flakes.
registry = {
self.flake = inputs.self;
nixpkgs = {
from = { id = "nixpkgs"; type = "indirect"; };
flake = inputs.nixpkgs;
};
unstable = {
from = { id = "unstable"; type = "indirect"; };
flake = inputs.unstable;
};
};
};
});
mkNixOsConfiguration = hostname: { system, config }:
nameValuePair hostname (nixosSystem {
inherit system;
modules = [
({ inputs, hostname, pkgs, ... }: {
# Set the hostname to the name of the configuration being applied (since the
# configuration being applied is determined by the hostname).
networking.hostName = hostname;
# Use the nixpkgs from the flake.
nixpkgs.pkgs = pkgsBySystem.${system};
# For compatibility with nix-shell, nix-build, etc.
# See also the setting of NIX_PATH in the home-manager host config
environment.etc.nixpkgs.source = inputs.nixpkgs;
environment.etc.unstable.source = inputs.unstable;
nix.nixPath = [ "nixpkgs=/etc/nixpkgs" "unstable=/etc/unstable" ];
nix = {
# Don't rely on the configuration to enable a flake-compatible version of Nix.
# package = pkgs.nixFlakes;
extraOptions = "experimental-features = nix-command flakes";
# Re-expose self, nixpkgs and unstable as flakes.
registry = {
self.flake = inputs.self;
nixpkgs = {
from = { id = "nixpkgs"; type = "indirect"; };
flake = inputs.nixpkgs;
};
unstable = {
from = { id = "unstable"; type = "indirect"; };
flake = inputs.unstable;
};
};
settings = {
auto-optimise-store = true;
};
};
})
(import config)
inputs.home-manager.nixosModules.home-manager
{
home-manager.useUserPackages = true;
home-manager.useGlobalPkgs = true;
home-manager.users.${username} = homeManagerConfigurations."${hostname}";
home-manager.extraSpecialArgs = {
inherit hostname inputs;
unstable = unstableBySystem."${system}";
};
}
];
specialArgs = {
inherit hostname inputs;
unstable = unstableBySystem."${system}";
};
});
mkHomeManagerHostConfiguration = hostname: { system, username }: # The original template is much more flexible here
# home-manager switch --flake tries `<flake-uri>#homeConfigurations."${username}@${hostname}"`
nameValuePair "${username}@${hostname}" (inputs.home-manager.lib.homeManagerConfiguration {
pkgs = pkgsBySystem."${system}";
modules = [
homeManagerConfigurations."${hostname}"
({ ... }: {
# Only username/hostname dependent configuration here
home = {
homeDirectory = "/home/${username}";
username = "${username}";
};
# For compatibility with nix-shell, nix-build, etc.
# See also the setting of NIX_PATH in the NixOS host config
home.file.".nixpkgs/stable".source = inputs.nixpkgs;
home.file.".nixpkgs/unstable".source = inputs.unstable;
systemd.user.sessionVariables."NIX_PATH" =
mkForce "nixpkgs=$HOME/.nixpkgs/stable:unstable=$HOME/.nixpkgs/unstable\${NIX_PATH:+:}$NIX_PATH";
})
];
extraSpecialArgs = {
inherit hostname inputs;
unstable = unstableBySystem."${system}";
kitty-fix = import inputs.kitty-fix {inherit system;};
};
});
# Attribute set of hostnames to home-manager modules with the entire configuration for
# that host - consumed by the home-manager NixOS module for that host (if it exists)
# or by `mkHomeManagerHostConfiguration` for home-manager-only hosts.
homeManagerConfigurations = mapAttrs' mkHomeManagerConfiguration {
nixos-framework = { system = "x86_64-linux"; config = ./home/private.nix; };
nixos-lt = { system = "x86_64-linux"; config = ./home/private.nix; };
chonk = { system = "x86_64-linux"; config = ./home/work.nix; };
Sebastian-PC = { system = "x86_64-linux"; config = ./home/pengwin.nix; };
};
homeManagerHostConfigurations = mapAttrs' mkHomeManagerHostConfiguration {
chonk = { system = "x86_64-linux"; username = "sg"; };
Sebastian-PC = { system = "x86_64-linux"; username = "sgraf"; };
};
# Attribute set of hostnames to evaluated NixOS configurations. Consumed by `nixos-rebuild`
# on those hosts.
nixosHostConfigurations = mapAttrs' mkNixOsConfiguration {
nixos-framework = { system = "x86_64-linux"; config = ./nixos/framework.nix; };
nixos-lt = { system = "x86_64-linux"; config = ./nixos/lt.nix; };
};
in
{
homeConfigurations = homeManagerHostConfigurations;
nixosConfigurations = nixosHostConfigurations;
};
}