Skip to content

Commit

Permalink
refactor: use findTargets for lib.ops
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Sep 15, 2023
1 parent 37eed5c commit 5c6d67b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 52 deletions.
33 changes: 0 additions & 33 deletions src/lib/ops.nix

This file was deleted.

7 changes: 7 additions & 0 deletions src/lib/ops/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let
inherit (inputs.std) findTargets;
in
findTargets {
inherit inputs cell;
block = ./.;
}
13 changes: 6 additions & 7 deletions src/lib/ops/mkDevOCI.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
inputs,
cell,
}: let
inherit (inputs) nixpkgs std;
let
inherit (inputs.cells.std.errors) requireInput;
inherit (requireInput "n2c" "github:nlewo/nix2container" "std.lib.ops.mkDevOCI") nixpkgs std n2c;
inherit (n2c.packages) nix2container;

l = nixpkgs.lib // builtins;
n2c = inputs.n2c.packages.nix2container;

envToList = {...} @ args:
if args.value != null
Expand Down Expand Up @@ -206,7 +205,7 @@ in
++ (l.optionals vscode [setupVSCode]);

layers = [
(n2c.buildLayer {
(nix2container.buildLayer {
deps = preLoadStorePaths;
copyToRoot = [
(nixpkgs.buildEnv
Expand Down
6 changes: 4 additions & 2 deletions src/lib/ops/mkMicrovm.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{inputs}: let
inherit (inputs) nixpkgs microvm;
let
inherit (inputs.cells.std.errors) requireInput;
inherit (requireInput "microvm" "github:astro/microvm.nix" "std.lib.ops.mkMicrovm") nixpkgs microvm;

nixosSystem = args:
import "${nixpkgs.path}/nixos/lib/eval-config.nix" (args
// {
Expand Down
12 changes: 7 additions & 5 deletions src/lib/ops/mkOCI.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
inputs,
cell,
}: let
inherit (inputs) nixpkgs std;
inherit (inputs.cells.std.errors) requireInput;
inherit (requireInput "n2c" "github:nlewo/nix2container" "std.lib.ops.mkOCI") nixpkgs std n2c;
inherit (n2c.packages) nix2container;

l = nixpkgs.lib // builtins;
n2c = inputs.n2c.packages.nix2container;
in
/*
Creates an OCI container image
Expand Down Expand Up @@ -51,20 +53,20 @@ in
image =
l.throwIf (args ? tag && meta ? tags)
"mkOCI/mkStandardOCI/mkDevOCI: use of `tag` and `meta.tags` arguments are not supported together. Remove the former."
n2c.buildImage (
nix2container.buildImage (
l.recursiveUpdate options {
inherit name tag;

# Layers are nested to reduce duplicate paths in the image
layers =
[
# Primary layer is the entrypoint layer
(n2c.buildLayer {
(nix2container.buildLayer {
deps = [entrypoint];
maxLayers = 50;
layers = [
# Runtime inputs layer
(n2c.buildLayer {
(nix2container.buildLayer {
deps = runtimeInputs;
maxLayers = 10;
})
Expand Down
12 changes: 7 additions & 5 deletions src/lib/ops/mkStandardOCI.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
inputs,
cell,
}: let
inherit (inputs) nixpkgs dmerge;
inherit (inputs.cells.std.errors) requireInput;
inherit (requireInput "n2c" "github:nlewo/nix2container" "std.lib.ops.mkStandardOCI") nixpkgs dmerge n2c;
inherit (n2c.packages) nix2container;

l = nixpkgs.lib // builtins;
n2c = inputs.n2c.packages.nix2container;
in
/*
Creates an OCI container image using the given operable.
Expand Down Expand Up @@ -123,11 +125,11 @@ in
# - env setup w.r.t. certs for ssl-library ecosysystems
layers = [
# Put liveness and readiness probes in a separate layer
(n2c.buildLayer {
(nix2container.buildLayer {
maxLayers = 10;
deps =
(l.optionals hasLivenessProbe [(n2c.buildLayer {deps = [livenessProbe];})])
++ (l.optionals hasReadinessProbe [(n2c.buildLayer {deps = [readinessProbe];})]);
(l.optionals hasLivenessProbe [(nix2container.buildLayer {deps = [livenessProbe];})])
++ (l.optionals hasReadinessProbe [(nix2container.buildLayer {deps = [readinessProbe];})]);
})
];
setup = prepend [setupLinks users nss];
Expand Down

0 comments on commit 5c6d67b

Please sign in to comment.