This repository was archived by the owner on Jul 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathflake.nix
More file actions
110 lines (95 loc) · 2.76 KB
/
flake.nix
File metadata and controls
110 lines (95 loc) · 2.76 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
{
description = "Nix + GitHub Actions";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self
, nixpkgs
, flake-utils
, rust-overlay
}:
# Non-system-specific logic
let
# Borrow project metadata from the Rust config
meta = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package;
inherit (meta) name version;
overlays = [
# Rust helpers
(import rust-overlay)
# Build Rust toolchain using helpers from rust-overlay
(self: super: {
# This supplies cargo, rustc, rustfmt, etc.
rustToolchain = super.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
})
];
in
# System-specific logic
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit overlays system; };
runCiLocally = pkgs.writeScriptBin "ci-local" ''
echo "Checking Rust formatting..."
cargo fmt --check
echo "Auditing Rust dependencies..."
cargo-deny check
echo "Auditing editorconfig conformance..."
eclint -exclude "Cargo.lock"
echo "Checking spelling..."
codespell \
--skip target,.git \
--ignore-words-list crate
echo "Testing Rust code..."
cargo test
echo "Building TODOs service..."
nix build .#todos
'';
in
{
devShells = {
# Unified shell environment
default = pkgs.mkShell
{
buildInputs = [ runCiLocally ] ++ (with pkgs; [
# Rust stuff (CI + dev)
rustToolchain
cargo-deny
# Rust stuff (dev only)
cargo-edit
cargo-watch
# Spelling and linting
codespell
eclint
]);
};
};
packages = rec {
default = todos;
todos = pkgs.rustPlatform.buildRustPackage {
pname = name;
inherit version;
src = ./.;
cargoSha256 = "sha256-nLnEn3jcSO4ChsXuCq0AwQCrq/0KWvw/xWK1s79+zBs=";
release = true;
};
docker =
let
bin = "${self.packages.${system}.todos}/bin/${name}";
in
pkgs.dockerTools.buildLayeredImage {
inherit name;
tag = "v${version}";
config = {
Entrypoint = [ bin ];
ExposedPorts."8080/tcp" = { };
};
};
};
});
}