Skip to content

Commit

Permalink
feat: Nix Shell support (#296)
Browse files Browse the repository at this point in the history
* feat(nix): add nix-shell support

* chore(nix): update niv dependencies

* chore(nix): update cargo dependencies

* chore(web): update open-api
  • Loading branch information
NickLarsenNZ authored May 28, 2024
1 parent 3de66fc commit 85c9b52
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Cargo.nix

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

110 changes: 48 additions & 62 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
{ sources ? import ./nix/sources.nix # managed by https://github.com/nmattia/niv
, nixpkgs ? sources.nixpkgs
, pkgs ? import nixpkgs {
overlays = [
# gomod2nix must be imported as a nixpkgs overlay
(import (sources.gomod2nix+"/overlay.nix"))
];
overlays = [
# gomod2nix must be imported as a nixpkgs overlay
(import (sources.gomod2nix+"/overlay.nix"))
];
}
, meta ? pkgs.lib.importJSON ./nix/meta.json
, dockerName ? "docker.stackable.tech/sandbox/${meta.operator.name}"
, dockerTag ? null
}:
rec {
cargo = import ./Cargo.nix {
, cargo ? import ./Cargo.nix {
inherit nixpkgs pkgs; release = false;
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
prost-build = attrs: {
buildInputs = [ pkgs.protobuf ];
};
tonic-reflection = attrs: {
buildInputs = [ pkgs.rustfmt ];
};
stackable-secret-operator = attrs: {
buildInputs = [ pkgs.protobuf pkgs.rustfmt ];
};
krb5-sys = attrs: {
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ (pkgs.enableDebugging pkgs.krb5) ];
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.glibc.dev}/include -I${pkgs.clang.cc.lib}/lib/clang/${pkgs.lib.getVersion pkgs.clang.cc}/include";
};
stackable-cockpit-web = attrs: {
nativeBuildInputs = [ pkgs.nodePackages.yarn pkgs.nodejs ];
preConfigure =
Expand Down Expand Up @@ -60,7 +40,49 @@ rec {
SWAGGER_UI_DOWNLOAD_URL = "file:///invalid-path/swagger-ui.zip";
};
};
};
}
, meta ? pkgs.lib.importJSON ./nix/meta.json
, dockerName ? "docker.stackable.tech/sandbox/${meta.operator.name}"
, dockerTag ? null
, web ? js2nix.buildEnv {
# js2nix doesn't import peer dependencies, so we use overlays to patch them in explicitly
# https://github.com/canva-public/js2nix/blob/d37912f6cc824e7f41bea7a481af1739ca195c8f/docs/usage.md#overriding
package-json = ./web/package.json;
yarn-lock = ./yarn.lock;
overlays = [
(self: super: {
# TODO: remove once this https://github.com/canva-public/js2nix/issues/20 is resolved
buildNodeModule = pkgs.lib.makeOverridable
(args: (super.buildNodeModule args).override { doCheck = false; });
})
];
}
, goHelmWrapper ? pkgs.buildGoApplication {
pname = "go-helm-wrapper";
version = "0.0";
src = pkgs.runCommand "go-helm-wrapper-src" {}
''
mkdir $out
cp ${./go.mod} $out/go.mod
cp ${./go.sum} $out/go.sum
cp -r ${./rust/helm-sys/go-helm-wrapper} $out/go-helm-wrapper
'';
pwd = ./rust/helm-sys/go-helm-wrapper;
modules = ./gomod2nix.toml;
ldflags = "-buildmode c-archive";
allowGoReference = true;
postBuild =
''
for pkg in $(getGoDirs ""); do
buildFlags="-buildmode c-archive -o $GOPATH/bin/libgo-helm-wrapper.a" buildGoDir build "$pkg"
done
'';
}
, js2nix ? pkgs.callPackage sources.js2nix { nodejs = pkgs.nodejs-18_x; }
, gomod2nix ? pkgs.callPackage sources.gomod2nix {}
}:
rec {
inherit cargo sources pkgs meta;
build = cargo.workspaceMembers.stackable-cockpitd.build.override {
features = [ "ui" ];
};
Expand Down Expand Up @@ -117,45 +139,9 @@ rec {

# need to use vendored crate2nix because of https://github.com/kolloch/crate2nix/issues/264
crate2nix = import sources.crate2nix {};
js2nix = pkgs.callPackage sources.js2nix { nodejs = pkgs.nodejs-18_x; };
gomod2nix = pkgs.callPackage sources.gomod2nix {};
tilt = pkgs.tilt;

web = js2nix.buildEnv {
# js2nix doesn't import peer dependencies, so we use overlays to patch them in explicitly
# https://github.com/canva-public/js2nix/blob/d37912f6cc824e7f41bea7a481af1739ca195c8f/docs/usage.md#overriding
package-json = ./web/package.json;
yarn-lock = ./yarn.lock;
overlays = [
(self: super: {
# TODO: remove once this https://github.com/canva-public/js2nix/issues/20 is resolved
buildNodeModule = pkgs.lib.makeOverridable
(args: (super.buildNodeModule args).override { doCheck = false; });
})
];
};

goHelmWrapper = pkgs.buildGoApplication {
pname = "go-helm-wrapper";
version = "0.0";
src = pkgs.runCommand "go-helm-wrapper-src" {}
''
mkdir $out
cp ${./go.mod} $out/go.mod
cp ${./go.sum} $out/go.sum
cp -r ${./rust/helm-sys/go-helm-wrapper} $out/go-helm-wrapper
'';
pwd = ./rust/helm-sys/go-helm-wrapper;
modules = ./gomod2nix.toml;
ldflags = "-buildmode c-archive";
allowGoReference = true;
postBuild =
''
for pkg in $(getGoDirs ""); do
buildFlags="-buildmode c-archive -o $GOPATH/bin/libgo-helm-wrapper.a" buildGoDir build "$pkg"
done
'';
};

regenerateNixLockfiles = pkgs.writeScriptBin "regenerate-nix-lockfiles"
''
Expand Down
12 changes: 6 additions & 6 deletions nix/sources.json

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

42 changes: 42 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
let
self = import ./. {};
inherit (self) sources pkgs meta;

cargoDependencySetOfCrate = crate: [ crate ] ++ pkgs.lib.concatMap cargoDependencySetOfCrate (crate.dependencies ++ crate.buildDependencies);
cargoDependencySet = pkgs.lib.unique (pkgs.lib.flatten (pkgs.lib.mapAttrsToList (crateName: crate: cargoDependencySetOfCrate crate.build) self.cargo.workspaceMembers));
in pkgs.mkShell rec {
name = meta.operator.name;

packages = with pkgs; [
## cargo et-al
rustup # this breaks pkg-config if it is in the nativeBuildInputs

## Extra dependencies for use in a pure env (nix-shell --pure)
## These are mosuly useful for maintainers of this shell.nix
## to ensure all the dependencies are caught.
# cacert
# vim nvim nano
];

# derivation runtime dependencies
buildInputs = pkgs.lib.concatMap (crate: crate.buildInputs) cargoDependencySet;

# build time dependencies
nativeBuildInputs = pkgs.lib.concatMap (crate: crate.nativeBuildInputs) cargoDependencySet ++ (with pkgs; [
clang
git
# Replace llvmPackages with llvmPackages_X, where X is the latest LLVM version (at the time of writing, 16)
llvmPackages.bintools
rustup

# additions for this repo
yarn
typescript
vite
go
]);

LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.glibc.dev}/include -I${pkgs.clang}/resource-root/include";

}
2 changes: 0 additions & 2 deletions web/src/api/schema.d.ts

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

0 comments on commit 85c9b52

Please sign in to comment.