-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
89 lines (75 loc) · 2.35 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
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=21.11";
nixos-shell = {
url = "github:Mic92/nixos-shell?ref=1.0.0";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane?ref=v0.3.3";
inputs.nixkpgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixkpgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, rust-overlay, crane, nixos-shell, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlay ];
};
checkNixFilesFormatting = pkgs.stdenv.mkDerivation {
name = "checkNixFilesFormatting";
src = ./.;
installPhase = ''
find . -type f -name '*.nix' ! -name 'yarn-project.nix' | xargs nixfmt -c
mkdir $out
'';
buildInputs = [ pkgs.nixfmt ];
};
rust = pkgs.rust-bin.stable.latest.default;
backendSrc = ./backend;
craneLib = (crane.lib.${system}).overrideScope' (final: prev: {
rustc = rust;
cargo = rust;
rustfmt = rust;
clippy = rust;
});
cargoArtifacts = craneLib.buildDepsOnly { src = backendSrc; };
frontend = pkgs.callPackage ./frontend { };
backendPreBuildPhase = ''
mkdir -p static
cp -r ${frontend}/static/* static
'';
backendCheck = craneLib.cargoClippy {
inherit cargoArtifacts;
src = backendSrc;
preBuild = backendPreBuildPhase;
cargoClippyExtraArgs = "--all-features -- -D warnings";
};
backendFormat = craneLib.cargoFmt { src = backendSrc; };
backend = craneLib.buildPackage {
cargoArtifacts = backendCheck;
src = backendSrc;
preBuild = backendPreBuildPhase;
};
in {
devShells.${system}.default =
pkgs.mkShell { buildInputs = [ nixos-shell ]; };
checks.${system} = {
inherit checkNixFilesFormatting frontend backendCheck backendFormat;
};
nixosConfigurations = let lib = nixpkgs.lib;
in {
vm = lib.makeOverridable lib.nixosSystem {
system = system;
specialArgs = { inherit frontend backend; };
modules =
[ nixos-shell.nixosModules.nixos-shell ./common.nix ./vm.nix ];
};
};
};
}