From 59f97876e31e52156ac933edd9a4f2d41312502c Mon Sep 17 00:00:00 2001 From: Serhii Khoma Date: Wed, 13 Feb 2019 11:04:17 +0200 Subject: [PATCH 1/3] feat: custom nix store --- src/nix/docker-compose-module.nix | 3 ++- src/nix/eval-composition.nix | 3 ++- src/nix/service-host-store.nix | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/nix/docker-compose-module.nix b/src/nix/docker-compose-module.nix index 159ff26..c76e36f 100644 --- a/src/nix/docker-compose-module.nix +++ b/src/nix/docker-compose-module.nix @@ -9,7 +9,7 @@ - docker-compose.services */ -{ pkgs, uid, lib, config, ... }: +{ pkgs, uid, lib, config, customNixRootPath, ... }: let evalService = name: modules: @@ -30,6 +30,7 @@ let key = ./docker-compose-module.nix; config._module.args.pkgs = lib.mkForce pkgs; config._module.args.uid = uid; + config._module.args.customNixRootPath = customNixRootPath; }; in diff --git a/src/nix/eval-composition.nix b/src/nix/eval-composition.nix index c6cf620..d8bb6f2 100644 --- a/src/nix/eval-composition.nix +++ b/src/nix/eval-composition.nix @@ -1,4 +1,4 @@ -{ modules ? [], uid ? 0, pkgs }: +{ modules ? [], uid ? 0, pkgs, customNixRootPath ? "", }: let _pkgs = pkgs; in @@ -26,6 +26,7 @@ let 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; }; in diff --git a/src/nix/service-host-store.nix b/src/nix/service-host-store.nix index e650d78..5a06bdb 100644 --- a/src/nix/service-host-store.nix +++ b/src/nix/service-host-store.nix @@ -4,7 +4,8 @@ when the service.useHostStore option is set to true. */ -{ lib, config, pkgs, ... }: +{ lib, config, pkgs, customNixRootPath, ... }: + let inherit (lib) mkOption types mkIf; in @@ -20,8 +21,8 @@ in service.image = "arion-base"; service.build.context = "${../arion-image}"; service.volumes = [ - "/nix/store:/nix/store" - "${pkgs.buildEnv { name = "container-system-env"; paths = [ pkgs.bashInteractive pkgs.coreutils ]; }}:/run/system" + "${customNixRootPath}/nix/store:/nix/store" + "${customNixRootPath}${pkgs.buildEnv { name = "container-system-env"; paths = [ pkgs.bashInteractive pkgs.coreutils ]; }}:/run/system" ]; }; } From 359c8b601d0fa94fc33e6683f5f61320ccd618bb Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 13 Feb 2019 17:33:19 +0700 Subject: [PATCH 2/3] Move modules into modules/{composition,service} --- src/nix/eval-composition.nix | 2 +- .../composition/docker-compose.nix} | 8 ++++---- .../service/docker-compose-service.nix} | 0 .../service/host-store.nix} | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename src/nix/{docker-compose-module.nix => modules/composition/docker-compose.nix} (90%) rename src/nix/{service.nix => modules/service/docker-compose-service.nix} (100%) rename src/nix/{service-host-store.nix => modules/service/host-store.nix} (92%) diff --git a/src/nix/eval-composition.nix b/src/nix/eval-composition.nix index d8bb6f2..349a414 100644 --- a/src/nix/eval-composition.nix +++ b/src/nix/eval-composition.nix @@ -18,7 +18,7 @@ let builtinModules = [ argsModule - ./docker-compose-module.nix + ./modules/composition/docker-compose.nix ]; argsModule = { diff --git a/src/nix/docker-compose-module.nix b/src/nix/modules/composition/docker-compose.nix similarity index 90% rename from src/nix/docker-compose-module.nix rename to src/nix/modules/composition/docker-compose.nix index c76e36f..af4e896 100644 --- a/src/nix/docker-compose-module.nix +++ b/src/nix/modules/composition/docker-compose.nix @@ -21,13 +21,13 @@ let builtinModules = [ argsModule - ./service.nix - ./service-host-store.nix + ../service/docker-compose-service.nix + ../service/host-store.nix ]; argsModule = { - _file = ./docker-compose-module.nix; - key = ./docker-compose-module.nix; + _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; diff --git a/src/nix/service.nix b/src/nix/modules/service/docker-compose-service.nix similarity index 100% rename from src/nix/service.nix rename to src/nix/modules/service/docker-compose-service.nix diff --git a/src/nix/service-host-store.nix b/src/nix/modules/service/host-store.nix similarity index 92% rename from src/nix/service-host-store.nix rename to src/nix/modules/service/host-store.nix index 5a06bdb..f837a81 100644 --- a/src/nix/service-host-store.nix +++ b/src/nix/modules/service/host-store.nix @@ -19,7 +19,7 @@ in }; config = mkIf config.service.useHostStore { service.image = "arion-base"; - service.build.context = "${../arion-image}"; + 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" From c03ca68795820b4af8c4d6576434204d1a2051ba Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 13 Feb 2019 18:29:54 +0700 Subject: [PATCH 3/3] 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. + ''; + }; + }; +}