ZFS: Difference between revisions

imported>2r
stateless root
imported>2r
immutable root
Line 62: Line 62:


'''Optional''': stateless home directory.  This requires you to keep track of your dot files with a version control system.  Git is used here as an example.
'''Optional''': stateless home directory.  This requires you to keep track of your dot files with a version control system.  Git is used here as an example.
<syntaxhighlight lang="nix">
## In /etc/nixos/configuration.nix:
## Manage home with home-manager
  environment.systemPackages = with pkgs; [
    home-manager
  ];
## Disable mutable users
  users.mutableUsers = false;
## Password hashes now need to be declared in config
## generate hash with mkpasswd -m SHA-512 -s
    users.users.myUser.initialHashedPassword = "HASH";
## New service to fix home permissions
  systemd.services.home-perm = {
    enable = true;
    description = "Fix home dir permission";
    wantedBy = [ "multi-user.target" ];
    path = [ pkgs.coreutils pkgs.git ];
    after = [ "local-fs.target" ];
    serviceConfig = {
      ExecStart = ''/bin/sh -c "git -C /home/myUser reset --hard; chown -R myUser:users /home/myUser; chmod  700 /home/myUser"'';
      User = "root";
      Type = "oneshot";
      PrivateTmp = "true";
      ProtectSystem = "full";
      WorkingDirectory = "/tmp";
    };
  };
</syntaxhighlight>
<syntaxhighlight lang="nix">
## In /etc/nixos/hardware-configuration.nix:
  fileSystems."/home/myUser" = {
    device = "none";
    fsType = "tmpfs";
    options = [ "defaults" "size=1G" "mode=755" "X-mount=mkdir" ];
  };
  fileSystems."/home/myUser/.git" = {
    device = "/altroot/home/myUser/.git";
    fsType = "none";
    options = [ "bind" "X-mount.mkdir" ];
  };
  fileSystems."/home/myUser/Downloads" = {
    device = "/altroot/home/myUser/Downloads";
    fsType = "none";
    options = [ "bind" "X-mount.mkdir" ];
  };
  fileSystems."/home/myUser/Documents" = {
    device = "/altroot/home/myUser/Documents";
    fsType = "none";
    options = [ "bind" "X-mount.mkdir" ];
  };
</syntaxhighlight>


== Mount datasets at boot ==
== Mount datasets at boot ==