Executiong nixops in systemd unit fails

I have a nixops deployment that at the moment is failing.

; sc start nixops-upgrade-flatwoody.service                                                                                                                                                                               

; sc status nixops-upgrade-flatwoody.service                                                                                                                                                                                         

× nixops-upgrade-flatwoody.service
     Loaded: loaded (/etc/systemd/system/nixops-upgrade-flatwoody.service; linked; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2022-06-18 14:54:37 UTC; 2s ago
TriggeredBy: ● nixops-upgrade-flatwoody.timer
    Process: 284027 ExecStart=/nix/store/7wkdshkdb29kg41gc6f9fl2w8ddwad7f-python3.8-nixops-2.0.0/bin/nixops deploy --network ./. -d 0e84df64-e9b7-11ec-8410-44af2811d866 --include flatwoody (code=exited, status=1/FAILURE)
   Main PID: 284027 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 195ms

Jun 18 14:54:37 nassie systemd[1]: Started nixops-upgrade-flatwoody.service.
Jun 18 14:54:37 nassie nixops[284027]: User: root, Command: /nix/store/7wkdshkdb29kg41gc6f9fl2w8ddwad7f-python3.8-nixops-2.0.0/bin/nixops deploy --network ./. -d 0e84df64-e9b7-11ec-8410-44af2811d866 --include flatwoody
Jun 18 14:54:37 nassie nixops[284027]: error: evaluation of the deployment specification failed
Jun 18 14:54:37 nassie nixops[284027]: 
Jun 18 14:54:37 nassie nixops[284027]: error: evaluation of the deployment specification failed
Jun 18 14:54:37 nassie systemd[1]: nixops-upgrade-flatwoody.service: Main process exited, code=exited, status=1/FAILURE
Jun 18 14:54:37 nassie systemd[1]: nixops-upgrade-flatwoody.service: Failed with result 'exit-code'.
; sc cat nixops-upgrade-flatwoody.service                                                                                                                                                                                       
# /etc/systemd/system/nixops-upgrade-flatwoody.service
[Unit]
After=network-online.target nixops-upgrade.service
Wants=network-online.target

[Service]
Environment="HOME=/root"
Environment="LOCALE_ARCHIVE=/nix/store/snyv674qd9gsg8j1in9wwpa5l6ns1nxj-glibc-locales-2.34-210/lib/locale/locale-archive"
Environment="PATH=/nix/store/y72i4llqf5zxvdp6b3j7ysixpdrid7qr-coreutils-9.1/bin:/nix/store/lxd4xas5jkkf4q2gnb9v8iss3lpgh4jh-findutils-4.9.0/bin:/nix/store/z3q9q9549ci7kbdgyq99r6crnvrky6v3-gnugrep-3.7/bin:/nix/store/j8hcaam4dpv1ys2bnxij>
Environment="TZDIR=/nix/store/2gwcg7qi7p4pg83pyibmhg76dc65zlyp-tzdata-2022a/share/zoneinfo"



CPUWeight=20
ExecStart=/nix/store/7wkdshkdb29kg41gc6f9fl2w8ddwad7f-python3.8-nixops-2.0.0/bin/nixops deploy --network ./. -d 0e84df64-e9b7-11ec-8410-44af2811d866 --include flatwoody
IOWeight=20
WorkingDirectory=/etc/nixos

the weird thing is that if I execute nixops deploy --include flatwoody it succeeds.
The unit is defined here : hosts/nassie/update.nix · main · Paki / My Nixos Conf · GitLab

IN fact if I copy paste the line in ExecStart in my terminal it succeeds.

systemd units have an explicitly declared environment. Likely the deployment evaluation depends on some environment variables (NIX_PATH, perhaps?) you need to set as well.

1 Like

Added environment.NIX_PATH = lib.strings.concatStringsSep ":" config.nix.nixPath; to the base nix options but it still give me the same error

And no the entire configuration is in a flake, and it does not depend on any eternal factors.

In fact the unit nixops-upgrade.service that only builds the system, succeeds without problems

Hell I’ve even tried to add --debug but not even the output changes.