{
description = "SD Switch";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane?ref=v0.21.0";
pre-commit-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
crane,
pre-commit-hooks,
}:
let
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
forAllSystems =
f:
nixpkgs.lib.genAttrs systems (
system:
f rec {
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
craneLib = crane.mkLib pkgs;
src = lib.cleanSourceWith {
src = craneLib.path ./.;
filter = path: type: lib.hasInfix "/testdata/" path || craneLib.filterCargoSources path type;
};
commonArgs = {
inherit src;
meta = {
description = "Systemd unit switcher for Home Manager";
homepage = "https://git.sr.ht/~rycee/sd-switch";
changelog = "https://git.sr.ht/~rycee/sd-switch/tree/master/item/CHANGELOG.md";
license = lib.licenses.gpl3Plus;
platforms = lib.platforms.linux;
mainProgram = "sd-switch";
};
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
package = craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; });
pre-commit-check = pre-commit-hooks.lib.${system}.run {
inherit src;
hooks = {
nixfmt-rfc-style.enable = true;
rustfmt.enable = true;
};
};
}
);
in
{
packages = forAllSystems (
p:
let
integrationTestPackages =
let
tests = import ./tests/integration {
pkgs = import nixpkgs {
inherit (p) system;
overlays = [ (final: prev: { sd-switch = p.package; }) ];
};
};
renameTestPkg = n: p.lib.nameValuePair "integration-test-${n}";
in
p.lib.mapAttrs' renameTestPkg tests;
in
{
default = p.package;
# Package for CI only. Used to cache the dependencies.
_deps = p.cargoArtifacts;
}
// integrationTestPackages
);
checks = forAllSystems (p: {
inherit (p) pre-commit-check;
clippy =
with p;
craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
});
devShells = forAllSystems (p: {
default = p.craneLib.devShell {
checks = self.checks.${p.system};
inputsFrom = [ p.package ];
packages = with p.pkgs; [
cargo-audit
cargo-outdated
];
shellHook = p.pre-commit-check.shellHook;
};
});
};
}