# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE. { config, lib, pkgs, ... }: with lib; let etc' = filter (f: f.enable) (attrValues config.environment.etc); etc = pkgs.stdenvNoCC.mkDerivation { name = "etc"; builder = ./make-etc.sh; preferLocalBuild = true; allowSubstitutes = false; sources = map (x: x.source) etc'; targets = map (x: x.target) etc'; }; fileType = types.submodule ( { name, config, ... }: { options = { enable = mkOption { type = types.bool; default = true; description = '' Whether this /etc file should be generated. This option allows specific /etc files to be disabled. ''; }; target = mkOption { type = types.str; description = '' Name of symlink (relative to /etc). Defaults to the attribute name. ''; }; text = mkOption { type = types.nullOr types.lines; default = null; description = "Text of the file."; }; source = mkOption { type = types.path; description = "Path of the source file."; }; }; config = { target = mkDefault name; source = mkIf (config.text != null) ( let name' = "etc-" + baseNameOf name; in mkDefault (pkgs.writeText name' config.text) ); }; } ); in { ###### interface options = { environment = { etc = mkOption { type = types.loaOf fileType; default = { }; example = literalExpression '' { example-configuration-file = { source = "/nix/store/.../etc/dir/file.conf.example"; }; "default/useradd".text = "GROUP=100 ..."; } ''; description = '' Set of files that have to be linked in /etc. ''; }; etcBackupExtension = mkOption { type = types.nullOr types.str; default = null; example = ".bak"; description = '' Backup file extension. If a file in /etc already exists and is not managed by Nix-on-Droid, the activation fails because we do not overwrite unknown files. When an extension is provided through this option, the original file will be moved in respect of the backup extension and the activation executes successfully. ''; }; }; }; ###### implementation config = { build = { inherit etc; activation.setUpEtc = '' $DRY_RUN_CMD bash ${./setup-etc.sh} /etc ${etc}/etc ${toString config.environment.etcBackupExtension} ''; }; }; }