From 46b782165a3509e8c16abdc371e8eeb89066c93d Mon Sep 17 00:00:00 2001 From: Tobias Happ Date: Sat, 5 Oct 2019 17:43:11 +0200 Subject: [PATCH] Move id derivation to separate file --- src/pkgs/default.nix | 2 ++ src/pkgs/files/default.nix | 7 ++++--- src/pkgs/files/etc-group.nix | 15 ++------------- src/pkgs/files/etc-passwd.nix | 12 +++--------- src/pkgs/ids.nix | 13 +++++++++++++ 5 files changed, 24 insertions(+), 25 deletions(-) create mode 100644 src/pkgs/ids.nix diff --git a/src/pkgs/default.nix b/src/pkgs/default.nix index 6c49327..869e3f2 100644 --- a/src/pkgs/default.nix +++ b/src/pkgs/default.nix @@ -15,6 +15,8 @@ let files = callPackage ./files { } // { recurseForDerivations = true; }; + ids = callPackage ./ids.nix { }; + nixDirectory = callPackage ./nix-directory.nix { }; proot = callPackage ./proot.nix { }; diff --git a/src/pkgs/files/default.nix b/src/pkgs/files/default.nix index a4e8e2a..43ef5d8 100644 --- a/src/pkgs/files/default.nix +++ b/src/pkgs/files/default.nix @@ -1,7 +1,9 @@ # Licensed under GNU Lesser General Public License v3 or later, see COPYING. # Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. -{ buildPkgs, initialBuild, nixDirectory, nixOnDroidChannelURL, nixpkgsChannelURL }: +{ buildPkgs, initialBuild, nixDirectory +, nixOnDroidChannelURL, nixpkgsChannelURL +, ids }: let instDir = "/data/data/com.termux.nix/files/usr"; @@ -20,14 +22,13 @@ let callPackage = buildPkgs.lib.callPackageWith (buildPkgs // { inherit initialBuild instDir packageInfo writeTextDir; - inherit groupName userName; + inherit groupName userName ids; inherit shell; inherit nixOnDroidChannelURL nixpkgsChannelURL; }); in { - etc-group = callPackage ./etc-group.nix { }; etc-passwd = callPackage ./etc-passwd.nix { }; diff --git a/src/pkgs/files/etc-group.nix b/src/pkgs/files/etc-group.nix index a830786..160a20b 100644 --- a/src/pkgs/files/etc-group.nix +++ b/src/pkgs/files/etc-group.nix @@ -1,20 +1,9 @@ # 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, userName, groupName, ids }: writeTextDir "etc/group" '' root:x:0: - ${groupName}:x:${gid}:${userName} + ${groupName}:x:${(import ids).gid}:${userName} '' - diff --git a/src/pkgs/files/etc-passwd.nix b/src/pkgs/files/etc-passwd.nix index e760bed..11180f4 100644 --- a/src/pkgs/files/etc-passwd.nix +++ b/src/pkgs/files/etc-passwd.nix @@ -1,19 +1,13 @@ # 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 }: +{ writeTextDir, instDir, userName, shell, ids }: 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"; + idSet = import ids; 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} + ${userName}:x:${idSet.uid}:${idSet.gid}:/data/data/com.termux.nix/files/home:${shell} '' diff --git a/src/pkgs/ids.nix b/src/pkgs/ids.nix new file mode 100644 index 0000000..7baea41 --- /dev/null +++ b/src/pkgs/ids.nix @@ -0,0 +1,13 @@ +# Licensed under GNU Lesser General Public License v3 or later, see COPYING. +# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. + +{ buildPkgs }: + +buildPkgs.runCommand "ids.nix" {} '' + cat > $out <