-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
159 lines (137 loc) · 5.32 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
# A flake that sets up the necessary development environment for things.
{
description = "Hieratika: Compiling LLVM to CairoVM";
# The things that we want to pin to.
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
cairo.url = "github:cairo-nix/cairo-nix";
};
# The results of our flake.
outputs = {
self,
nixpkgs,
flake-utils,
crane,
fenix,
naersk,
cairo,
}:
flake-utils.lib.eachDefaultSystem (system:
let
# We grab our expected rust version from the Cargo.toml.
rustVersion = (lib.importTOML ./Cargo.toml).workspace.package.rust-version;
# Then we set up our libraries for building this thing.
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
fenixLib = fenix.packages.${system};
toolchainHash = "sha256-s1RPtyvDGJaX/BisLT+ifVfuhDT1nZkZ1NcK8sbwELM=";
fenixStable = fenixLib.fromToolchainName {
name = rustVersion;
sha256 = toolchainHash;
};
# As we want nightly Rustfmt, we have to build a custom toolchain.
fenixToolchain = fenixLib.combine [
fenixLib.latest.rustfmt # `fenixLib.latest` is specifically the latest nightly
(fenixStable.withComponents [
"cargo"
"clippy"
"rust-docs"
"rust-src"
"rust-std"
"rustc"
])
];
fenixToolchainUnstable = fenixLib.combine [
fenixLib.latest.cargo
fenixLib.latest.clippy
fenixLib.latest.rust-docs
fenixLib.latest.rust-src
fenixLib.latest.rust-std
fenixLib.latest.rustc
fenixLib.latest.rustfmt
];
# The crane library configures the Rust toolchain, along with the components we expect it
# to have.
craneLib = (crane.mkLib pkgs).overrideToolchain fenixToolchain;
craneLibUnstable = (crane.mkLib pkgs).overrideToolchain fenixToolchainUnstable;
# Collect our workspace packages, including our application.
workspacePackages = pkgs.callPackage ./workspace.nix {
inherit craneLib;
};
workspacePackagesUnstable = pkgs.callPackage ./workspace.nix {
craneLib = craneLibUnstable;
};
naersk' = naersk.lib.${system}.override {
cargo = fenixToolchainUnstable;
rustc = fenixToolchainUnstable;
};
test-inputs = pkgs.callPackage ./tests/rust-test-input/package.nix {
naersk = naersk';
inherit (fenixLib.latest) rust-src;
};
# Filter out things that aren't derivations for the `packages` output, or Nix gets mad.
hieratika = lib.filterAttrs (lib.const lib.isDerivation) workspacePackages;
hieratikaUnstable = lib.filterAttrs (lib.const lib.isDerivation) workspacePackagesUnstable;
# And for convenience, collect all the workspace members into a single derivation,
# so we can check they all compile with one command, `nix build '.#all'`.
all = pkgs.symlinkJoin {
name = "hieratika-all";
paths = lib.attrValues hieratika;
};
# We get your default shell to make sure things feel familiar in the dev shell.
getUserShellCommand = if pkgs.stdenv.hostPlatform.isDarwin then
"dscl . -read ~ UserShell | cut -d ' ' -f2 | tr -d '\n'"
else
"getent passwd $USER | cut -d ':' -f7 | tr -d '\n'";
# The packages that we want to make available in the dev shells.
devshellPackages = [
pkgs.nodejs_22
pkgs.cargo-deny
];
in {
packages = {
inherit all;
default = hieratika.hieratika-cli;
unstable = hieratikaUnstable.hieratika-cli;
inherit test-inputs;
} // hieratika;
# The default dev shell puts you in your native shell to make things feel happy.
devShells.default = craneLib.devShell {
LLVM_SYS_191_PREFIX = "${pkgs.lib.getDev pkgs.llvmPackages_19.libllvm}";
inputsFrom = lib.attrValues hieratika;
packages = devshellPackages;
rustTestInputs = test-inputs;
rustTestInputsDest = "crates/compiler/input/compilation";
shellHook = ''
mkdir -p "$rustTestInputsDest"
cp -r "$rustTestInputs"/* "$rustTestInputsDest"
exec $(${getUserShellCommand})
'';
};
devShells.unstable = craneLibUnstable.devShell {
LLVM_SYS_191_PREFIX = "${pkgs.lib.getDev pkgs.llvmPackages_19.libllvm}";
inputsFrom = lib.attrValues hieratikaUnstable;
packages = devshellPackages;
shellHook = ''
exec $(${getUserShellCommand})
'';
};
# The dev shell for CI allows it to interpret commands properly.
devShells.ci = craneLib.devShell {
LLVM_SYS_191_PREFIX = "${pkgs.lib.getDev pkgs.llvmPackages_19.libllvm}";
inputsFrom = lib.attrValues hieratika;
packages = devshellPackages;
};
}
);
}