Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit installation of dev/test dependencies via Nix #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion buildkitd.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func SpawnBuildkitd(req Request, opts *BuildkitdOpts) (*Buildkitd, error) {
if os.Getuid() == 0 {
cmd = exec.Command("buildkitd", buildkitdFlags...)
} else {
cmd = exec.Command("rootlesskit", append([]string{"buildkitd"}, buildkitdFlags...)...)
cmd = exec.Command("rootlesskit", append([]string{"buildkitd", "--rootless"}, buildkitdFlags...)...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one related or is it a bug left from before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly NixOS-specific, and certainly reasonable to separate out into a different PR to be individually evaluated. While debugging, it came up that buildkit (or at least, the version shipped in NixOS 21.11) has a --rootless which is documented to enable configuration changes for better compatibility with rootlesskit -- but that said, I didn't go back after getting other issues ironed out to confirm that we were unable to run tests without it.

I'll do that now and follow up with findings.

}

// kill buildkitd on exit
Expand Down
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# If using a flake-enabled version of Nix (minimum 2.4, with experimental
# features enabled), ''nix develop'' will spawn an environment in which
# ''./scripts/test'' will work as intended.

# For older versions of Nix, ''nix-shell'' will invoke this same code via the
# shell.nix compatibility layer.

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-21.11";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = import nixpkgs { inherit system; };
in rec {
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
buildkit
go
rootlesskit
runc
];
shellHook = ''
if ! type newuidmap >/dev/null 2>&1; then {
echo "WARNING: newuidmap and newgid map are required but not found"
echo " Because these tools require a setuid bit to operate,"
echo " they cannot be installed in a local Nix shell."
echo
} >&2; fi
PS1='[oci-build-task devshell] '"$PS1"
'';
};
});
}


2 changes: 1 addition & 1 deletion scripts/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give some info about this line? Thx.

Copy link
Contributor Author

@charles-dyfis-net charles-dyfis-net May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. NixOS doesn't have a /bin/bash; the only executables with hardcoded locations are /bin/sh and /usr/bin/env; everything else comes from a generated PATH with pointers into /nix/store/<hash>-<application>-<version>/bin (allowing NixOS to have different versions of the same application, or differently-compiled versions of the same application version, simultaneously installed; similarly, dynamic library linkage all uses explicit rpaths with a hash component, so applications only link the specific library versions they were compiled and tested against, even if some newer or differently-patched version of the library is installed for a different application's use).

Using #!/usr/bin/env bash causes a PATH lookup to be used to find the shell interpreter.


set -e -u

Expand Down
10 changes: 10 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).shellNix