-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflake.nix
175 lines (153 loc) · 5.49 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
{
description = "jtojnar’s machines";
inputs = {
agenix = {
url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "nixpkgs";
# HACK: Prevent adding a nix-darwin copy.
inputs.darwin.follows = "nixpkgs";
inputs.home-manager.follows = "home-manager";
};
# Shim to make flake.nix work with stable Nix.
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
home-manager = {
url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs =
{
self,
agenix,
home-manager,
nixpkgs,
...
}@inputs:
let
inherit (nixpkgs) lib;
# Flakes require ‘packages’ attribute to contain per-platform attrsets.
# Here we explicitly define all the platforms that will be exposed.
platforms = [
"x86_64-linux"
"aarch64-linux"
];
forAllPlatforms = f: lib.genAttrs platforms (platform: f platform);
# Generate an attribute set by mapping a function over a list of values.
genAttrs' = values: f: builtins.listToAttrs (map f values);
# Convert a list to file paths to attribute set
# that has the filenames stripped of nix extension as keys
# and original path as value.
pathsToAttrs =
paths:
genAttrs' paths (path: {
name = lib.removeSuffix ".nix" (
builtins.baseNameOf (lib.removeSuffix "/default.nix" (builtins.toString path))
);
value = path;
});
# Convert a list to file paths to attribute set
# that has the filenames stripped of nix extension as keys
# and imported content of the file as value.
pathsToImportedAttrs = paths: lib.mapAttrs (_k: path: import path) (pathsToAttrs paths);
# Create combined package set from nixpkgs and our overlays.
mkPkgs =
platform:
let
libVersionInfoOverlay = import "${nixpkgs}/lib/flake-version-info.nix" nixpkgs;
in
import nixpkgs {
system = platform;
overlays = builtins.attrValues self.overlays ++ [
(final: prev: {
home-manager = prev.callPackage "${home-manager}/home-manager" { };
# Ensure version info is properly populated.
lib = prev.lib.extend libVersionInfoOverlay;
})
];
config = {
allowUnfree = true;
allowAliases = false;
permittedInsecurePackages = [
# Will not be available for the whole lifetime of NixOS 23.05.
"openssl-1.1.1w"
];
};
};
# Package sets for each platform.
pkgss = forAllPlatforms mkPkgs;
in
{
# Configurations for our hosts.
# These are used by tools like nixos-rebuild.
nixosConfigurations =
let
configs = import ./hosts { inherit inputs pkgss; };
in
configs;
# All our overlays.
# The packages defined in this repository are defined in ‘./pkgs’ and linked to the ‘default’ overlay.
# We will apply them to all hosts.
overlays =
let
overlayDir = ./common/overlays;
fullPath = name: overlayDir + "/${name}";
overlayPaths = map fullPath (builtins.attrNames (builtins.readDir overlayDir));
in
pathsToImportedAttrs overlayPaths;
# Nixpkgs packages with our overlays and packages.
legacyPackages = pkgss;
# All our modules and profiles that can be imported.
# A module in /common/modules/baz/qux.nix can be accessed as ‘${flakeRef}.nixosModules.qux’
# A profile in /common/profiles/foo.nix can be accessed as ‘${flakeRef}.nixosModules.profiles.foo’
nixosModules =
let
modulesAttrs = pathsToAttrs (import ./common/modules/list.nix);
profilesAttrs = {
profiles = pathsToAttrs (import ./common/profiles/list.nix);
};
in
modulesAttrs // profilesAttrs;
# All our home-manager modules and profiles that can be imported.
# A profile in /common/home-profiles/foo.nix can be accessed as ‘${flakeRef}.homeModules.profiles.foo’
# The key name from https://github.com/nix-community/home-manager/issues/1783#issuecomment-1461178166
homeModules =
let
modulesAttrs = { };
profilesAttrs = {
profiles = pathsToAttrs (import ./common/home-profiles/list.nix);
};
in
modulesAttrs // profilesAttrs;
# Development shell containing our maintenance utils
devShells = forAllPlatforms (platform: {
default = pkgss.${platform}.mkShell {
nativeBuildInputs = with pkgss.${platform}; [
agenix.packages.${platform}.default
deploy
git
nix
nopt
update
];
env = {
# Enable flakes even though they are optional
NIX_CONF_DIR =
let
current = pkgss.${platform}.lib.optionalString (builtins.pathExists /etc/nix/nix.conf) (
builtins.readFile /etc/nix/nix.conf
);
nixConf = pkgss.${platform}.writeTextDir "opt/nix.conf" ''
${current}
experimental-features = nix-command flakes
'';
in
"${nixConf}/opt";
};
};
});
};
}