systemconfig: chown files if uid/gid > 0

This commit is contained in:
Daniel Barlow 2023-04-15 22:53:28 +01:00
parent 5dd0c6e3c0
commit 65dfbad365
3 changed files with 18 additions and 5 deletions

View file

@ -28,8 +28,6 @@ let
, uid ? 0 , uid ? 0
, gid ? 0 , gid ? 0
}: }:
assert uid == 0;
assert gid == 0;
let let
pathname = "${prefix}/${filename}"; pathname = "${prefix}/${filename}";
qpathname = builtins.toJSON pathname; qpathname = builtins.toJSON pathname;
@ -49,7 +47,10 @@ let
"i" = "MKNOD_P(${qpathname}, ${mode'});"; "i" = "MKNOD_P(${qpathname}, ${mode'});";
}; };
cmd = cmds.${type}; cmd = cmds.${type};
in "${cmd}"; chown = if uid>0 || gid>0
then "\nCHOWN(${qpathname},${toString uid},${toString gid});\n"
else "";
in "${cmd} ${chown}";
in mapAttrsToList (makeFile prefix) attrset; in mapAttrsToList (makeFile prefix) attrset;
activateScript = attrset: writeText "makedevs.c" '' activateScript = attrset: writeText "makedevs.c" ''
#include "defs.h" #include "defs.h"

View file

@ -35,3 +35,4 @@ void print_file(char * path, mode_t mode, char * text) {
#define LN_S(target, path) (void)symlink(target, path) #define LN_S(target, path) (void)symlink(target, path)
#define LN(target, path) link(target, path) #define LN(target, path) link(target, path)
#define MKNOD_P(path, mode) mkfifo(path, mode) #define MKNOD_P(path, mode) mkfifo(path, mode)
#define CHOWN(path, uid, gid) chown(path, uid, gid)

View file

@ -1,8 +1,19 @@
{ config, pkgs, lib, ... } : { config, pkgs, lib, ... } :
{ let
inherit (pkgs.pseudofile) dir symlink;
in {
imports = [ imports = [
../../vanilla-configuration.nix ../../vanilla-configuration.nix
../../modules/squashfs.nix
../../modules/jffs2.nix ../../modules/jffs2.nix
]; ];
config.rootfsType = "jffs2"; config.rootfsType = "jffs2";
config.filesystem = dir {
hello = {
type = "f";
uid = 7;
gid = 24;
file = "hello world";
};
};
} }