-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
190 lines (170 loc) · 5.55 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
{
inputs = {
#nixpkgs.url = "/mnt/home/michael/github/NixOS/nixpkgs";
nixpkgs.url = "github:prinzdezibel/nixpkgs?ref=d432ca284c1a78cd9f4d6722e3dc6ab10a53ece6";
#nixpkgs.url = "github:NixOS/nixpkgs?ref=staging";
};
outputs =
{
self,
nixpkgs,
...
}:
let
buildSystem = "aarch64-linux"; # Change this if you're building on Intel arch
platformConfigMatrix = {
x86_64-linux = "gnu64";
aarch64-linux = "aarch64-multiplatform";
};
llvmTripleMatrix = {
x86_64-linux = "x86_64-unknown-linux-gnu";
aarch64-linux = "aarch64-unknown-linux-gnu";
};
forAllSystems =
function:
nixpkgs.lib.genAttrs (nixpkgs.lib.attrNames platformConfigMatrix) (
platformConfigMatrixAttr:
function {
system = platformConfigMatrixAttr;
# nixos =
# nixpkgs.legacyPackages.${buildSystem}.pkgsCross.${
# platformConfigMatrix.${platformConfigMatrixAttr}
# }.nixos;
nixos = nixpkgs.lib.nixosSystem;
}
);
in
{
nixosModules.images =
{
config,
lib,
pkgs,
modulesPath,
system,
...
}:
{
options = {
emulatedUEFI = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Emulation of an UEFI environment on legacy BIOS systems. Uses Clover bootloader to chainload systemd-boot.
Does only work for x86_64 architecture.
'';
};
};
imports = [
(
{
config,
lib,
pkgs,
modulesPath,
...
}:
let
configuration = builtins.readFile ./modules/configuration.nix;
configFile = pkgs.writeText "configuration.nix" ''
{pkgs, ...}: {
imports = [
./modules/base-system.nix
${configuration}
];
system.stateVersion = "${lib.version}";
}
'';
in
{
system.build.qcow = import "${toString modulesPath}/../lib/make-disk-image.nix" (
{
inherit lib config pkgs;
inherit (config.virtualisation) diskSize;
format = "qcow2";
partitionTableType = "efi";
bootSize = "2048M";
contents = [
# Touch /etc/os-release (needed by activation script)
{
source = pkgs.writeText "os-release" '''';
target = "etc/os-release";
}
{
source = configFile;
target =
if config.system.etc.overlay.enable then
".rw-etc/upper/nixos/configuration.nix"
else
"etc/nixos/configuration.nix";
mode = "0755";
}
{
source = ./modules;
target =
if config.system.etc.overlay.enable then ".rw-etc/upper/nixos/modules" else "etc/nixos/modules";
mode = "0755";
}
];
}
// lib.optionalAttrs (pkgs.system != "x86_64-linux") {
touchEFIVars = config.boot.loader.efi.canTouchEfiVariables;
}
);
}
)
./modules/base-system.nix
./modules/configuration.nix
./modules/cloud-init.nix
];
config = {
# Build platform
nixpkgs.system = buildSystem;
# Target platform
nixpkgs.crossSystem = {
system = system;
config = llvmTripleMatrix.${system};
};
nixpkgs.overlays = [
(final: prev: {
})
];
environment = {
# Prevent cross compile error "Option environment.ldso32 currently only works on x86_64"
# Don't support 32 bit.
ldso32 = lib.mkIf (pkgs.system == "x86_64-linux") null;
};
# This pulls in nixos-containers which depend on Perl.
boot.enableContainers = false;
system.stateVersion = lib.version;
};
};
nixosConfigurations = forAllSystems (
{
system,
nixos,
}:
rec {
nixosConfigurations = nixos {
# a) nixpkgs.lib.nixosSystem
modules = [ self.nixosModules.images ];
specialArgs = {
inherit system;
};
# b) nixpkgs.legacyPackages.x86-64-linux.pkgsCross.gnu64.nixos
# system = buildSystem;
# imports = [
# {
# # Set system as special arguments for all submodules
# _module.args = {
# inherit system;
# };
# }
# self.nixosModules.images
# ];
};
qcow = nixosConfigurations.config.system.build.qcow;
}
);
};
}