-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathflake.nix
93 lines (80 loc) · 2.48 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
{
inputs = {
gleam.url = "github:gleam-lang/gleam/v1.0.0";
gleam.flake = false;
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
nixpkgs.url = "github:nixos/nixpkgs?ref=23.11";
cargo2nix.url = "github:cargo2nix/cargo2nix";
cargo2nix.inputs.nixpkgs.follows = "nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.inputs.flake-utils.follows = "flake-utils";
};
outputs = {
self,
gleam,
nixpkgs,
cargo2nix,
flake-utils,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
cargo2nix.overlays.default
rust-overlay.overlays.default
];
};
rustPkgs = pkgs.rustBuilder.makePackageSet {
rustChannel = "1.74.0";
packageFun = import ./Cargo.nix;
workspaceSrc = gleam;
};
workspaceShell = rustPkgs.workspaceShell {
nativeBuildInputs = with pkgs; [rust-analyzer];
};
gleamBin = (rustPkgs.workspace.gleam {}).bin;
packages = {
gleam = gleamBin;
default = gleamBin;
};
devShells.default = workspaceShell;
apps = {
default = flake-utils.lib.mkApp {drv = gleamBin;};
fmt = flake-utils.lib.mkApp {
drv = with pkgs;
writeScriptBin "fmt" ''
${pkgs.alejandra}/bin/alejandra "$@" -e ./Cargo.nix .
'';
};
genCargoNix = flake-utils.lib.mkApp {
drv = with pkgs;
writeScriptBin "genCargoNix.bash" ''
set -xeuo pipefail
GLEAM_NIX="''${1:-$PWD}"
GLEAM_SRC="''${2:-${gleam}}"
${cargo2nix.packages.${system}.default}/bin/cargo2nix "$GLEAM_SRC" --locked --file $GLEAM_NIX/Cargo.nix
'';
};
};
checks = {
gleamHello = with pkgs;
stdenvNoCC.mkDerivation {
name = "gleam-hello";
phases = ["test"];
test = ''
${gleamBin}/bin/gleam --help > $out
'';
};
};
in {inherit packages devShells apps checks;}
)
// {
overlays.default = final: prev: {inherit (self.packages.${final.system}) gleam;};
};
}