From c03ca68795820b4af8c4d6576434204d1a2051ba Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 13 Feb 2019 18:29:54 +0700 Subject: [PATCH] Move uid and customNixRootPath into config.host module Also make the type of host.uid consistently int. --- src/nix/eval-composition.nix | 7 ++-- .../modules/composition/docker-compose.nix | 6 ++-- .../modules/composition/host-environment.nix | 32 +++++++++++++++++++ src/nix/modules/service/host-store.nix | 6 ++-- src/nix/modules/service/host.nix | 11 +++++++ 5 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 src/nix/modules/composition/host-environment.nix create mode 100644 src/nix/modules/service/host.nix diff --git a/src/nix/eval-composition.nix b/src/nix/eval-composition.nix index 349a414..56e2538 100644 --- a/src/nix/eval-composition.nix +++ b/src/nix/eval-composition.nix @@ -1,4 +1,4 @@ -{ modules ? [], uid ? 0, pkgs, customNixRootPath ? "", }: +{ modules ? [], uid ? "0", pkgs, hostNixStorePrefix ? "", }: let _pkgs = pkgs; in @@ -19,14 +19,15 @@ let builtinModules = [ argsModule ./modules/composition/docker-compose.nix + ./modules/composition/host-environment.nix ]; argsModule = { _file = ./eval-composition.nix; key = ./eval-composition.nix; config._module.args.pkgs = lib.mkIf (pkgs != null) (lib.mkForce pkgs); - config._module.args.uid = uid; - config._module.args.customNixRootPath = customNixRootPath; + config.host.nixStorePrefix = hostNixStorePrefix; + config.host.uid = lib.toInt uid; }; in diff --git a/src/nix/modules/composition/docker-compose.nix b/src/nix/modules/composition/docker-compose.nix index af4e896..63aeace 100644 --- a/src/nix/modules/composition/docker-compose.nix +++ b/src/nix/modules/composition/docker-compose.nix @@ -9,7 +9,7 @@ - docker-compose.services */ -{ pkgs, uid, lib, config, customNixRootPath, ... }: +{ pkgs, lib, config, ... }: let evalService = name: modules: @@ -23,14 +23,14 @@ let argsModule ../service/docker-compose-service.nix ../service/host-store.nix + ../service/host.nix ]; argsModule = { _file = ./docker-compose.nix; key = ./docker-compose.nix; config._module.args.pkgs = lib.mkForce pkgs; - config._module.args.uid = uid; - config._module.args.customNixRootPath = customNixRootPath; + config.host = config.host; }; in diff --git a/src/nix/modules/composition/host-environment.nix b/src/nix/modules/composition/host-environment.nix new file mode 100644 index 0000000..16bf23e --- /dev/null +++ b/src/nix/modules/composition/host-environment.nix @@ -0,0 +1,32 @@ +{ lib, ... }: + +{ + options = { + + host.uid = lib.mkOption { + type = lib.types.int; + description = '' + The numeric user id (UID) of the user running arion. + + Assuming this user id is helpful when dealing with the user's + files, mounted into the container as a volume. + ''; + }; + + host.nixStorePrefix = lib.mkOption { + type = lib.types.string; + default = ""; + example = "/mnt/foo"; + description = '' + Prefixes store paths on the host, allowing the Nix store to be + stored at an alternate location without altering the format of + store paths. + + For example: instead of mounting the host's /nix/store as the + container's /nix/store, this will mount /mnt/foo/nix/store + as the container's /nix/store. + ''; + }; + + }; +} diff --git a/src/nix/modules/service/host-store.nix b/src/nix/modules/service/host-store.nix index f837a81..ae6a1e5 100644 --- a/src/nix/modules/service/host-store.nix +++ b/src/nix/modules/service/host-store.nix @@ -4,7 +4,7 @@ when the service.useHostStore option is set to true. */ -{ lib, config, pkgs, customNixRootPath, ... }: +{ lib, config, pkgs, ... }: let inherit (lib) mkOption types mkIf; @@ -21,8 +21,8 @@ in service.image = "arion-base"; service.build.context = "${../../../arion-image}"; service.volumes = [ - "${customNixRootPath}/nix/store:/nix/store" - "${customNixRootPath}${pkgs.buildEnv { name = "container-system-env"; paths = [ pkgs.bashInteractive pkgs.coreutils ]; }}:/run/system" + "${config.host.nixStorePrefix}/nix/store:/nix/store" + "${config.host.nixStorePrefix}${pkgs.buildEnv { name = "container-system-env"; paths = [ pkgs.bashInteractive pkgs.coreutils ]; }}:/run/system" ]; }; } diff --git a/src/nix/modules/service/host.nix b/src/nix/modules/service/host.nix new file mode 100644 index 0000000..3ba2ee8 --- /dev/null +++ b/src/nix/modules/service/host.nix @@ -0,0 +1,11 @@ +{ lib, ... }: +{ + options = { + host = lib.mkOption { + type = lib.types.attrs; + description = '' + The composition-level host option values. + ''; + }; + }; +}