diff --git a/src/nix/eval-composition.nix b/src/nix/eval-composition.nix index c6cf620..56e2538 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, hostNixStorePrefix ? "", }: let _pkgs = pkgs; in @@ -18,14 +18,16 @@ let builtinModules = [ argsModule - ./docker-compose-module.nix + ./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.host.nixStorePrefix = hostNixStorePrefix; + config.host.uid = lib.toInt uid; }; in diff --git a/src/nix/docker-compose-module.nix b/src/nix/modules/composition/docker-compose.nix similarity index 84% rename from src/nix/docker-compose-module.nix rename to src/nix/modules/composition/docker-compose.nix index 159ff26..63aeace 100644 --- a/src/nix/docker-compose-module.nix +++ b/src/nix/modules/composition/docker-compose.nix @@ -9,7 +9,7 @@ - docker-compose.services */ -{ pkgs, uid, lib, config, ... }: +{ pkgs, lib, config, ... }: let evalService = name: modules: @@ -21,15 +21,16 @@ let builtinModules = [ argsModule - ./service.nix - ./service-host-store.nix + ../service/docker-compose-service.nix + ../service/host-store.nix + ../service/host.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.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/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 66% rename from src/nix/service-host-store.nix rename to src/nix/modules/service/host-store.nix index e650d78..ae6a1e5 100644 --- a/src/nix/service-host-store.nix +++ b/src/nix/modules/service/host-store.nix @@ -5,6 +5,7 @@ */ { lib, config, pkgs, ... }: + let inherit (lib) mkOption types mkIf; in @@ -18,10 +19,10 @@ in }; config = mkIf config.service.useHostStore { service.image = "arion-base"; - service.build.context = "${../arion-image}"; + service.build.context = "${../../../arion-image}"; service.volumes = [ - "/nix/store:/nix/store" - "${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. + ''; + }; + }; +}