Add modules

This commit is contained in:
Tobias Happ 2019-11-24 00:37:40 +01:00 committed by Alexander Sosedkin
parent 5cc656fffc
commit f40362898a
19 changed files with 1045 additions and 0 deletions

81
modules/user.nix Normal file
View file

@ -0,0 +1,81 @@
# Licensed under GNU Lesser General Public License v3 or later, see COPYING.
# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS.
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.user;
idsDerivation = pkgs.runCommand "ids.nix" {} ''
cat > $out <<EOF
{
gid = "$(${pkgs.coreutils}/bin/id -g)";
uid = "$(${pkgs.coreutils}/bin/id -u)";
}
EOF
'';
ids = import idsDerivation;
in
{
###### interface
options = {
user = {
group = mkOption {
type = types.str;
default = "nix-on-droid";
description = "Group name.";
};
home = mkOption {
type = types.path;
readOnly = true;
description = "Path to home directory.";
};
shell = mkOption {
type = types.path;
readOnly = true;
description = "Path to login shell.";
};
userName = mkOption {
type = types.str;
default = "nix-on-droid";
description = "User name.";
};
};
};
###### implementation
config = {
environment.etc = {
"group".text = ''
root:x:0:
${cfg.group}:x:${ids.gid}:${cfg.userName}
'';
"passwd".text = ''
root:x:0:0:System administrator:${config.build.installationDir}/root:/bin/sh
${cfg.userName}:x:${ids.uid}:${ids.gid}:${cfg.userName}:${cfg.home}:${cfg.shell}
'';
};
user = {
home = "/data/data/com.termux.nix/files/home";
shell = "/bin/sh";
};
};
}