Home Explore Blog Models CI



nixpkgs

2nd chunk of `doc/build-helpers/images/portableservice.section.md`
d78fdb1190e2a73537801f6418c55fb7f9d712eabe1aa74900000001000008e2
  For each item in the list, `portableService` will create a symlink in the path specified by `symlink` (relative to the root of the image) that points to `object`.

  All packages that `object` depends on and their dependencies are automatically copied into the image.

  This can be used to create symlinks for applications that assume some files to exist globally (`/etc/ssl` or `/bin/bash`, for example).
  See [](#ex-portableService-symlinks) to understand how to do that.

  _Default value:_ `[]`.

`contents` (List of Attribute Set; _optional_)

: A list of additional derivations to be included as-is in the image.
  These derivations will be included directly in a `/nix/store` directory inside the image.

  _Default value:_ `[]`.

`squashfsTools` (Attribute Set; _optional_)

: Allows you to override the package that provides {manpage}`mksquashfs(1)`, which is used internally by `portableService`.

  _Default value:_ `pkgs.squashfsTools`.

`squash-compression` (String; _optional_)

: Passed as the compression option to {manpage}`mksquashfs(1)`, which is used internally by `portableService`.

  _Default value:_ `"xz -Xdict-size 100%"`.

`squash-block-size` (String; _optional_)

: Passed as the block size option to {manpage}`mksquashfs(1)`, which is used internally by `portableService`.

  _Default value:_ `"1M"`.

## Examples {#ssec-pkgs-portableService-examples}

[]{#ex-pkgs-portableService}
:::{.example #ex-portableService-hello}
# Building a Portable Service image

The following example builds a Portable Service image with the `hello` package, along with a service unit that runs it.

```nix
{
  lib,
  writeText,
  portableService,
  hello,
}:
let
  hello-service = writeText "hello.service" ''
    [Unit]
    Description=Hello world service

    [Service]
    Type=oneshot
    ExecStart=${lib.getExe hello}
  '';
in
portableService {
  pname = "hello";
  inherit (hello) version;
  units = [ hello-service ];
}
```

After building the package, the generated image can be loaded into a system through {manpage}`portablectl(1)`:

```shell
$ nix-build
(some output removed for clarity)
/nix/store/8c20z1vh7z8w8dwagl8w87b45dn5k6iq-hello-img-2.12.1

$ portablectl attach /nix/store/8c20z1vh7z8w8dwagl8w87b45dn5k6iq-hello-img-2.12.1/hello_2.12.1.raw

Title: Nix `pkgs.portableService` Attributes and Basic Example
Summary
This chunk continues the description of optional attributes for `pkgs.portableService`, including `contents` for adding derivations directly to `/nix/store` within the image, `squashfsTools` for overriding the `mksquashfs(1)` package, and `squash-compression` and `squash-block-size` for configuring `mksquashfs(1)` options. It then provides an example demonstrating how to build a basic Portable Service image for a 'hello world' application using `portableService`, showing the Nix code to define the service and how to attach the resulting `.raw` image using `portablectl(1)`.