Skip to content

Commit b8b476f

Browse files
committed
Fix sudo
1 parent f87b926 commit b8b476f

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

flake.nix

+42-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
exa
2323
getopt
2424
git
25+
gnused
2526
go_1_20
2627
go-migrate
2728
golangci-lint
@@ -48,33 +49,67 @@
4849
shellcheck
4950
shfmt
5051
sqlc
52+
strace
5153
terraform
5254
typos
5355
yq
5456
zip
5557
zstd
5658
];
57-
baseImage = pkgs.dockerTools.pullImage {
59+
60+
# Start with an Ubuntu image!
61+
baseDevEnvImage = pkgs.dockerTools.pullImage {
5862
imageName = "ubuntu";
5963
imageDigest = "sha256:7a520eeb6c18bc6d32a21bb7edcf673a7830813c169645d51c949cecb62387d0";
6064
sha256 = "1qa9nq3rir0wnhbs15mwbilzw530x7ih9pq5q1wv3axz44ap6dka";
6165
finalImageName = "ubuntu";
6266
finalImageTag = "lunar";
6367
};
68+
# Build the image and modify it to have the "coder" user.
69+
intermediateDevEnvImage = pkgs.dockerTools.buildImage {
70+
name = "intermediate";
71+
fromImage = baseDevEnvImage;
72+
# This replaces the "ubuntu" user with "coder" and
73+
# gives it sudo privileges!
74+
runAsRoot = ''
75+
#!${pkgs.runtimeShell}
76+
${pkgs.dockerTools.shadowSetup}
77+
userdel ubuntu
78+
useradd coder \
79+
--create-home \
80+
--shell=/bin/bash \
81+
--uid=1000 \
82+
--user-group
83+
cat > /etc/pam.d/other <<EOF
84+
account sufficient pam_unix.so
85+
auth sufficient pam_rootok.so
86+
password requisite pam_unix.so nullok yescrypt
87+
session required pam_unix.so
88+
EOF
89+
echo "coder ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers
90+
cp ${pkgs.sudo}/bin/sudo /usr/bin/sudo
91+
chmod 4755 /usr/bin/sudo
92+
'';
93+
};
6494
dockerImage = pkgs.dockerTools.streamLayeredImage {
6595
name = "codercom/oss-dogfood";
6696
tag = "testing";
67-
fromImage = baseImage;
68-
extraCommands = ''
69-
touch ./.wh.bin
70-
ln -s usr/bin bin
71-
'';
97+
fromImage = builtImage;
7298

7399
config = {
74100
Env = [
75-
"PATH=${pkgs.lib.makeBinPath devShellPackages}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
101+
"PATH=${pkgs.lib.makeBinPath devShellPackages}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/coder/go/bin"
102+
#This setting prevents Go from using the public checksum database for
103+
# our module path prefixes. It is required because these are in private
104+
# repositories that require authentication.
105+
#
106+
# For details, see: https://golang.org/ref/mod#private-modules
107+
"GOPRIVATE=coder.com,cdr.dev,go.coder.com,github.com/cdr,github.com/coder"
108+
# Increase memory allocation to NodeJS
109+
"NODE_OPTIONS=--max_old_space_size=8192"
76110
];
77111
Entrypoint = [ "/bin/bash" ];
112+
User = "coder";
78113
};
79114
};
80115
in

0 commit comments

Comments
 (0)