systemconfig: chown files if uid/gid > 0

module-based-network
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
, gid ? 0
}:
assert uid == 0;
assert gid == 0;
let
pathname = "${prefix}/${filename}";
qpathname = builtins.toJSON pathname;
@ -49,7 +47,10 @@ let
"i" = "MKNOD_P(${qpathname}, ${mode'});";
};
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;
activateScript = attrset: writeText "makedevs.c" ''
#include "defs.h"
@ -72,6 +73,6 @@ in attrset:
makeFlags = ["makedevs"];
installPhase = ''
mkdir -p $out/bin
$STRIP --remove-section=.note --remove-section=.comment --strip-all makedevs -o $out/bin/activate
$STRIP --remove-section=.note --remove-section=.comment --strip-all makedevs -o $out/bin/activate
'';
}

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(target, path) link(target, path)
#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, ... } :
{
let
inherit (pkgs.pseudofile) dir symlink;
in {
imports = [
../../vanilla-configuration.nix
../../modules/squashfs.nix
../../modules/jffs2.nix
];
config.rootfsType = "jffs2";
config.filesystem = dir {
hello = {
type = "f";
uid = 7;
gid = 24;
file = "hello world";
};
};
}