nix-on-droid/modules/environment/etc/default.nix
Tobias Happ ae0569fb92 treewide: use consitent casing of Nix-on-Droid/nix-on-droid
Whenever Nix-on-Droid references the project or application it should be
upper-cased.

When nix-on-droid is referencing the CLI-tool or is used as some ID, it
should be lower-cased.
2022-11-20 20:15:31 +01:00

125 lines
2.9 KiB
Nix

# 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 <filename>/etc</filename> file should be generated. This
option allows specific <filename>/etc</filename> files to be disabled.
'';
};
target = mkOption {
type = types.str;
description = ''
Name of symlink (relative to <filename>/etc</filename>).
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 <filename>/etc</filename>.
'';
};
etcBackupExtension = mkOption {
type = types.nullOr types.str;
default = null;
example = ".bak";
description = ''
Backup file extension.
</para><para>
If a file in <filename>/etc</filename> 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}
'';
};
};
}