nixos-container: rename extraBinds to bindMounts and use attribute set format.
This commit is contained in:
parent
c4f66eb85d
commit
4d551227c9
@ -41,8 +41,40 @@ let
|
|||||||
|
|
||||||
system = config.nixpkgs.system;
|
system = config.nixpkgs.system;
|
||||||
|
|
||||||
mkBindFlag = d: if d.isReadOnly then " --bind-ro=${d.host}:${d.container}" else " --bind=${d.host}:${d.container}";
|
bindMountOpts = { name, config, ... }: {
|
||||||
mkBindFlags = bs: concatMapStrings mkBindFlag bs;
|
|
||||||
|
options = {
|
||||||
|
mountPoint = mkOption {
|
||||||
|
example = "/mnt/usb";
|
||||||
|
type = types.str;
|
||||||
|
description = "Location of the mounted in the container file systems";
|
||||||
|
};
|
||||||
|
hostPath = mkOption {
|
||||||
|
default = null;
|
||||||
|
example = "/home/alice";
|
||||||
|
type = types.uniq (types.nullOr types.string);
|
||||||
|
description = "Location of the host path to be mounted";
|
||||||
|
};
|
||||||
|
isReadOnly = mkOption {
|
||||||
|
default = false;
|
||||||
|
example = true;
|
||||||
|
type = types.bool;
|
||||||
|
description = "Determine whether the mounted path will be accessed in read-only mode";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
mountPoint = mkDefault name;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
mkBindFlag = d:
|
||||||
|
let flagPrefix = if d.isReadOnly then " --bind-ro=" else " --bind=";
|
||||||
|
mountstr = if d.hostPath != null then "${d.hostPath}:${d.mountPoint}" else "${d.mountPoint}";
|
||||||
|
in flagPrefix + mountstr ;
|
||||||
|
|
||||||
|
mkBindFlags = bs: concatMapStrings mkBindFlag (lib.attrValues bs);
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
@ -131,29 +163,20 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
extraBinds = mkOption {
|
bindMounts = mkOption {
|
||||||
type = types.listOf types.attrs;
|
type = types.loaOf types.optionSet;
|
||||||
default = [];
|
options = [ bindMountOpts ];
|
||||||
example = [ { host = "/home/alice";
|
default = {};
|
||||||
container = "/home";
|
example = { "/home" = { hostPath = "/home/alice";
|
||||||
isReadOnly = false; }
|
isReadOnly = false; };
|
||||||
];
|
};
|
||||||
|
|
||||||
description =
|
description =
|
||||||
''
|
''
|
||||||
An extra list of directories that is bound to the container.
|
An extra list of directories that is bound to the container.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
#extraBindsRW = mkOption {
|
|
||||||
# type = types.listOf types.str;
|
|
||||||
# default = [];
|
|
||||||
# example = [ "/home/alice" ];
|
|
||||||
# description =
|
|
||||||
# ''
|
|
||||||
# An extra list of directories that is bound to the container with read-only permission.
|
|
||||||
# '';
|
|
||||||
#};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkMerge
|
config = mkMerge
|
||||||
@ -265,7 +288,7 @@ in
|
|||||||
exec ${config.systemd.package}/bin/systemd-nspawn \
|
exec ${config.systemd.package}/bin/systemd-nspawn \
|
||||||
--keep-unit \
|
--keep-unit \
|
||||||
-M "$INSTANCE" -D "$root" $extraFlags \
|
-M "$INSTANCE" -D "$root" $extraFlags \
|
||||||
$EXTRABINDS \
|
$EXTRABINDS \
|
||||||
--bind-ro=/nix/store \
|
--bind-ro=/nix/store \
|
||||||
--bind-ro=/nix/var/nix/db \
|
--bind-ro=/nix/var/nix/db \
|
||||||
--bind-ro=/nix/var/nix/daemon-socket \
|
--bind-ro=/nix/var/nix/daemon-socket \
|
||||||
@ -365,14 +388,11 @@ in
|
|||||||
AUTO_START=1
|
AUTO_START=1
|
||||||
''}
|
''}
|
||||||
|
|
||||||
EXTRABINDS="${mkBindFlags cfg.extraBinds}"
|
EXTRABINDS="${mkBindFlags cfg.bindMounts}"
|
||||||
|
|
||||||
'';
|
'';
|
||||||
}) config.containers;
|
}) config.containers;
|
||||||
|
|
||||||
#"${concatMapStrings (d: " --bind-ro=${d}") cfg.extraBindsRO + concatMapStrings (d: " --bind=${d}") cfg.extraBindsRW}"
|
|
||||||
|
|
||||||
|
|
||||||
# Generate /etc/hosts entries for the containers.
|
# Generate /etc/hosts entries for the containers.
|
||||||
networking.extraHosts = concatStrings (mapAttrsToList (name: cfg: optionalString (cfg.localAddress != null)
|
networking.extraHosts = concatStrings (mapAttrsToList (name: cfg: optionalString (cfg.localAddress != null)
|
||||||
''
|
''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user