-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathflake.nix
159 lines (150 loc) · 5.17 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
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-24.11";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
treefmt-nix,
...
}:
let
inherit (nixpkgs) lib;
inherit (lib) genAttrs mapAttrs recursiveUpdate;
supportedSystems = [
"aarch64-linux"
"x86_64-linux"
"aarch64-darwin"
];
eachSystem = f: genAttrs supportedSystems (system: f nixpkgs.legacyPackages.${system});
treefmtEval = eachSystem (
pkgs:
treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs.black.enable = true;
programs.nixfmt.enable = true;
programs.actionlint.enable = true;
programs.yamlfmt.enable = false; # check and format dont agree about comments
programs.shellcheck.enable = true;
}
);
in
{
nixosModules = {
ec2-instance-connect = ./modules/ec2-instance-connect.nix;
legacyAmazonProfile = nixpkgs + "nixos/modules/virtualisation/amazon-image.nix";
legacyAmazonImage = nixpkgs + "/nixos/maintainers/scripts/ec2/amazon-image.nix";
amazonProfile = ./modules/amazon-profile.nix;
amazonImage = ./modules/amazon-image.nix;
mock-imds = ./modules/mock-imds.nix;
version =
{ config, ... }:
{
system.stateVersion = config.system.nixos.release;
# NOTE: This will cause an image to be built per commit.
# system.nixos.versionSuffix = lib.mkForce
# ".${lib.substring 0 8 (nixpkgs.lastModifiedDate or nixpkgs.lastModified or "19700101")}.${nixpkgs.shortRev}.${lib.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}";
};
};
packages =
recursiveUpdate
(genAttrs supportedSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
upload-ami = pkgs.python3Packages.callPackage ./upload-ami { };
amazon-ec2-metadata-mock = pkgs.buildGoModule rec {
pname = "amazon-ec2-metadata-mock";
version = "1.11.2";
doCheck = false; # check is flakey
src = pkgs.fetchFromGitHub {
owner = "aws";
repo = "amazon-ec2-metadata-mock";
rev = "v${version}";
hash = "sha256-hYyJtkwAzweH8boUY3vrvy6Ug+Ier5f6fvR52R+Di8o=";
};
vendorHash = "sha256-T45abGVoiwxAEO60aPH3hUqiH6ON3aRhkrOFcOi+Bm8=";
};
}
))
(
genAttrs [ "aarch64-linux" "x86_64-linux" ] (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
ec2-instance-connect = pkgs.callPackage ./packages/ec2-instance-connect.nix { };
}
)
);
apps = genAttrs supportedSystems (
system:
let
upload-ami = self.packages.${system}.upload-ami;
mkApp = name: _: {
type = "app";
program = "${upload-ami}/bin/${name}";
};
in
mapAttrs mkApp self.packages.${system}.upload-ami.passthru.pyproject.project.scripts
);
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
checks =
recursiveUpdate
(genAttrs supportedSystems (system: {
inherit (self.packages.${system}) upload-ami;
formatting = treefmtEval.${system}.config.build.check self;
}))
(
lib.genAttrs [ "aarch64-linux" "x86_64-linux" ] (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
config = {
node.pkgs = pkgs;
node.specialArgs.selfPackages = self.packages.${system};
defaults =
{ name, ... }:
{
imports = [
self.nixosModules.version
self.nixosModules.amazonImage
self.nixosModules.mock-imds
];
# Needed because test framework insists on having a hostName
networking.hostName = "";
};
};
in
{
resize-partition = lib.nixos.runTest {
hostPkgs = pkgs;
imports = [
config
./tests/resize-partition.nix
];
};
ec2-metadata = lib.nixos.runTest {
hostPkgs = pkgs;
imports = [
config
./tests/ec2-metadata.nix
];
};
}
)
);
devShells = genAttrs supportedSystems (system: {
default = self.packages.${system}.upload-ami;
});
};
}