Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions makes/container-image/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
# shellcheck shell=bash

function configure_nix {
mkdir -p "${out}/home/makes/.config/nix" \
: \
&& mkdir -p "${out}/home/makes/.config/nix" \
&& mkdir -p "${out}/home/root/.config/nix" \
&& mkdir -p "${out}/etc/nix" \
&& mkdir -p "${out}/nix/store/.links" \
&& mkdir -p "${out}/nix/var" \
&& mkdir -p "${out}/nix/var/nix" \
&& echo 'build-users-group =' | tee \
"${out}/home/makes/.config/nix/nix.conf" \
"${out}/home/root/.config/nix/nix.conf" \
"${out}/etc/nix/nix.conf"
}

Expand Down
34 changes: 29 additions & 5 deletions makes/container-image/main.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ makeContainerImage {
"SYSTEM_CERTIFICATE_PATH=/etc/ssl/certs/ca-bundle.crt"
"USER=makes"
];
User = "makes:makes";
WorkingDir = "/makes";
User = "root:root";
WorkingDir = "/";
};
layers = [
(makeDerivation {
env = {
envEtcGroup = ''
makes:x:0:
root:x:0:
makes:x:48:
nobody:x:65534:
'';
envEtcGshadow = ''
root:*::
makes:*::
nobody:*::
'';
Expand All @@ -41,10 +43,12 @@ makeContainerImage {
session required pam_unix.so
'';
envEtcPasswd = ''
makes:x:0:0::/home/makes:${inputs.nixpkgs.bash}/bin/bash
root:x:0:0:root:/home/root:${inputs.nixpkgs.bash}/bin/bash
makes:x:48:48:makes:/home/makes:${inputs.nixpkgs.bash}/bin/bash
nobody:x:65534:65534:nobody:/homeless:/bin/false
'';
envEtcShadow = ''
root:!x:::::::
makes:!x:::::::
nobody:!x:::::::
'';
Expand All @@ -61,7 +65,27 @@ makeContainerImage {
inputs.nixpkgs.gzip
inputs.nixpkgs.nix

outputs."/"
(inputs.nixpkgs.writeShellScriptBin "m" ''
if test -z "''${MAKES_NON_ROOT:-}"; then
${outputs."/"}/bin/m "$@"
else
echo Using feature flag: MAKES_NON_ROOT

chown -R makes:makes /nix

chmod u+w /home/makes
chmod u+w /tmp
chown makes:makes /home/makes
chown makes:makes /tmp

{
echo permit nopass keepenv makes
echo permit nopass keepenv root
} > /etc/doas.conf

${inputs.nixpkgs.doas}/bin/doas -u makes ${outputs."/"}/bin/m "$@"
fi
'')
];
maxLayers = 20;
}