Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
138 lines (125 loc) · 3.89 KB
/
Copy pathflake.nix
File metadata and controls
138 lines (125 loc) · 3.89 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
129
130
131
132
133
134
135
136
137
138
# This flake allows a user to run any version of the
# roc nightly compiler as listed in sources.json as
# available on the host platform for the listed systems.
# It provides built-in smoke test via checks, an overlay...
{
description = "Official Roc new-compiler nightly binaries";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# nixos-unstable no longer supports Intel macOS (x86_64-darwin)
nixpkgs-darwin.url = "github:NixOS/nixpkgs/nixpkgs-26.05-darwin";
};
outputs = {
self,
nixpkgs,
nixpkgs-darwin,
}: let
inherit (nixpkgs) lib;
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
# A function which maps each system in systems
# to the fn provided to it (in this case, the
# system switching logic).
eachSystem = lib.genAttrs systems;
# Map every system to its corresponding nixpkgs package
# set.
# e.g. {
# x86_64-linux = nixpkgs.legacyPackages.x86_64-linux;
# aarch64-linux = nixpkgs.legacyPackages.aarch64-linux;
# x86_64-darwin = nixpkgs-darwin.legacyPackages.x86_64-darwin;
# aarch64-darwin = nixpkgs.legacyPackages.aarch64-darwin;
# }
pkgsFor = eachSystem (
system:
if system == "x86_64-darwin"
then nixpkgs-darwin.legacyPackages.${system}
else nixpkgs.legacyPackages.${system}
);
in {
# Call default.nix for every system & pkg for that system,
# resulting package set is all the pkgs for host platform's
# system (i.e. the one running this flake).
#
# result e.g.:
# {
# x86_64-linux = {
# default = <Roc derivation>;
# nightly = <Roc derivation>;
# "nightly-2026-..." = <Roc derivation>;
# };
#
# # Other systems...
# }
packages = lib.mapAttrs (system: pkgs: import ./default.nix {inherit pkgs system;}) pkgsFor;
apps = eachSystem (system: {
default = self.apps.${system}.roc;
roc = {
type = "app";
program = "${self.packages.${system}.default}/bin/roc";
meta.description = "Run the latest recorded Roc nightly";
};
});
# Extend a consumer's nixpkgs package set with the
# packages provided by the overlay.
overlays.default = final: prev: {
# Roc package set for the selected platform, e.g.
# {
# default = <derivation>;
# nightly = <derivation>;
# "nightly-2026-..." = <derivation>;
# }
rocpkgs = self.packages.${prev.stdenv.hostPlatform.system};
};
formatter =
lib.mapAttrs (
_: pkgs:
pkgs.writeShellScriptBin "roc-overlay-fmt" ''
exec ${lib.getExe pkgs.alejandra} "$@" .
''
)
pkgsFor;
devShells =
lib.mapAttrs (_: pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
coreutils
curl
git
jq
];
};
})
pkgsFor;
# - Ensures nightly package builds
# - Checks that roc version exactly matches recorded
# metadata from sources.json
# - Compiles and runs a hello program
# - Checks its exact stdout
checks =
lib.mapAttrs (
system: pkgs: let
roc = self.packages.${system}.nightly;
in {
nightly = roc;
smoke = pkgs.runCommand "roc-nightly-smoke" {nativeBuildInputs = [roc];} ''
export HOME="$TMPDIR/home"
mkdir -p "$HOME" "$TMPDIR/test"
test "$(roc version)" = "Roc compiler version ${roc.compilerVersion}"
cat >"$TMPDIR/test/main.roc" <<'EOF'
main! = |_args| {
echo!("Hello from Roc!")
Ok({})
}
EOF
test "$(cd "$TMPDIR/test" && roc main.roc)" = "Hello from Roc!"
touch "$out"
'';
}
)
pkgsFor;
};
}