<commit_before>{pkgs, lib, config, ...}:

with lib;

let
  cfg = config.dysnomiaTest;
  
  printProperties = properties:
    concatMapStrings (propertyName:
      let
        property = properties."${propertyName}";
      in
      if isList property then "${propertyName}=(${lib.concatMapStrings (elem: "\"${toString elem}\" ") (properties."${propertyName}")})\n"
      else "${propertyName}=\"${toString property}\"\n"
    ) (builtins.attrNames properties);
  
  properties = pkgs.stdenv.mkDerivation {
    name = "dysnomia-properties";
    buildCommand = ''
      cat > $out << "EOF"
      ${printProperties cfg.properties}
      EOF
    '';
  };
  
  containersDir = pkgs.stdenv.mkDerivation {
    name = "dysnomia-containers";
    buildCommand = ''
      mkdir -p $out
      cd $out
      
      ${concatMapStrings (containerName:
        let
          containerProperties = cfg.containers."${containerName}";
        in
        ''
          cat > ${containerName} <<EOF
          ${printProperties containerProperties}
          type=${containerName}
          EOF
        ''
      ) (builtins.attrNames cfg.containers)}
    '';
  };
  
  linkMutableComponents = {containerName}:
    ''
      mkdir ${containerName}
      
      ${concatMapStrings (componentName:
        let
          component = cfg.components."${containerName}"."${componentName}";
        in
        "ln -s ${component} ${containerName}/${componentName}\n"
      ) (builtins.attrNames (cfg.components."${containerName}" or {}))}
    '';
  
  componentsDir = pkgs.stdenv.mkDerivation {
    name = "dysnomia-components";
    buildCommand = ''
      mkdir -p $out
      cd $out
      
      ${concatMapStrings (containerName:
        let
          components = cfg.components."${containerName}";
        in
        linkMutableComponents { inherit containerName; }
      ) (builtins.attrNames cfg.components)}
    '';
  };
in
{
  options = {
    dysnomiaTest = {
      
      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable Dysnomia";
      };
      
      enableAuthentication = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to publish privacy-sensitive authentication credentials";
      };
      
      package = mkOption {
        type = types.path;
        description = "The Dysnomia package";
      };
      
      properties = mkOption {
        description = "An attribute set in which each attribute represents a machine property. Optionally, these values can be shell substitutions.";
        default = {};
      };
      
      containers = mkOption {
        description = "An attribute set in which each key represents a container and each value an attribute set providing its configuration properties";
        default = {};
      };
      
      components = mkOption {
        description = "An atttribute set in which each key represents a container and each value an attribute set in which each key represents a component and each value a derivation constructing its initial state";
        default = {};
      };
      
      extraContainerProperties = mkOption {
        description = "An attribute set providing additional container settings in addition to the default properties";
        default = {};
      };
    };
  };
  
  config = mkIf cfg.enable {
  
    environment.etc = {
      "dysnomia/containers" = {
        source = containersDir;
      };
      "dysnomia/components" = {
        source = componentsDir;
      };
      "dysnomia/properties" = {
        source = properties;
      };
    };
    
    environment.variables = {
      DYSNOMIA_STATEDIR = "/var/state/dysnomia-nixos";
    };
    
    environment.systemPackages = [ cfg.package ];
    
    dysnomiaTest.package = mkDefault (import ./build.nix {
      enableApacheWebApplication = config.services.httpd.enable;
      enableAxis2WebService = config.services.tomcat.axis2.enable;
      enableEjabberdDump = config.services.ejabberd.enable;
      enableMySQLDatabase = config.services.mysql.enable;
      enablePostgreSQLDatabase = config.services.postgresql.enable;
      enableTomcatWebApplication = config.services.tomcat.enable;
      enableMongoDatabase = config.services.mongodb.enable;
      enableSubversionRepository = config.services.svnserve.enable;
      jobTemplate = "systemd";
      inherit pkgs;
      tarball = (import ./release.nix {}).tarball;
    });
    
    dysnomiaTest.properties = {
      hostname = config.networking.hostName;<commit_msg>Make the container and module search directories configurable<commit_after>{pkgs, lib, config, ...}:

with lib;

let
  cfg = config.dysnomiaTest;
  
  printProperties = properties:
    concatMapStrings (propertyName:
      let
        property = properties."${propertyName}";
      in
      if isList property then "${propertyName}=(${lib.concatMapStrings (elem: "\"${toString elem}\" ") (properties."${propertyName}")})\n"
      else "${propertyName}=\"${toString property}\"\n"
    ) (builtins.attrNames properties);
  
  properties = pkgs.stdenv.mkDerivation {
    name = "dysnomia-properties";
    buildCommand = ''
      cat > $out << "EOF"
      ${printProperties cfg.properties}
      EOF
    '';
  };
  
  containersDir = pkgs.stdenv.mkDerivation {
    name = "dysnomia-containers";
    buildCommand = ''
      mkdir -p $out
      cd $out
      
      ${concatMapStrings (containerName:
        let
          containerProperties = cfg.containers."${containerName}";
        in
        ''
          cat > ${containerName} <<EOF
          ${printProperties containerProperties}
          type=${containerName}
          EOF
        ''
      ) (builtins.attrNames cfg.containers)}
    '';
  };
  
  linkMutableComponents = {containerName}:
    ''
      mkdir ${containerName}
      
      ${concatMapStrings (componentName:
        let
          component = cfg.components."${containerName}"."${componentName}";
        in
        "ln -s ${component} ${containerName}/${componentName}\n"
      ) (builtins.attrNames (cfg.components."${containerName}" or {}))}
    '';
  
  componentsDir = pkgs.stdenv.mkDerivation {
    name = "dysnomia-components";
    buildCommand = ''
      mkdir -p $out
      cd $out
      
      ${concatMapStrings (containerName:
        let
          components = cfg.components."${containerName}";
        in
        linkMutableComponents { inherit containerName; }
      ) (builtins.attrNames cfg.components)}
    '';
  };
in
{
  options = {
    dysnomiaTest = {
      
      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable Dysnomia";
      };
      
      enableAuthentication = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to publish privacy-sensitive authentication credentials";
      };
      
      package = mkOption {
        type = types.path;
        description = "The Dysnomia package";
      };
      
      properties = mkOption {
        description = "An attribute set in which each attribute represents a machine property. Optionally, these values can be shell substitutions.";
        default = {};
      };
      
      containers = mkOption {
        description = "An attribute set in which each key represents a container and each value an attribute set providing its configuration properties";
        default = {};
      };
      
      components = mkOption {
        description = "An atttribute set in which each key represents a container and each value an attribute set in which each key represents a component and each value a derivation constructing its initial state";
        default = {};
      };
      
      extraContainerProperties = mkOption {
        description = "An attribute set providing additional container settings in addition to the default properties";
        default = {};
      };
      
      extraContainerPaths = mkOption {
        description = "A list of paths containing additional container configurations that are added to the search folders";
        default = [];
      };
      
      extraModulePaths = mkOption {
        description = "A list of paths containing additional modules that are added to the search folders";
        default = [];
      };
    };
  };
  
  config = mkIf cfg.enable {
  
    environment.etc = {
      "dysnomia/containers" = {
        source = containersDir;
      };
      "dysnomia/components" = {
        source = componentsDir;
      };
      "dysnomia/properties" = {
        source = properties;
      };
    };
    
    environment.variables = {
      DYSNOMIA_STATEDIR = "/var/state/dysnomia-nixos";
      DYSNOMIA_CONTAINERS_PATH = "${lib.concatMapStrings (containerPath: "${containerPath}:") cfg.extraContainerPaths}/etc/dysnomia/containers";
      DYSNOMIA_MODULES_PATH = "${lib.concatMapStrings (modulePath: "${modulePath}:") cfg.extraModulePaths}/etc/dysnomia/modules";
    };
    
    environment.systemPackages = [ cfg.package ];
    
    dysnomiaTest.package = mkDefault (import ./build.nix {
      enableApacheWebApplication = config.services.httpd.enable;
      enableAxis2WebService = config.services.tomcat.axis2.enable;
      enableEjabberdDump = config.services.ejabberd.enable;
      enableMySQLDatabase = config.services.mysql.enable;
      enablePostgreSQLDatabase = config.services.postgresql.enable;
      enableTomcatWebApplication = config.services.tomcat.enable;
      enableMongoDatabase = config.services.mongodb.enable;
      enableSubversionRepository = config.services.svnserve.enable;
      jobTemplate = "systemd";
      inherit pkgs;
      tarball = (import ./release.nix {}).tarball;
    });
    
    dysnomiaTest.properties = {
      hostname = config.networking.hostName;
{'fraction_non_alphanumeric': 0.10697152189445748, 'fraction_numerical': 0.00040828825150556294, 'mean_word_length': 2.4009024644220758, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3581303', 'n_tokens_mistral': 2690, 'n_tokens_neox': 2647, 'n_words': 627}