Help with Zrepl

Hi all, someone can help me to set zrepl? I’m using this with arch, Gentoo and feeebsd. I puted package and service.zrepl.enable on my configuration.nix but I didn’t understand how create its configuration file

The config file is created by its corresponding settings option.
https://search.nixos.org/options?channel=unstable&show=services.zrepl.settings&from=0&size=50&sort=relevance&type=packages&query=services.zrepl.settings

I’m using this model

but when I launch nixos-rebuild test I have a few errors, e.g. an error near jobs :

This afternoon I post correct error

There are errors:

[11:41:42] zar_marco :: nixgram  ➜  ~ » sudo nixos-rebuild test 
error:
       … while evaluating the attribute 'config'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: syntax error, unexpected '='

       at /etc/nixos/zrepl.nix:8:10:

            7|  jobs = [
            8|     name = "snapjob";
             |          ^
            9|     type = "snap";
building Nix...
error:
       … while evaluating the attribute 'config'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: syntax error, unexpected '='

       at /etc/nixos/zrepl.nix:8:10:

            7|  jobs = [
            8|     name = "snapjob";
             |          ^
            9|     type = "snap";
building the system configuration...
error:
       … while evaluating the attribute 'config.system.build.toplevel'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: syntax error, unexpected '='

       at /etc/nixos/zrepl.nix:8:10:

            7|  jobs = [
            8|     name = "snapjob";
             |          ^
            9|     type = "snap";

and this is my zrepl.nix file
`[11:44:43] zar_marco :: nixgram ➜ ~ » cat /etc/nixos/zrepl.nix
{ config, pkgs, lib, … }:

{

services.zrepl.settings = {

jobs = [
name = “snapjob”;
type = “snap”;
filesystems: {
“rpool/root/nixos”: true,
“rpool/data/nixos-home”: true,
“rpool/data/condivise”: true,
}
snapshotting:
type: periodic
interval: 30m
prefix: zrepl_snapjob_
pruning:
keep:
- type: last_n
count: 20
]
};
}
``

The linked snippet seems to be no valid nix.
You could peek on my config. nix-configuration/machines/tank/configuration.nix at 6f155193b2f261e22e0ae162e2d0a9a26d900484 · Shawn8901/nix-configuration · GitHub

The nix code will be translated to yaml by the module

1 Like

Thanks so much, I generated setting correctly. Now I must understand how enable systemd service

Sorry, I’ve this error that I don’t know

[17:25:32] zar_marco :: nixgram  ➜  ~ » systemctl status zrepl.service                 
○ zrepl.service - zrepl daemon
     Loaded: loaded (/etc/systemd/system/zrepl.service; enabled; preset: enabled)
    Drop-In: /nix/store/p1mpzax6sjblibiv7gpi5iskkc4vl2wg-system-units/zrepl.service.d
             └─overrides.conf
     Active: inactive (dead) since Mon 2024-04-01 17:20:34 CEST; 5min ago
       Docs: https://zrepl.github.io
    Process: 4860 ExecStartPre=/nix/store/hnwbdspbqacr1b84c2q0ziss93k21mvs-zrepl-0.6.1/bin/zrepl --config /etc/zrepl/zrepl.yml configcheck (co>
         IP: 0B in, 0B out
        CPU: 30ms

apr 01 17:20:34 nixgram systemd[1]: zrepl.service: Scheduled restart job, restart counter is at 5.
apr 01 17:20:34 nixgram systemd[1]: zrepl.service: Start request repeated too quickly.
apr 01 17:20:34 nixgram systemd[1]: zrepl.service: Failed with result 'exit-code'.
apr 01 17:20:34 nixgram systemd[1]: Failed to start zrepl daemon.
[17:25:47] zar_marco :: nixgram  ➜  ~ »                           

can I fixed this?

Now I must understand how enable systemd service

The module already enables the systems service, there should not be any need of manual intervention. Just activate the config switch switch or test, or enable it with boot and reboot.

Sorry, I’ve this error that I don’t know

Posting an actual error could be helpful. You now have postet “sorry I can not start, there is something wrong with config” (pre check fails)

It would be also interesting what systems override you have applied

Ok this is the error:

[18:13:49] zar_marco :: nixgram  ➜  ~ » systemctl status zrepl.service                                                                                                                                                                                                                                                  3 ↵
× zrepl.service - zrepl daemon
     Loaded: loaded (/etc/systemd/system/zrepl.service; enabled; preset: enabled)
    Drop-In: /nix/store/p1mpzax6sjblibiv7gpi5iskkc4vl2wg-system-units/zrepl.service.d
             └─overrides.conf
     Active: failed (Result: exit-code) since Mon 2024-04-01 18:08:31 CEST; 5min ago
       Docs: https://zrepl.github.io
    Process: 1730 ExecStartPre=/nix/store/hnwbdspbqacr1b84c2q0ziss93k21mvs-zrepl-0.6.1/bin/zrepl --config /etc/zrepl/zrepl.yml configcheck (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 17ms

apr 01 18:08:31 nixgram systemd[1]: zrepl.service: Scheduled restart job, restart counter is at 5.
apr 01 18:08:31 nixgram systemd[1]: zrepl.service: Start request repeated too quickly.
apr 01 18:08:31 nixgram systemd[1]: zrepl.service: Failed with result 'exit-code'.
apr 01 18:08:31 nixgram systemd[1]: Failed to start zrepl daemon.

there are my configuration for nixos:
configuration.nix

# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      ./users.nix
      ./desktop.nix 
      ./package.nix
      ./tlp.nix
      ./zrepl.nix
    ];
  boot.loader.grub = {
    enable = true;
    zfsSupport = true;
    efiSupport = true;
    efiInstallAsRemovable = true;
    mirroredBoots = [
      { devices = [ "nodev"]; path = "/boot/efi"; }
    ];
  };
  networking.hostId = "00bab10c";
 boot.zfs.extraPools = [ "rpool" ];
  # Use the systemd-boot EFI boot loader.
  #boot.loader.systemd-boot.enable = true;
  #boot.loader.efi.canTouchEfiVariables = true;
 
  hardware.bluetooth.enable = true; # enables support for Bluetooth
  hardware.bluetooth.powerOnBoot = true; # powers up the default Bluetooth controller on boot
  services.blueman.enable = true;
  
  hardware.bluetooth.settings = {
	General = {
		Experimental = true;
	};
   };
   
   networking.hostName = "nixgram"; # Define your hostname.
  # Pick only one of the below networking options.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.
  # networking.networkmanager.enable = true;  # Easiest to use and most distros use this by default.

  nixpkgs.config.allowUnfree = true; #needed for nvidia drivers  
 
  # tlp service
  services.tlp.enable = true;

  services.power-profiles-daemon.enable = false;
  
  services.zrepl.enable = true;
  services.zrepl.package = pkgs.zrepl;
  
  services.flatpak.enable = true;
  services.packagekit.enable = true;  

  # thunderbolt
  services.hardware.bolt.enable = true;
 
 # Set your time zone.
  time.timeZone = "Europe/Rome";

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
  networking.networkmanager.enable = true;

  # Select internationalisation properties.
   i18n.defaultLocale = "it_IT.UTF-8";
   console = {
     font = "Lat2-Terminus16";
    # keyMap = "it";
     useXkbConfig = true; # use xkbOptions in tty.
   };

  # Enable the X11 windowing system.
  services.xserver.enable = true;
  

  # Configure keymap in X11
 #  services.xserver.layout = "it";
  # services.xserver.xkbOptions = {
  #   "eurosign:e";
  #   "caps:escape" # map caps to escape.
  # };

  # Enable CUPS to print documents.
  # services.printing.enable = true;

  # Enable sound.
   sound.enable = true;
   hardware.pulseaudio.enable = true;

  # Enable touchpad support (enabled default in most desktopManager).
  services.xserver.libinput.enable = true;
programs.zsh.enable = true;
 users.extraUsers.root = {
      shell = pkgs.zsh;
    };
 

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  # environment.systemPackages = with pkgs; [
  #   vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
  #   wget
  # ];

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  # services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  # Copy the NixOS configuration file and link it from the resulting system
  # (/run/current-system/configuration.nix). This is useful in case you
  # accidentally delete configuration.nix.
  # system.copySystemConfiguration = true;

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "23.11"; # Did you read the comment?

}


and this zrepl.nix:

{ config, pkgs, lib,  ... }:


{
services.zrepl.settings = {

 jobs = [
  { 
    name = "snapjob";
    type = "snap";
    filesystems = {
     "rpool/root/nixos"= true;
     "rpool/data/nixos-home"= true;
     "rpool/data/condivise"= true;
  };
  snapshotting = [
   {
    type = "periodic";
    interval= "30m";
    prefix= "zrepl_snapjob_";
  pruning=
   { 
   keep = [
   { 
        type= "last_n";
        count= "20";
}
];
};
}
];
}
];
};
}

and there are my dataset:

[18:13:51] zar_marco :: nixgram  ➜  ~ » zfs list                                                                                                                                                                                                                                                                        3 ↵
NAME                       USED  AVAIL  REFER  MOUNTPOINT
rpool                      268G   631G    96K  none
rpool/data                 167G   631G    96K  none
rpool/data/arch-home-old  18.7G   631G  16.9G  legacy
rpool/data/condivise       122G   631G   122G  legacy
rpool/data/gentoo-home    2.55G   631G  1.93G  legacy
rpool/data/gentooD-home   11.1G   631G  10.5G  legacy
rpool/data/gentoorc-home  1.84G   631G  1.32G  legacy
rpool/data/nixos-home     1.00G   631G  1.00G  legacy
rpool/data/void-home      10.3G   631G  8.44G  legacy
rpool/root                 101G   631G    96K  none
rpool/root/arch-old       23.5G   631G  16.5G  /
rpool/root/gentooD        32.8G   631G  32.3G  /
rpool/root/gentoorc       11.6G   631G  10.7G  /
rpool/root/nixos          17.0G   631G  17.0G  /
rpool/root/void           16.1G   631G  11.5G  /

Sorry, but, someone using zrepl? Someone Who ever restored a snapshot?

I can not extract a specific question that I am able to answer here.
Restoring of a snapshot does not have a direct relations to zrepl, it’s just meant for taking snapshots and replicating them.

To restore you need to use the built-in zfs tools.
Raising a specific question or describing a scenario that you are in might help.
It think that we are facing a xy problem otherwise.

1 Like

Second question is my fault, I’m wrong to write in this thread. Anyway tomorrow I will try with zrepl, because currently zrepl service fault on my system, with error how I wrote a few days ago

You should check what pre checks are failing. That could either be done by manually running them (see command in the systems unit) or check if the fails are mentioned in journalctl -u zrepl

For context, the zrepl service checks if the configuration is valid before starting. That seems not to be the case for your config according the provided log snippets

apr 01 18:08:31 nixgram systemd[1]: zrepl.service: Scheduled restart job, restart counter is at 5.
apr 01 18:08:31 nixgram systemd[1]: zrepl.service: Start request repeated too quickly.
apr 01 18:08:31 nixgram systemd[1]: zrepl.service: Failed with result ‘exit-code’.

I don’t understand these three errors

Systemd is saying that it tried to start zrepl 5 times and now stop doing so, as it stopped “to quickly” as it never has started.
That is all just partly related to zrepl. Those are logs from systemd.

Zrepl is not starting due to the failing pre check (according the log you showed few days ago).
The task is to check what the configcheck (preStart command) is complaining about.

░░ L'unità zrepl.service ha iniziato la fase di avvio.
apr 26 10:49:20 nixgram zrepl[3874]: could not parse config: yaml: unmarshal errors:
apr 26 10:49:20 nixgram zrepl[3874]:   line 8: cannot unmarshal !!seq into struct { Type string }
apr 26 10:49:20 nixgram zrepl[3874]:   line 1: field pruning is required but not given
apr 26 10:49:20 nixgram zrepl[3874]:   line 1: field snapshotting is required but has zero value
apr 26 10:49:20 nixgram zrepl[3874]:   line 0: field jobs is required but has zero value
apr 26 10:49:20 nixgram systemd[1]: zrepl.service: Control process exited, code=exited, status=1/FAILURE

I’ve these errors, have I problems with configs?

Yes, your current configuration is invalid for zrepl.
Which exact problems it has, is shown there per line.
Be aware that zrepl inspects the zrepl.yaml in /etc/zrepl that is generated from your nix configuration (so you need to translate it to your nix config).
For that I recommend to compare the generated yaml with your nix config.

Really I don’t understand, this is my configuration.nix with zrepl config

# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
     
      ./hardware-configuration.nix
      ./users.nix
      ./desktop.nix 
      ./package.nix
      ./tlp.nix
      #./zrepl.nix
    ];
  boot.loader.grub = {
    enable = true;
    zfsSupport = true;
    efiSupport = true;
    efiInstallAsRemovable = true;
    mirroredBoots = [
      { devices = [ "nodev"]; path = "/boot"; }
    ];
  };
  networking.hostId = "00bab10c";
  boot.zfs.extraPools = [ "ipool" ];
  boot.kernelParams = [ "zfs.zfs_arc_max=12884901888" ];
  # Use the systemd-boot EFI boot loader.
  #boot.loader.systemd-boot.enable = true;
  #boot.loader.efi.canTouchEfiVariables = true;
 
 # boot.kernelPackages = pkgs.linuxKernel.packages.linux_6_8.zfs;
  boot.kernelPackages = pkgs.linuxPackages_latest;
 
  nix.settings.experimental-features = [ "nix-command" "flakes" ];

  nixpkgs.config.allowBroken = true;

  hardware.bluetooth.enable = true; # enables support for Bluetooth
  hardware.bluetooth.powerOnBoot = true; # powers up the default Bluetooth controller on boot
  services.blueman.enable = true;
  


  hardware.bluetooth.settings = {
	General = {
		Experimental = true;
	};
   };
   
   networking.hostName = "nixgram"; # Define your hostname.
  # Pick only one of the below networking options.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.
  # networking.networkmanager.enable = true;  # Easiest to use and most distros use this by default.

  nixpkgs.config.allowUnfree = true; #needed for nvidia drivers  
 
  # tlp service
  services.tlp.enable = true;

  system.autoUpgrade.enable = true;
  system.autoUpgrade.allowReboot = false;

  services.power-profiles-daemon.enable = false;
  
  services.zrepl.enable = true;
  services.zrepl.package = pkgs.zrepl;
  services.zrepl.settings = {

    jobs = [
      { 
        name = "snapjob";
        type = "snap";
        filesystems = {
        "ipool/nixos/root"= true;
        "ipool/nixos/home"= true;
        "ipool/condivise"= true;
        };
       snapshotting = [
        {
          type = "periodic";
          interval= "30m";
          prefix= "zrepl_snapjob_";
        pruning=
        { 
          keep = [
            { 
              type= "last_n";
              count= "20";
            }
          ];
          };
        }
      ];
     }
    ];
  };
  
  services.flatpak.enable = true;
  services.packagekit.enable = true;  

  # thunderbolt
  services.hardware.bolt.enable = true;
 
 # Set your time zone.
  time.timeZone = "Europe/Rome";

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
  networking.networkmanager.enable = true;

  # Select internationalisation properties.
   i18n.defaultLocale = "it_IT.UTF-8";
   console = {
     font = "Lat2-Terminus16";
     #keyMap = "it";
     useXkbConfig = true; # use xkbOptions in tty.
   };

  # Enable the X11 windowing system.
  services.xserver.enable = true;
  

  # Configure keymap in X11
 #  services.xserver.layout = "it";
  # services.xserver.xkbOptions = {
  #   "eurosign:e";
  #   "caps:escape" # map caps to escape.
  # };

  # Enable CUPS to print documents.
  # services.printing.enable = true;

  # Enable sound.
   #sound.enable = true;
   #hardware.pulseaudio.enable = true;
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # If you want to use JACK applications, uncomment this
    jack.enable = true;
  };
  # Enable touchpad support (enabled default in most desktopManager).
  services.xserver.libinput.enable = true;
programs.zsh.enable = true;
 users.extraUsers.root = {
      shell = pkgs.zsh;
    };
  
  users.extraUsers = {
     marco = {
      isNormalUser = true;
      uid = 1000;
      extraGroups = [ "wheel" "users" "networkmanager" ];
      shell = pkgs.zsh;
    };
  };

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  # environment.systemPackages = with pkgs; [
  #   vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
  #   wget
  # ];

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  # services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  # Copy the NixOS configuration file and link it from the resulting system
  # (/run/current-system/configuration.nix). This is useful in case you
  # accidentally delete configuration.nix.
  # system.copySystemConfiguration = true;

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "24.05"; # Did you read the comment?

}

this is /etc/zrepl/zrepl.yml

│ File: /etc/zrepl/zrepl.yml
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ jobs:
   2   │ - filesystems:
   3   │     ipool/condivise: true
   4   │     ipool/nixos/home: true
   5   │     ipool/nixos/root: true
   6   │   name: snapjob
   7   │   snapshotting:
   8   │   - interval: 30m
   9   │     prefix: zrepl_snapjob_
  10   │     pruning:
  11   │       keep:
  12   │       - count: '20'
  13   │         type: last_n
  14   │     type: periodic
  15   │   type: snap

how wrong?

for example, this is my configuration on arch

   1   │ jobs:
   2   │ - name: snapjob
   3   │   type: snap
   4   │   filesystems: {
   5   │     "ipool/arch/root": true,
   6   │     "ipool/arch/home": true,
   7   │     "ipool/condivise": true,
   8   │   }
   9   │   snapshotting:
  10   │     type: periodic
  11   │     interval: 30m
  12   │     prefix: zrepl_snapjob_
  13   │   pruning:
  14   │     keep:
  15   │       - type: last_n
  16   │         count: 20

I think that problem is how configuration.nix write /etc/zrepl/zrepl.yml

There is an “error” in your nix config here.
As nix does not know what a valid zrepl yaml looks like, it can not tell you when building the config.
That does the configcheck on service start.

Try this snippet

{
  config,
  pkgs,
  lib,
  ...
}:

{
  services.zrepl.settings = {
    jobs = [
      {
        name = "snapjob";
        type = "snap";
        filesystems = {
          "rpool/root/nixos" = true;
          "rpool/data/nixos-home" = true;
          "rpool/data/condivise" = true;
        };
        snapshotting = {
          type = "periodic";
          interval = "30m";
          prefix = "zrepl_snapjob_";
        };
        pruning = {
          keep = [
            {
              type = "last_n";
              count = 20;
            }
          ];
        };
      }
    ];
  };
}

That should translate to the same config like the arch snippet that you have provided.

I recommend, that you use a formatter that is capable to format some nix code, then you might have spotted the problem quite easily (i assume that its not formatted, as you pasted it to the discourse unformatted)

1 Like

Thanks so much, I made an error with [ ]