mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-10-03 02:57:30 +03:00
Merge pull request #180111 from Mic92/syncoid
syncoid: handle syncing dataset without a parent
This commit is contained in:
commit
e19518cdab
@ -16,11 +16,11 @@ let
|
|||||||
lib.concatMapStrings (s: if lib.isList s then "-" else s)
|
lib.concatMapStrings (s: if lib.isList s then "-" else s)
|
||||||
(builtins.split "[^a-zA-Z0-9_.\\-]+" name);
|
(builtins.split "[^a-zA-Z0-9_.\\-]+" name);
|
||||||
|
|
||||||
# Function to build "zfs allow" commands for the filesystems we've
|
# Function to build "zfs allow" commands for the filesystems we've delegated
|
||||||
# delegated permissions to. It also checks if the target dataset
|
# permissions to. It also checks if the target dataset exists before
|
||||||
# exists before delegating permissions, if it doesn't exist we
|
# delegating permissions, if it doesn't exist we delegate it to the parent
|
||||||
# delegate it to the parent dataset. This should solve the case of
|
# dataset (if it exists). This should solve the case of provisoning new
|
||||||
# provisoning new datasets.
|
# datasets.
|
||||||
buildAllowCommand = permissions: dataset: (
|
buildAllowCommand = permissions: dataset: (
|
||||||
"-+${pkgs.writeShellScript "zfs-allow-${dataset}" ''
|
"-+${pkgs.writeShellScript "zfs-allow-${dataset}" ''
|
||||||
# Here we explicitly use the booted system to guarantee the stable API needed by ZFS
|
# Here we explicitly use the booted system to guarantee the stable API needed by ZFS
|
||||||
@ -38,6 +38,7 @@ let
|
|||||||
(concatStringsSep "," permissions)
|
(concatStringsSep "," permissions)
|
||||||
dataset
|
dataset
|
||||||
]}
|
]}
|
||||||
|
${lib.optionalString ((builtins.dirOf dataset) != ".") ''
|
||||||
else
|
else
|
||||||
${lib.escapeShellArgs [
|
${lib.escapeShellArgs [
|
||||||
"/run/booted-system/sw/bin/zfs"
|
"/run/booted-system/sw/bin/zfs"
|
||||||
@ -47,6 +48,7 @@ let
|
|||||||
# Remove the last part of the path
|
# Remove the last part of the path
|
||||||
(builtins.dirOf dataset)
|
(builtins.dirOf dataset)
|
||||||
]}
|
]}
|
||||||
|
''}
|
||||||
fi
|
fi
|
||||||
''}"
|
''}"
|
||||||
);
|
);
|
||||||
@ -67,14 +69,14 @@ let
|
|||||||
(concatStringsSep "," permissions)
|
(concatStringsSep "," permissions)
|
||||||
dataset
|
dataset
|
||||||
]}
|
]}
|
||||||
${lib.escapeShellArgs [
|
${lib.optionalString ((builtins.dirOf dataset) != ".") (lib.escapeShellArgs [
|
||||||
"/run/booted-system/sw/bin/zfs"
|
"/run/booted-system/sw/bin/zfs"
|
||||||
"unallow"
|
"unallow"
|
||||||
cfg.user
|
cfg.user
|
||||||
(concatStringsSep "," permissions)
|
(concatStringsSep "," permissions)
|
||||||
# Remove the last part of the path
|
# Remove the last part of the path
|
||||||
(builtins.dirOf dataset)
|
(builtins.dirOf dataset)
|
||||||
]}
|
])}
|
||||||
''}"
|
''}"
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
|
@ -48,6 +48,9 @@ in {
|
|||||||
};
|
};
|
||||||
# Take snapshot and sync
|
# Take snapshot and sync
|
||||||
"pool/syncoid".target = "root@target:pool/syncoid";
|
"pool/syncoid".target = "root@target:pool/syncoid";
|
||||||
|
|
||||||
|
# Test pool without parent (regression test for https://github.com/NixOS/nixpkgs/pull/180111)
|
||||||
|
"pool".target = "root@target:pool/full-pool";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -105,6 +108,9 @@ in {
|
|||||||
source.systemctl("start --wait syncoid-pool-syncoid.service")
|
source.systemctl("start --wait syncoid-pool-syncoid.service")
|
||||||
target.succeed("cat /mnt/pool/syncoid/test.txt")
|
target.succeed("cat /mnt/pool/syncoid/test.txt")
|
||||||
|
|
||||||
|
source.systemctl("start --wait syncoid-pool.service")
|
||||||
|
target.succeed("[[ -d /mnt/pool/full-pool/syncoid ]]")
|
||||||
|
|
||||||
assert len(source.succeed("zfs allow pool")) == 0, "Pool shouldn't have delegated permissions set after syncing snapshots"
|
assert len(source.succeed("zfs allow pool")) == 0, "Pool shouldn't have delegated permissions set after syncing snapshots"
|
||||||
assert len(source.succeed("zfs allow pool/sanoid")) == 0, "Sanoid dataset shouldn't have delegated permissions set after syncing snapshots"
|
assert len(source.succeed("zfs allow pool/sanoid")) == 0, "Sanoid dataset shouldn't have delegated permissions set after syncing snapshots"
|
||||||
assert len(source.succeed("zfs allow pool/syncoid")) == 0, "Syncoid dataset shouldn't have delegated permissions set after syncing snapshots"
|
assert len(source.succeed("zfs allow pool/syncoid")) == 0, "Syncoid dataset shouldn't have delegated permissions set after syncing snapshots"
|
||||||
|
Loading…
Reference in New Issue
Block a user