forked from nixbuild/nix-quick-install-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
171 lines (147 loc) · 6.1 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
{
description = "nix-quick-install-action";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs-nix-2_16_1.url = "nixpkgs/e999e93d55c6298d151159c9e5ca4e773ff29d1f";
nixpkgs-nix-2_9_2.url = "nixpkgs/593d839e8fadea1183e071186ae1b584792d4884";
nixpkgs-nix-2_5_1.url = "nixpkgs/89f196fe781c53cb50fef61d3063fa5e8d61b6e5";
nixpkgs-nix-2_4.url = "nixpkgs/e912008eef096f52f28cf87492830c54ef334eb4";
nixpkgs-nix-2_2_2.url = "nixpkgs/5399f34ad9481849720d14605ce87b81abe202e9";
nixpkgs-nix-2_2_2.flake = false;
nixpkgs-nix-2_1_3.url = "nixpkgs/2c9265c95075170ad210ed5635ecffcd36db6b84";
nixpkgs-nix-2_1_3.flake = false;
nixpkgs-nix-2_0_4.url = "nixpkgs/47b85dc5ab8243a653c20d4851a3e6c966877251";
nixpkgs-nix-2_0_4.flake = false;
};
nixConfig = {
# We set some dummy Nix config here so we can use it for verification in our
# CI test
stalled-download-timeout = 333; # default 300
};
outputs = {
self,
flake-utils,
nixpkgs-nix-2_16_1,
nixpkgs-nix-2_9_2,
nixpkgs-nix-2_5_1,
nixpkgs-nix-2_4,
nixpkgs-nix-2_2_2,
nixpkgs-nix-2_1_3,
nixpkgs-nix-2_0_4
}:
let allSystems = ["x86_64-linux" "x86_64-darwin"];
in flake-utils.lib.eachSystem allSystems (system:
let
inherit (nixpkgs-nix-2_16_1) lib;
preferRemoteBuild = drv: drv.overrideAttrs (_: {
preferLocalBuild = false;
allowSubstitutes = true;
});
pkgs = import nixpkgs-nix-2_16_1 {
inherit system;
overlays = [
(self: super: super.prefer-remote-fetch self super)
];
};
makeNixArchive = nix:
pkgs.runCommand "nix-archive" {
buildInputs = [ nix pkgs.gnutar pkgs.zstd ];
closureInfo = pkgs.closureInfo { rootPaths = [ nix ]; };
fileName = "nix-${nix.version}-${system}.tar.zstd";
inherit nix;
} ''
mkdir -p "$out" root/nix/var/{nix,nix-quick-install-action}
ln -s $nix root/nix/var/nix-quick-install-action/nix
cp -t root/nix/var/nix-quick-install-action $closureInfo/registration
tar -cvT $closureInfo/store-paths -C root nix | zstd -o "$out/$fileName"
'';
nixVersions = system: lib.listToAttrs (map (nix: lib.nameValuePair
nix.version nix
) (
[ nixpkgs-nix-2_16_1.legacyPackages.${system}.nixVersions.nix_2_16
nixpkgs-nix-2_16_1.legacyPackages.${system}.nix
nixpkgs-nix-2_16_1.legacyPackages.${system}.nixVersions.nix_2_14
nixpkgs-nix-2_16_1.legacyPackages.${system}.nixVersions.nix_2_13
nixpkgs-nix-2_16_1.legacyPackages.${system}.nixVersions.nix_2_12
nixpkgs-nix-2_16_1.legacyPackages.${system}.nixVersions.nix_2_11
nixpkgs-nix-2_16_1.legacyPackages.${system}.nixVersions.nix_2_10
nixpkgs-nix-2_9_2.legacyPackages.${system}.nixVersions.nix_2_9
nixpkgs-nix-2_9_2.legacyPackages.${system}.nixVersions.nix_2_8
nixpkgs-nix-2_9_2.legacyPackages.${system}.nixVersions.nix_2_7
nixpkgs-nix-2_9_2.legacyPackages.${system}.nixVersions.nix_2_6
nixpkgs-nix-2_5_1.legacyPackages.${system}.nix
nixpkgs-nix-2_4.legacyPackages.${system}.nix
nixpkgs-nix-2_16_1.legacyPackages.${system}.nixVersions.nix_2_3
(import nixpkgs-nix-2_2_2 { inherit system; }).nix
(import nixpkgs-nix-2_1_3 { inherit system; }).nix
] ++ lib.optionals (system == "x86_64-linux") [
(import nixpkgs-nix-2_0_4 { inherit system; }).nix
]
));
nixPackages = lib.mapAttrs'
(v: p: lib.nameValuePair "nix-${lib.replaceStrings ["."] ["_"] v}" p)
(nixVersions system);
nixArchives = system: lib.mapAttrs (_: makeNixArchive) (nixVersions system);
allNixArchives = lib.concatMap (system:
map (version: {
inherit system version;
fileName = "nix-${version}-${system}.tar.zstd";
}) (lib.attrNames (nixArchives system))
) allSystems;
in rec {
defaultApp = apps.release;
apps.release = flake-utils.lib.mkApp { drv = packages.release; };
overlays = final: prev: nixPackages;
packages = nixPackages // {
nix-archives = preferRemoteBuild (pkgs.buildEnv {
name = "nix-archives";
paths = lib.attrValues (nixArchives system);
});
release = preferRemoteBuild (pkgs.writeScriptBin "release" ''
#!${pkgs.stdenv.shell}
PATH="${lib.makeBinPath (with pkgs; [
coreutils gitMinimal github-cli
])}"
if [ "$GITHUB_ACTIONS" != "true" ]; then
echo >&2 "not running in GitHub, exiting"
exit 1
fi
set -euo pipefail
nix_archives="$1"
release_file="$2"
release="$(head -n1 "$release_file")"
prev_release="$(gh release list -L 1 | cut -f 3)"
if [ "$release" = "$prev_release" ]; then
echo >&2 "Release tag not updated ($release)"
exit
else
release_notes="$(mktemp)"
tail -n+2 "$release_file" > "$release_notes"
echo "" | cat >>"$release_notes" - "${pkgs.writeText "notes" ''
## Supported Nix Versions on Linux Runners
${lib.concatStringsSep "\n" (
map (v: "* ${v}") (
lib.reverseList (lib.naturalSort (lib.attrNames (nixArchives "x86_64-linux")))
)
)}
## Supported Nix Versions on MacOS Runners
${lib.concatStringsSep "\n" (
map (v: "* ${v}") (
lib.reverseList (lib.naturalSort (lib.attrNames (nixArchives "x86_64-darwin")))
)
)}
''}"
echo >&2 "New release: $prev_release -> $release"
gh release create "$release" ${
lib.concatMapStringsSep " " ({ system, version, fileName }:
''"$nix_archives/${fileName}#nix-${version}-${system}"''
) allNixArchives
} \
--title "$GITHUB_REPOSITORY@$release" \
--notes-file "$release_notes"
fi
'');
};
}
);
}