Skip to content

Commit

Permalink
Support ZFS subdirs
Browse files Browse the repository at this point in the history
  • Loading branch information
patricoferris committed Apr 19, 2024
1 parent f7bc569 commit bd9ce2b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
26 changes: 26 additions & 0 deletions docs/zfs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ZFS Setup

The best store to use as a backend is probably ZFS. A simple setup without
changing your whole system to ZFS might look something like:


```
truncate --size XG zfs.img
sudo zpool create obuilder-zfs $PWD/zfs.img
```

And then you can run shark (from source, in a development mode).

```
sudo env "PATH=$PATH" dune exec -- shark md specs/shark.md --store=zfs:obuilder-zfs --verbose
```

If your system is booted from ZFS, then there might some `<hostname>` ZFS pool, and you will want
the datasets to be stored under a sub-dataset name for example `shark`.

```
sudo env "PATH=$PATH" dune exec -- shark md specs/shark.md --store=zfs:<hostname>:shark --zfs-path-without-pool --verbose
```

The files will be available from `/shark/results/<hash>/rootfs` after this.

27 changes: 9 additions & 18 deletions src/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@ let ( / ) = Filename.concat
module Sandbox = Obuilder.Native_sandbox
module Store_spec = Obuilder.Store_spec

let store_of_string = function
| `Rsync path -> `Rsync (path, Obuilder.Rsync_store.Copy)
| (`Zfs _ | `Btrfs _ | `Xfs _ | `Docker _) as v -> v

let config_path =
let _config_path =
match Sys.getenv_opt "SHARK_CONFIG" with
| Some config -> config
| None -> (
match Sys.getenv_opt "HOME" with
| Some home -> Filename.concat home ".shark"
| None -> failwith "No SHARK_CONFIG or HOME environment variables")

let store_or_default v =
match Option.map store_of_string v with
| Some store -> Obuilder.Store_spec.to_store store
| None ->
let config = In_channel.with_open_bin config_path In_channel.input_all in
let config = Shark.Config.t_of_sexp (Sexplib.Sexp.of_string config) in
Obuilder.Store_spec.to_store config.store
(* TODO: Default store config is disabled for now *)
let store_or_default = function store -> store
(* | None ->
let config = In_channel.with_open_bin config_path In_channel.input_all in
let config = Shark.Config.t_of_sexp (Sexplib.Sexp.of_string config) in
Obuilder.Store_spec.to_store config.store *)

let run_eventloop ~clock main =
Lwt_eio.with_event_loop ~clock @@ fun _ -> main ()
Expand Down Expand Up @@ -196,7 +191,7 @@ let template ~clock ~fs () file directory =
Ok ()

let config () =
let config = Shark.Config.{ store = `Zfs "obuilder-zfs" } in
let config = Shark.Config.{ store = `Zfs (None, "obuilder-zfs", false) } in
Fmt.pr "%a" Sexplib.Sexp.pp_hum (Shark.Config.sexp_of_t config);
Ok ()

Expand Down Expand Up @@ -243,11 +238,7 @@ let src_dir =
@@ Arg.pos 0 Arg.(some dir) None
@@ Arg.info ~doc:"Directory containing the source files." ~docv:"DIR" []

let store =
Arg.value
@@ Arg.opt Arg.(some Store_spec.store_t) None
@@ Arg.info ~doc:"Store for shark, defaults to configuration file."
~docv:"STORE" [ "store" ]
let store = Store_spec.cmdliner

let no_run =
Arg.value @@ Arg.flag
Expand Down

0 comments on commit bd9ce2b

Please sign in to comment.