feat(nix): switch to Nix Flakes

This commit is contained in:
Harsh Shandilya 2022-12-28 07:21:37 +00:00
parent d43144267c
commit 584b9d0439
6 changed files with 357 additions and 18 deletions

View File

@ -10,7 +10,7 @@ on:
name: Check Rust code
jobs:
check:
uses: msfjarvis/shared-workflows/.github/workflows/test-rust-project.yml@main
with:
# Keep in sync with healthchecks/Cargo.toml
msrv: 1.64.0
uses: msfjarvis/shared-workflows/.github/workflows/test-flakes-project.yml@main
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}
cachix-token: ${{ secrets.CACHIX_AUTH_TOKEN }}

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"nixEnvSelector.nixFile": "${workspaceRoot}/shell.nix"
}

8
default.nix Normal file
View File

@ -0,0 +1,8 @@
(import (let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}) {src = ./.;})
.defaultNix

131
flake.lock Normal file
View File

@ -0,0 +1,131 @@
{
"nodes": {
"advisory-db": {
"flake": false,
"locked": {
"lastModified": 1669556130,
"narHash": "sha256-6qRQVSgpw+Tw17TroiUg8nAte9/KVDH+v30MOOd+pQU=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "a66a3049c98395410a2afadf0382882b0a04d8b1",
"type": "github"
},
"original": {
"owner": "rustsec",
"repo": "advisory-db",
"type": "github"
}
},
"crane": {
"inputs": {
"flake-compat": [
"flake-compat"
],
"flake-utils": [
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
],
"rust-overlay": [
"rust-overlay"
]
},
"locked": {
"lastModified": 1669605882,
"narHash": "sha256-TiQtL5sUI5rp28S63v+VX25qNjcrc8Xeu+shf3g7Tj4=",
"owner": "ipetkov",
"repo": "crane",
"rev": "24591d5f8cc979f7b243b88a2d39da09976970ad",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1668681692,
"narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "009399224d5e398d03b22badca40a37ac85412a1",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1669597967,
"narHash": "sha256-R+2NaDkXsYkOpFOhmVR8jBZ77Pq55Z6ilaqwFLLn000=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "be9e3762e719211368d186f547f847737baad720",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"advisory-db": "advisory-db",
"crane": "crane",
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1669689198,
"narHash": "sha256-YsWu3C9IGbH3+xguTzEDyQorFe/igr6FGZ+Q5T2ocxE=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "4e093ce661a63aca4bcbace33695225eae4ef4e4",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

203
flake.nix Normal file
View File

@ -0,0 +1,203 @@
{
description = "healthchecks-rs monorepo";
inputs = {
nixpkgs = {url = "github:NixOS/nixpkgs/nixpkgs-unstable";};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
flake-utils = {url = "github:numtide/flake-utils";};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
crane = {
url = "github:ipetkov/crane";
inputs = {
flake-compat.follows = "flake-compat";
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
rust-overlay.follows = "rust-overlay";
};
};
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
outputs = {
self,
nixpkgs,
crane,
flake-utils,
advisory-db,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [(import rust-overlay)];
};
rustStable =
pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
# Keep in sync with healthchecks/Cargo.toml
rustMsrv = pkgs.rust-bin.stable."1.64.0".default;
craneLib = (crane.mkLib pkgs).overrideToolchain rustStable;
commonArgs = {
src = ./.;
buildInputs = [];
nativeBuildInputs = [];
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
};
src = ./.;
hcctlArgs = "-p hcctl";
healthchecksArgs = "-p healthchecks";
monitorArgs = "-p healthchecks-monitor";
audit = craneLib.cargoAudit {
inherit src advisory-db;
};
cargoArtifacts = craneLib.buildDepsOnly (commonArgs
// {
pname = "workspace-deps";
});
hcctl-fmt = craneLib.cargoFmt (commonArgs
// {
inherit cargoArtifacts;
pname = "hcctl";
cargoExtraArgs = hcctlArgs;
});
hcctl-clippy = craneLib.cargoClippy (commonArgs
// {
pname = "hcctl";
cargoArtifacts = hcctl-fmt;
cargoExtraArgs = hcctlArgs;
});
hcctl = craneLib.buildPackage (
commonArgs
// {
pname = "hcctl";
cargoArtifacts = hcctl-clippy;
}
);
hcctl-nextest = craneLib.cargoNextest (commonArgs
// {
pname = "hcctl";
cargoArtifacts = hcctl;
cargoExtraArgs = hcctlArgs;
partitions = 1;
partitionType = "count";
});
monitor-fmt = craneLib.cargoFmt (commonArgs
// {
inherit cargoArtifacts;
pname = "monitor";
cargoExtraArgs = monitorArgs;
});
monitor-clippy = craneLib.cargoClippy (commonArgs
// {
pname = "monitor";
cargoArtifacts = monitor-fmt;
cargoExtraArgs = monitorArgs;
});
monitor = craneLib.buildPackage (
commonArgs
// {
pname = "monitor";
cargoArtifacts = monitor-clippy;
}
);
monitor-nextest = craneLib.cargoNextest (commonArgs
// {
pname = "monitor";
cargoArtifacts = monitor;
cargoExtraArgs = monitorArgs;
partitions = 1;
partitionType = "count";
});
healthchecks-fmt = craneLib.cargoFmt (commonArgs
// {
inherit cargoArtifacts;
pname = "healthchecks";
cargoExtraArgs = healthchecksArgs;
});
healthchecks-clippy = craneLib.cargoClippy (commonArgs
// {
pname = "healthchecks";
cargoArtifacts = healthchecks-fmt;
cargoExtraArgs = healthchecksArgs;
});
healthchecks = craneLib.buildPackage (
commonArgs
// {
pname = "healthchecks";
cargoArtifacts = healthchecks-clippy;
}
);
healthchecks-nextest = craneLib.cargoNextest (commonArgs
// {
pname = "healthchecks";
cargoArtifacts = healthchecks;
cargoExtraArgs = healthchecksArgs;
partitions = 1;
partitionType = "count";
});
healthchecks-msrv = ((crane.mkLib pkgs).overrideToolchain rustMsrv).buildPackage (commonArgs
// {
pname = "healthchecks-msrv";
cargoArtifacts = healthchecks;
cargoExtraArgs = healthchecksArgs;
doCheck = false;
});
in {
checks = {
inherit
audit
hcctl
hcctl-clippy
hcctl-fmt
hcctl-nextest
healthchecks
healthchecks-msrv
healthchecks-clippy
healthchecks-fmt
healthchecks-nextest
monitor
monitor-clippy
monitor-fmt
monitor-nextest
;
};
packages.default = hcctl;
apps.hcctl = flake-utils.lib.mkApp {drv = hcctl;};
apps.monitor = flake-utils.lib.mkApp {drv = monitor;};
apps.default = flake-utils.lib.mkApp {drv = hcctl;};
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self.checks;
nativeBuildInputs = with pkgs; [
cargo-nextest
cargo-release
nil
rustStable
];
};
});
}

View File

@ -1,14 +1,8 @@
with import <nixpkgs> { overlays = [ (import <rust-overlay>) ]; };
mkShell {
buildInputs = [
(rust-bin.stable.latest.default.override {
extensions =
[ "rust-src" "rustc-dev" "rustfmt-preview" "llvm-tools-preview" ];
targets =
pkgs.lib.optionals pkgs.stdenv.isDarwin [ "aarch64-apple-darwin" ]
++ pkgs.lib.optionals pkgs.stdenv.isLinux
[ "x86_64-unknown-linux-gnu" ];
})
] ++ pkgs.lib.optionals stdenv.isDarwin
[ pkgs.darwin.apple_sdk.frameworks.Security ];
}
(import (let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}) {src = ./.;})
.shellNix