sd-switch 0.5.2

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.19.3";
    pre-commit-hooks = {
      url = "github:cachix/git-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.mkLib pkgs;

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

        commonArgs = {
          inherit src;
          meta.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;
          };
        };

        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 = pre-commit-check.shellHook;
        };
      }
    );
}