-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
128 lines (112 loc) · 4.02 KB
/
Copy pathflake.nix
File metadata and controls
128 lines (112 loc) · 4.02 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
{
description = "My NixOS configuration flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
# nix profile install nixpkgs/nixpkgs-unstable#packagename
# TODO: Also add overlays to this and make them available
# like the overlayed nixpks
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
nixos-hardware.url = "github:NixOS/nixos-hardware";
home-manager = {
url = "github:nix-community/home-manager/release-26.05";
inputs.nixpkgs.follows = "nixpkgs";
};
alejandra-fork = {
url = "github:maxdexh/alejandra";
flake = false;
};
};
outputs = inputs: let
lib = inputs.nixpkgs.lib;
# TODO: Try to make nixd give completions for the module system?
module_system = lib.evalModules {
modules = [
./hosts
./options
./modules
./overlays
];
specialArgs = {
inherit inputs;
};
};
# TODO: host-dependent overlays, perhaps by moving them or the hosts to different flake(s)?
full_config = module_system.config;
overlays_attrset = full_config.overlays;
pkgs_by_system = lib.pipe hosts [
(builtins.groupBy (host: host.system))
(builtins.mapAttrs (system: _: import inputs.nixpkgs {
inherit system;
overlays = builtins.attrValues overlays_attrset;
config = {
allowUnfree = true;
};
}))
];
# Some attributes for host._internals that are only available in this flake
# (specialArgs gets the original host attrset)
host_flake_internals = host: let
pkgs = pkgs_by_system.${host.system};
path_prefix = "${inputs.self}/";
mkNixConfigSymlink = path: let
# Turn /nix/store/<hash>-<basename> into ${source-store}/actual/path/to/<basename>
# Could also be done without the builtin by traversing backwards using
# `+ "/.."` and using `baseNameOf` to get each path segment.
abs = builtins.unsafeDiscardStringContext (toString path);
rel = assert lib.hasPrefix path_prefix abs; lib.removePrefix path_prefix abs;
in "${nixConfigSymlink}/${rel}";
nixConfigSymlink = pkgs.cfgUtils.mkSymlink host.nixConfigLocation;
in {
inherit pkgs;
specialArgs = {
inherit inputs;
unstable = inputs.nixpkgs-unstable.legacyPackages.${host.system};
host = host // {inherit nixConfigSymlink mkNixConfigSymlink;};
};
};
hosts = map (host: host // {_internals = host_flake_internals host;}) (builtins.attrValues full_config.hosts);
nixos_system = host: lib.nixosSystem {
pkgs = host._internals.pkgs;
modules = [
host.nixos.module
{
home-manager = {
useGlobalPkgs = true; # Also inherits nixpkgs configs
verbose = true;
extraSpecialArgs = host._internals.specialArgs;
};
}
inputs.home-manager.nixosModules.home-manager
];
specialArgs = host._internals.specialArgs;
};
standalone_hm_config = host: user: inputs.home-manager.lib.homeManagerConfiguration {
pkgs = pkgs_by_system.${host.system};
extraSpecialArgs = host._internals.specialArgs;
modules = [user.hm.module];
};
in {
# TODO: expose devShells, if this can be made to work with flake-compat
nixosConfigurations = lib.pipe hosts [
(builtins.filter (host: host.nixos.enable))
(map (host: {
name = host.name;
value = nixos_system host;
}))
builtins.listToAttrs
];
homeConfigurations = lib.pipe hosts [
(builtins.concatMap (host: map (user: {
name = "${user.username}@${host.name}";
value = standalone_hm_config host user;
}) (builtins.attrValues host.users)))
builtins.listToAttrs
];
# This allows using the nix config location as a replacement for nixpkgs,
# but with overlays applied.
# See also: ./modules/nix-meta/nixpkgs-override.nix
packages = pkgs_by_system;
# For `import <nixpkgs>`. See ./default.nix
overlays = overlays_attrset;
};
}