Move /etc/{passwd,group} to basic-environment

This commit is contained in:
Alexander Sosedkin 2019-10-05 04:01:07 +02:00
parent 0c0f62f604
commit 7775c8f1d6
6 changed files with 55 additions and 22 deletions

View file

@ -22,6 +22,8 @@ in
nixpkgs.coreutils nixpkgs.coreutils
nixpkgs.nix nixpkgs.nix
# pkgs.proot # pkgs.proot
pkgs.files.etc-group
pkgs.files.etc-passwd
pkgs.files.hm-install pkgs.files.hm-install
pkgs.files.home-nix-default pkgs.files.home-nix-default
pkgs.files.login pkgs.files.login

View file

@ -5,6 +5,9 @@
let let
instDir = "/data/data/com.termux.nix/files/usr"; instDir = "/data/data/com.termux.nix/files/usr";
userName = "nix-on-droid";
groupName = "nix-on-droid";
shell = "/bin/sh";
packageInfo = import "${nixDirectory}/nix-support/package-info.nix"; packageInfo = import "${nixDirectory}/nix-support/package-info.nix";
@ -16,11 +19,16 @@ let
}; };
callPackage = buildPkgs.lib.callPackageWith (buildPkgs // { callPackage = buildPkgs.lib.callPackageWith (buildPkgs // {
inherit initialBuild instDir packageInfo writeTextDir; inherit groupName initialBuild instDir packageInfo shell writeTextDir userName;
}); });
in in
{ {
etc-group = callPackage ./etc-group.nix { };
etc-passwd = callPackage ./etc-passwd.nix { };
hm-install = callPackage ./hm-install.nix { }; hm-install = callPackage ./hm-install.nix { };
home-nix-default = writeTextDir "etc/home.nix.default" (builtins.readFile ./raw/home.nix.default); home-nix-default = writeTextDir "etc/home.nix.default" (builtins.readFile ./raw/home.nix.default);

View file

@ -0,0 +1,20 @@
# Licensed under GNU Lesser General Public License v3 or later, see COPYING.
# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS.
{ coreutils, runCommand, writeTextDir, instDir, userName, groupName }:
let
ids = runCommand "ids" {} ''
mkdir $out
echo -n $(${coreutils}/bin/id -u) > $out/uid
echo -n $(${coreutils}/bin/id -g) > $out/gid
'';
gid = builtins.readFile "${ids}/gid";
in
writeTextDir "etc/group" ''
root:x:0:
${groupName}:x:${gid}:${userName}
''

View file

@ -0,0 +1,19 @@
# Licensed under GNU Lesser General Public License v3 or later, see COPYING.
# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS.
{ coreutils, runCommand, writeTextDir, instDir, userName, shell }:
let
ids = runCommand "ids" {} ''
mkdir $out
echo -n $(${coreutils}/bin/id -u) > $out/uid
echo -n $(${coreutils}/bin/id -g) > $out/gid
'';
uid = builtins.readFile "${ids}/uid";
gid = builtins.readFile "${ids}/gid";
in
writeTextDir "etc/passwd" ''
root:x:0:0:System administrator:${instDir}/root:/bin/sh
${userName}:x:${uid}:${gid}:/data/data/com.termux.nix/files/home:${shell}
''

View file

@ -33,21 +33,6 @@ writeTextDir "usr/lib/login-inner" ''
echo "Setting up dynamic symlinks via nix-on-droid-linker" echo "Setting up dynamic symlinks via nix-on-droid-linker"
nix-on-droid-linker nix-on-droid-linker
[ "$#" -gt 0 ] || echo "Sourcing Nix environment..."
. $HOME/.nix-profile/etc/profile.d/nix.sh
if [ ! -e ${instDir}/etc/passwd ]; then
[ -n "$@" ] || echo "Creating /etc/passwd..."
echo "root:x:0:0:System administrator:${instDir}/root:/bin/sh" > ${instDir}/etc/passwd
echo "$USER:x:$(id -u):$USER:/data/data/com.termux.nix/files/home:/bin/sh" >> ${instDir}/etc/passwd
fi
if [ ! -e ${instDir}/etc/group ]; then
[ -n "$@" ] || echo "Creating /etc/group..."
echo "root:x:0:" > ${instDir}/etc/group
echo "$USER:x:$(id -g):$USER" >> ${instDir}/etc/group
fi
echo echo
echo "Congratulations! Now you have Nix installed with some basic packages like" echo "Congratulations! Now you have Nix installed with some basic packages like"
echo "bashInteractive, coreutils, cacert and some scripts provided by nix-on-droid" echo "bashInteractive, coreutils, cacert and some scripts provided by nix-on-droid"
@ -56,13 +41,12 @@ writeTextDir "usr/lib/login-inner" ''
echo "You can go for the bare Nix setup or you can configure your phone via" echo "You can go for the bare Nix setup or you can configure your phone via"
echo "home-manager. For that simply run hm-install." echo "home-manager. For that simply run hm-install."
echo echo
'' '' else ""
else ''
[ "$#" -gt 0 ] || echo "Sourcing Nix environment..."
. $HOME/.nix-profile/etc/profile.d/nix.sh
''
} }
[ "$#" -gt 0 ] || echo "Sourcing Nix environment..."
. $HOME/.nix-profile/etc/profile.d/nix.sh
if [ -e "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then if [ -e "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then
[ "$#" -gt 0 ] || echo "Sourcing home-manager environment..." [ "$#" -gt 0 ] || echo "Sourcing home-manager environment..."
export NIX_PATH=$HOME/.nix-defexpr/channels''${NIX_PATH:+:}$NIX_PATH export NIX_PATH=$HOME/.nix-defexpr/channels''${NIX_PATH:+:}$NIX_PATH

View file

@ -20,7 +20,7 @@ writeScriptBin "nix-on-droid-linker" ''
link bin/$i bin/$i link bin/$i bin/$i
done done
for i in home.nix.default nix/nix.conf resolv.conf; do for i in group home.nix.default nix/nix.conf passwd resolv.conf; do
link etc/$i etc/$i link etc/$i etc/$i
done done