diff options
author | Katharina Fey <kookie@spacekookie.de> | 2019-08-30 15:46:57 +0200 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2019-09-04 22:46:42 +0000 |
commit | 8f7da8ce0b310e7a64e4ab01a62122b70075083f (patch) | |
tree | f122a099eb0e037b286191b9e7f0f76c5ccc0c18 /nixos/modules/virtualisation | |
parent | 18f7f19ce2adc6d61d73cf993cec5de89869d86a (diff) |
nixos/railcar: init
Diffstat (limited to 'nixos/modules/virtualisation')
-rw-r--r-- | nixos/modules/virtualisation/railcar.nix | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/nixos/modules/virtualisation/railcar.nix b/nixos/modules/virtualisation/railcar.nix new file mode 100644 index 0000000000000..1508c171cc765 --- /dev/null +++ b/nixos/modules/virtualisation/railcar.nix @@ -0,0 +1,124 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.railcar; + generateUnit = name: containerConfig: + let + container = pkgs.ociTools.buildContainer { + args = [ + (pkgs.writeShellScript "run.sh" containerConfig.cmd).outPath + ]; + }; + in + nameValuePair "railcar-${name}" { + enable = true; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = '' + ${cfg.package}/bin/railcar -r ${cfg.stateDir} run ${name} -b ${container} + ''; + Type = containerConfig.runType; + }; + }; + mount = { + options = { + type = mkOption { + type = types.string; + default = "none"; + description = '' + The type of the filesystem to be mounted. + Linux: filesystem types supported by the kernel as listed in + `/proc/filesystems` (e.g., "minix", "ext2", "ext3", "jfs", "xfs", + "reiserfs", "msdos", "proc", "nfs", "iso9660"). For bind mounts + (when options include either bind or rbind), the type is a dummy, + often "none" (not listed in /proc/filesystems). + ''; + }; + source = mkOption { + type = types.string; + description = "Source for the in-container mount"; + }; + options = mkOption { + type = with types; loaOf (string); + default = [ "bind" ]; + description = '' + Mount options of the filesystem to be used. + + Support optoions are listed in the mount(8) man page. Note that both + filesystem-independent and filesystem-specific options are listed. + ''; + }; + }; + }; +in +{ + options.services.railcar = { + enable = mkEnableOption "railcar"; + + containers = mkOption { + default = {}; + description = "Declarative container configuration"; + type = with types; loaOf (submodule ({ name, config, ... }: { + options = { + cmd = mkOption { + type = types.string; + description = "Command or script to run inside the container"; + }; + + mounts = mkOption { + type = with types; attrsOf (submodule (mount)); + default = {}; + description = '' + A set of mounts inside the container. + + The defaults have been chosen for simple bindmounts, meaning + that you only need to provide the "source" parameter. + ''; + example = '' + { "/data" = { source = "/var/lib/data"; }; } + ''; + }; + + runType = mkOption { + type = types.string; + default = "oneshot"; + description = "The systemd service run type"; + }; + + os = mkOption { + type = types.string; + default = "linux"; + description = "OS type of the container"; + }; + + arch = mkOption { + type = types.string; + default = "x86_64"; + description = "Computer architecture type of the container"; + }; + }; + })); + }; + + stateDir = mkOption { + type = types.path; + default = ''/var/railcar''; + description = "Railcar persistent state directory"; + }; + + package = mkOption { + type = types.package; + default = pkgs.railcar; + description = "Railcar package to use"; + }; + }; + + config = mkIf cfg.enable { + systemd.services = flip mapAttrs' cfg.containers (name: containerConfig: + generateUnit name containerConfig + ); + }; +} + |