Is it possible to prevent GC when using nix-copy and systemd?

I wasn’t sure how to describe my problem in the title.
I want to run one of my Rust application on a NixOS server.

I did:

crate2nix generate
nix-build Cargo.nix
nix copy --to ssh://nixos ./result

Now I can use it in a systemd unit but it will will be garbage collected the next time I run nix-collect-garbage. = rec {
    startAt = "01:00:00";
    script = "/nix/store/00000000000000000000000000000000-rust_my-thing-0.1.0/bin/my-thing";

Any better way?

I recommend you check out

1 Like

The proper thing is to use the same Nix expression on the server’s configuration to get that path, rather than hard coding a /nix/store path.

1 Like