`nixos-rebuild build` not outputting changed lines

Edit 2 [issue mostly solved]: It looks like I need to look for the drv name during the build step, then use cat $(nix-store -q --outputs <drvpath>) to see the file contents I want. I’d still appreciate any comments on a more convenient way to do this. Also, is the symlinking postfix does to /var/lib/postfix normal? Maybe it only bit me, but it seems dirty and unnecessarily complex.

I’m building a mailserver in NixOS and wanted to use nixos-rebuild build to preview my outputted configuration files before "switch"ing to them. I can’t get my changes to the nix file to show up in the output! nixos-rebuild switch does work, but I don’t want to actually switch until I check the output.

If this is just the wrong way of doing what I’m trying to do, I’ll take another way, but at this point I’m also curious why “build” doesn’t seem to work.

Here’s some summarized terminal output from a minimal testcase.

# nixos-rebuild switch

[scintill@nixos:/etc/nixos]$ grep inet_protocols configuration.nix result/etc/postfix/main.cf /etc/postfix/main.cf ; ls -l result/etc/postfix/main.cf
configuration.nix:      inet_protocols = "ipv6";
result/etc/postfix/main.cf:inet_protocols = ipv6
/etc/postfix/main.cf:inet_protocols = ipv6
lrwxrwxrwx 1 root root 59 Jun 26 00:45 result/etc/postfix/main.cf -> /nix/store/abjppmrwp94lwh71jadh8yndqv8w9nzr-postfix-main.cf

# change configuration.nix (to ipv4)

[scintill@nixos:/etc/nixos]$ nixos-rebuild build
building Nix...
building the system configuration...
these derivations will be built:
  /nix/store/i0kk0cg3wv23aj2y24wpsm7xqm8kiil3-postfix-main.cf.drv
  /nix/store/2gam9pfyfa8pzi4mbikn319jxdqrc9ir-unit-script-postfix-pre-start.drv
  /nix/store/i1dg5skdilyqrg9nnfqa1gp73ixfyxv1-unit-postfix.service.drv
  /nix/store/8dqv3v93n6b7hv9wrr5s76zmb7bzkfxg-system-units.drv
  /nix/store/92gcsb32s5ac9w3dyacdi236zlbdw5pk-etc.drv
  /nix/store/5yp8ds46bqf61qaxlxbcs2gh4q3y92in-nixos-system-nixos-19.03.172927.30a82bba734.drv
building '/nix/store/i0kk0cg3wv23aj2y24wpsm7xqm8kiil3-postfix-main.cf.drv'...
building '/nix/store/2gam9pfyfa8pzi4mbikn319jxdqrc9ir-unit-script-postfix-pre-start.drv'...
building '/nix/store/i1dg5skdilyqrg9nnfqa1gp73ixfyxv1-unit-postfix.service.drv'...
building '/nix/store/8dqv3v93n6b7hv9wrr5s76zmb7bzkfxg-system-units.drv'...
building '/nix/store/92gcsb32s5ac9w3dyacdi236zlbdw5pk-etc.drv'...
building '/nix/store/5yp8ds46bqf61qaxlxbcs2gh4q3y92in-nixos-system-nixos-19.03.172927.30a82bba734.drv'...

[scintill@nixos:/etc/nixos]$ grep inet_protocols configuration.nix result/etc/postfix/main.cf /etc/postfix/main.cf ; ls -l result/etc/postfix/main.cf
configuration.nix:      inet_protocols = "ipv4";
result/etc/postfix/main.cf:inet_protocols = ipv6
/etc/postfix/main.cf:inet_protocols = ipv6
lrwxrwxrwx 1 root root 59 Jun 26 00:45 result/etc/postfix/main.cf -> /nix/store/abjppmrwp94lwh71jadh8yndqv8w9nzr-postfix-main.cf

# nixos-rebuild switch

[scintill@nixos:/etc/nixos]$ grep inet_protocols configuration.nix result/etc/postfix/main.cf /etc/postfix/main.cf ; ls -l result/etc/postfix/main.cf
configuration.nix:      inet_protocols = "ipv4";
result/etc/postfix/main.cf:inet_protocols = ipv4
/etc/postfix/main.cf:inet_protocols = ipv4
lrwxrwxrwx 1 root root 59 Jun 26 00:49 result/etc/postfix/main.cf -> /nix/store/vhpcrhxkg9rwxs48mhp6pncmn25vcisr-postfix-main.cf

It seems noteworthy that the symlink under result/ changes after “switch”, which I would think shouldn’t happen.

This is on the live CD nixos-minimal-19.03.172927.30a82bba734-i686-linux.iso with the following in /etc/nixos/configuration.nix

{ config, pkgs, ... }:

{
  imports = [ <nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix> ];

  services.openssh.enable = true;

  services.postfix = {
    enable = true;
    config = {
      smtpd_tls_received_header = true;
      inet_protocols = "ipv4";
    };
  };
}

Any ideas what’s going on? Thanks.

Edit: I think I found a clue:

[scintill@nixos:/etc/nixos]$ ls -l result result/etc result/etc/postfix result/etc/postfix/main.cf
lrwxrwxrwx 1 scintill users 87 Jun 26 00:47 result -> /nix/store/ql5w6dcyq63cjxzawj3krkkcmyhr34yp-nixos-system-nixos-19.03.172927.30a82bba734
lrwxrwxrwx 1 root     root  51 Jan  1  1970 result/etc -> /nix/store/917vsg9ywbhf7kqnxr40369cw67y042z-etc/etc
lrwxrwxrwx 1 root     root  21 Jan  1  1970 result/etc/postfix -> /var/lib/postfix/conf
lrwxrwxrwx 1 root     root  59 Jun 26 00:49 result/etc/postfix/main.cf -> /nix/store/vhpcrhxkg9rwxs48mhp6pncmn25vcisr-postfix-main.cf

result/etc/postfix symlinks to /var/lib/postfix/conf, which I did not expect. Where can I find the nixstore path of the newly built main.cf ?

I’m building a mailserver in NixOS and wanted to use nixos-rebuild build to preview my outputted configuration files before "switch"ing to them. I can’t get my changes to the nix file to show up in the output! nixos-rebuild switch does work, but I don’t want to actually switch until I check the output.

Looks like a bug in nixos-rebuild: it builds and computes the path of the new system instance but never prints it; not updating the result seems intentional, though.

Thanks. As far as I know, this command puts the output in a symlink named “result” in the working directory. It turns out the postfix package outputs a symlink to /var/postfix, so when I was trying to look in the result directory, it was actually resolving to the current live config via the /var symlink. I put a method to get the generated config in the edit at the top.