diff --git a/default.nix b/default.nix index d26522f..0562699 100644 --- a/default.nix +++ b/default.nix @@ -22,6 +22,8 @@ in nixpkgs.coreutils nixpkgs.nix # pkgs.proot + pkgs.files.etc-group + pkgs.files.etc-passwd pkgs.files.hm-install pkgs.files.home-nix-default pkgs.files.login diff --git a/src/pkgs/files/default.nix b/src/pkgs/files/default.nix index 1f764c6..34f8b87 100644 --- a/src/pkgs/files/default.nix +++ b/src/pkgs/files/default.nix @@ -5,6 +5,9 @@ let 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"; @@ -16,11 +19,16 @@ let }; callPackage = buildPkgs.lib.callPackageWith (buildPkgs // { - inherit initialBuild instDir packageInfo writeTextDir; + inherit groupName initialBuild instDir packageInfo shell writeTextDir userName; }); in { + + etc-group = callPackage ./etc-group.nix { }; + + etc-passwd = callPackage ./etc-passwd.nix { }; + hm-install = callPackage ./hm-install.nix { }; home-nix-default = writeTextDir "etc/home.nix.default" (builtins.readFile ./raw/home.nix.default); diff --git a/src/pkgs/files/etc-group.nix b/src/pkgs/files/etc-group.nix new file mode 100644 index 0000000..a830786 --- /dev/null +++ b/src/pkgs/files/etc-group.nix @@ -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} +'' + diff --git a/src/pkgs/files/etc-passwd.nix b/src/pkgs/files/etc-passwd.nix new file mode 100644 index 0000000..e760bed --- /dev/null +++ b/src/pkgs/files/etc-passwd.nix @@ -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} +'' diff --git a/src/pkgs/files/login-inner.nix b/src/pkgs/files/login-inner.nix index 107e7e3..f6a2f5a 100644 --- a/src/pkgs/files/login-inner.nix +++ b/src/pkgs/files/login-inner.nix @@ -33,21 +33,6 @@ writeTextDir "usr/lib/login-inner" '' echo "Setting up dynamic symlinks via 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 "Congratulations! Now you have Nix installed with some basic packages like" 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 "home-manager. For that simply run hm-install." echo - '' - else '' - [ "$#" -gt 0 ] || echo "Sourcing Nix environment..." - . $HOME/.nix-profile/etc/profile.d/nix.sh - '' + '' else "" } + [ "$#" -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 [ "$#" -gt 0 ] || echo "Sourcing home-manager environment..." export NIX_PATH=$HOME/.nix-defexpr/channels''${NIX_PATH:+:}$NIX_PATH diff --git a/src/pkgs/files/nix-on-droid-linker.nix b/src/pkgs/files/nix-on-droid-linker.nix index 283e87d..469f666 100644 --- a/src/pkgs/files/nix-on-droid-linker.nix +++ b/src/pkgs/files/nix-on-droid-linker.nix @@ -20,7 +20,7 @@ writeScriptBin "nix-on-droid-linker" '' link bin/$i bin/$i 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 done