sd-switch 0.5.1

A systemd unit reload/restart utility for Home Manager
Documentation
{
  description = "SD Switch";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    crane = {
      url = "github:ipetkov/crane?ref=v0.16.4";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    pre-commit-hooks = {
      url = "github:cachix/pre-commit-hooks.nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, flake-utils, crane, pre-commit-hooks }:
    let
      systems =
        [ "aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux" ];
    in flake-utils.lib.eachSystem systems (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        lib = pkgs.lib;
        craneLib = crane.lib.${system};

        src = lib.cleanSourceWith {
          src = craneLib.path ./.;
          filter = path: type:
            lib.hasInfix "/testdata/" path
            || craneLib.filterCargoSources path type;
        };

        commonArgs = { inherit src; };

        cargoArtifacts = craneLib.buildDepsOnly commonArgs;

        package =
          craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; });

        pre-commit-check = pre-commit-hooks.lib.${system}.run {
          inherit src;
          hooks = {
            nixfmt.enable = true;
            rustfmt.enable = true;
          };
        };

        integrationTestPackages = let
          tests = import ./tests/integration {
            pkgs = import nixpkgs {
              inherit system;
              overlays = [ (final: prev: { sd-switch = package; }) ];
            };
          };
          renameTestPkg = n: lib.nameValuePair "integration-test-${n}";
        in lib.mapAttrs' renameTestPkg tests;
      in {
        packages = {
          default = package;

          # Package for CI only. Used to cache the dependencies.
          _deps = cargoArtifacts;
        } // integrationTestPackages;

        apps.default = flake-utils.lib.mkApp { drv = package; };

        checks = { inherit pre-commit-check; };

        devShells.default = craneLib.devShell {
          checks = self.checks.${system};

          inputsFrom = [ package ];

          # Extra inputs can be added here; cargo and rustc are provided by default.
          packages = with pkgs; [ rust-analyzer ];

          shellHook =
            if system != "i686-linux" then pre-commit-check.shellHook else "";
        };
      });
}