diff --git a/Cargo.toml b/Cargo.toml index 5b674f4..c13b515 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,12 +28,16 @@ toml = "0.9.10" tracing = "0.1.44" tracing-subscriber = { version = "0.3.22", features = ["env-filter"] } # onc-rpc = "0.3.2" -sd-notify = "0.4.5" +sd-notify = { version = "0.4.5", optional = true } serde_json = "1.0.148" uucore = { version = "0.5.0", features = ["utmpx"] } zlink = { version = "0.2.0", features = ["introspection"] } clap_complete = "4.5.65" +[features] +default = ["systemd"] +systemd = ["sd-notify", "uucore/feat_systemd_logind"] + [lib] name = "roowho2_lib" path = "src/lib.rs" diff --git a/flake.nix b/flake.nix index 5e9a303..e452354 100644 --- a/flake.nix +++ b/flake.nix @@ -53,10 +53,17 @@ nativeBuildInputs = with pkgs; [ toolchain cargo-edit - ]; + ] ++ (lib.optionals stdenv.buildPlatform.isLinux [ + systemdLibs + ]); - env.RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; - env.RUSTFLAGS = "-Zhigher-ranked-assumptions"; + env = { + RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; + RUSTFLAGS = "-Zhigher-ranked-assumptions"; + CARGO_CFG_FEATURE = lib.concatStringsSep "," (lib.optionals pkgs.stdenv.buildPlatform.isLinux [ + "systemd" + ]); + }; }); overlays = { diff --git a/nix/package.nix b/nix/package.nix index 3bf0736..00a5fa8 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -5,6 +5,7 @@ , buildPackages , installShellFiles , versionCheckHook +, systemdLibs , cargoToml , cargoLock @@ -21,6 +22,14 @@ rustPlatform.buildRustPackage { RUSTFLAGS = "-Zhigher-ranked-assumptions"; + buildFeatures = lib.optionals stdenv.hostPlatform.isLinux [ + "systemd" + ]; + + buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ + systemdLibs + ]; + nativeBuildInputs = [ installShellFiles ]; postInstall = let emulator = stdenv.hostPlatform.emulator buildPackages;