-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
95 lines (84 loc) · 2.99 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
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.crane.inputs.nixpkgs.follows = "nixpkgs";
inputs.crane.url = "github:ipetkov/crane";
inputs.fenix.inputs.nixpkgs.follows = "nixpkgs";
inputs.fenix.url = "github:nix-community/fenix";
inputs.flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.treefmt-nix.url = "github:numtide/treefmt-nix";
inputs.treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
nixConfig.sandbox-paths = "/nix/var/nix/daemon-socket/socket";
outputs = {
self,
crane,
fenix,
flake-compat,
flake-utils,
nixpkgs,
treefmt-nix,
}: let
inherit (nixpkgs.lib) getExe optional mkForce;
in
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
packages = self.packages.${system};
toolchain = fenix.packages.${system}.stable.completeToolchain;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
nixDrv = pkgs.nixVersions.nix_2_21;
isolatedNix = postfix:
pkgs.symlinkJoin {
name = "isolated-nix${postfix}";
paths = [nixDrv];
nativeBuildInputs = [pkgs.makeWrapper];
postBuild =
''
wrapProgram $out/bin/nix${postfix} \
--set NIX_CONF_DIR /dev/null \
--set NIX_USER_CONF_FILES /dev/null \
''
+
# Serves as a test for handling early repl warnings
''
--set NIX_CONFIG "
intentionally-non-existent-option_a = 1
intentionally-non-existent-option_b = 1
"
'';
meta.mainProgram = "nix${postfix}";
};
NIX_CMD_PATH = getExe (isolatedNix "");
NIX_INSTANTIATE_CMD_PATH = getExe (isolatedNix "-instantiate");
commonArgs = {
src = craneLib.cleanCargoSource (craneLib.path ./.);
buildInputs = optional pkgs.stdenv.isDarwin pkgs.iconv;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
treefmtEval = treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs.alejandra.enable = true;
programs.rustfmt.enable = true;
settings.formatter.rustfmt.command = mkForce "${toolchain}/bin/rustfmt";
};
in {
packages.default = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts NIX_CMD_PATH NIX_INSTANTIATE_CMD_PATH;
}
);
apps = import ./release {inherit pkgs flake-utils;};
devShells.default = craneLib.devShell {
inherit NIX_CMD_PATH NIX_INSTANTIATE_CMD_PATH;
inputsFrom = [self.packages.${system}.default];
packages = [
toolchain
pkgs.nodePackages.nodejs
pkgs.mob
];
};
formatter = treefmtEval.config.build.wrapper;
checks.formatting = treefmtEval.config.build.check self;
checks.build = packages.default;
});
}