patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 06147eb8d1b713faac9b69ffdf42138d0c3e3093 6775 bytes (raw)
name: host/rootfs/default.nix 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
 
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2021-2025 Alyssa Ross <hi@alyssa.is>
# SPDX-FileCopyrightText: 2022 Unikie

import ../../lib/call-package.nix (
{ callSpectrumPackage, spectrum-build-tools, src
, pkgsMusl, pkgsStatic, linux_latest
, config
}:
pkgsStatic.callPackage (

{ spectrum-host-tools
, lib, stdenvNoCC, nixos, runCommand, writeClosure, erofs-utils, s6-rc
, busybox, cloud-hypervisor, cryptsetup, dbus, execline, inkscape
, iproute2, inotify-tools, jq, mdevd, s6, s6-linux-init, socat
, util-linuxMinimal, virtiofsd, xorg, xdg-desktop-portal-spectrum-host
, btrfs-progs
}:

let
  inherit (nixosAllHardware.config.hardware) firmware;
  inherit (lib)
    concatMapStringsSep concatStrings escapeShellArgs fileset optionalAttrs
    mapAttrsToList systems trivial;

  pkgsGui = pkgsMusl.extend (
    _: super:
    (optionalAttrs (systems.equals pkgsMusl.stdenv.hostPlatform super.stdenv.hostPlatform) {
      flatpak = super.flatpak.override {
        withMalcontent = false;
      };
    })
  );

  foot = pkgsGui.foot.override { allowPgo = false; };

  packages = [
    btrfs-progs cloud-hypervisor cryptsetup dbus execline inotify-tools
    iproute2 jq mdevd s6 s6-linux-init s6-rc socat spectrum-host-tools
    virtiofsd xdg-desktop-portal-spectrum-host

    (busybox.override {
      # Use a separate file as it is a bit too big.
      extraConfig = builtins.readFile ./busybox-config;
    })

  # Take kmod from pkgsGui since we use pkgsGui.kmod.lib below anyway.
  ] ++ (with pkgsGui; [ cosmic-files crosvm foot fuse3 kmod ]);


  nixosAllHardware = nixos ({ modulesPath, ... }: {
    imports = [ (modulesPath + "/profiles/all-hardware.nix") ];

    system.stateVersion = trivial.release;
  });

  kernel = linux_latest;

  appvm = callSpectrumPackage ../../img/app { inherit (foot) terminfo; };
  netvm = callSpectrumPackage ../../vm/sys/net { inherit (foot) terminfo; };

  # Packages that should be fully linked into /usr,
  # (not just their bin/* files).
  #
  # kmod.lib is dlopen()ed by systemd-udevd via libsystemd-shared.so.
  # It doesn't get picked up from libsystemd-shared.so's RUNPATH due to
  # https://inbox.vuxu.org/musl/20251017-dlopen-use-rpath-of-caller-dso-v1-1-46c69eda1473@iscas.ac.cn/
  usrPackages = [
    appvm kernel.modules firmware netvm
  ] ++ (with pkgsGui; [
    dejavu_fonts kmod.lib mesa westonLite
    # Work around NixOS/nixpkgs#459020: without "withImportd = true"
    # systemd-pull doesn't get built, so systemd-sysupdate doesn't work.
    # TODO: remove this when NixOS/nixpkgs#461277 is merged.
    (systemd.override {
      withImportd = true;
      withSysupdate = true;
    })
  ]);

  appvms = {
    appvm-firefox = callSpectrumPackage ../../vm/app/firefox.nix {};
    appvm-foot = callSpectrumPackage ../../vm/app/foot.nix {};
    appvm-gnome-text-editor = callSpectrumPackage ../../vm/app/gnome-text-editor.nix {};
    appvm-systemd-sysupdate = callSpectrumPackage ../../vm/app/systemd-sysupdate {};
  };

  update-url =
    let update-url = config.update-url; in
    # Use builtins.fromJSON because it supports \uXXXX escapes.
    # This is the same check done by check-url.awk in the update VM.
    # The update code is careful to escape any metacharacters, but some
    # simply cannot be made to work.  Concatenating the URL with /SHA256SUMS
    # must append to the path portion of the URL, and the URL must be one
    # that libcurl will accept.  I don't know how Unicode space is handled,
    # but it is a bad idea.
    if builtins.match (builtins.fromJSON "\"^[^\\u0001- #?\\u007F[:space:]]+$\"" update-url) == null then
      builtins.abort ''
        Update URL ${builtins.toJSON update-url} has forbidden characters.
        Query strings, and fragment specifiers are not supported.
        ASCII control characters and whitespace must be %-encoded.
        ''
    else
      update-url;
  packagesSysroot = runCommand "packages-sysroot" {
    depsBuildBuild = [ inkscape ];
    nativeBuildInputs = [ xorg.lndir ];
    src = builtins.path { name = "os-release"; path = ./os-release.in; };
  } ''
    mkdir -p $out/usr/bin $out/usr/share/dbus-1/services \
      $out/usr/share/icons/hicolor/20x20/apps

    # lndir silently ignores existing links, so run it before ln
    # so that ln catches any duplicates.
    for pkg in ${escapeShellArgs usrPackages}; do
        lndir -ignorelinks -silent "$pkg" "$out/usr"
    done

    # If systemd-pull is missing systemd-sysupdate will fail with a
    # very confusing error message.
    for i in sysupdate pull; do
        if ! cat -- "$out/usr/lib/systemd/systemd-$i" > /dev/null; then
            echo "link to systemd-$i didn't get installed" >&2
            exit 1
        fi
    done

    # Weston doesn't support SVG icons.
    inkscape -w 20 -h 20 \
        -o $out/usr/share/icons/hicolor/20x20/apps/com.system76.CosmicFiles.png \
        ${pkgsGui.cosmic-files}/share/icons/hicolor/24x24/apps/com.system76.CosmicFiles.svg

    ln -st $out/usr/bin \
        ${concatMapStringsSep " " (p: "${p}/bin/*") packages} \
        ${pkgsGui.xdg-desktop-portal}/libexec/xdg-document-portal \
        ${pkgsGui.xdg-desktop-portal-gtk}/libexec/xdg-desktop-portal-gtk
    ln -st $out/usr/share/dbus-1 \
        ${dbus}/share/dbus-1/session.conf
    ln -st $out/usr/share/dbus-1/services \
        ${pkgsGui.xdg-desktop-portal-gtk}/share/dbus-1/services/org.freedesktop.impl.portal.desktop.gtk.service

    ln -st "$out/usr/bin" ${util-linuxMinimal}/bin/*

    ${concatStrings (mapAttrsToList (name: path: ''
      ln -s ${path} $out/usr/lib/spectrum/vm/${name}
    '') appvms)}
  '';
in

stdenvNoCC.mkDerivation {
  name = "spectrum-rootfs";

  src = fileset.toSource {
    root = ../..;
    fileset = fileset.intersection src (fileset.unions [
      ./.
      ../../lib/common.mk
      ../../scripts/make-erofs.sh
    ]);
  };
  sourceRoot = "source/host/rootfs";

  nativeBuildInputs = [ cryptsetup erofs-utils spectrum-build-tools s6-rc ];

  env = {
    PACKAGES = runCommand "packages" {} ''
      printf "%s\n/\n" ${packagesSysroot} >$out
      sed p ${writeClosure [ packagesSysroot] } >>$out
    '';
    UPDATE_SIGNING_KEY = config.update-signing-key;
    UPDATE_URL = update-url;
    VERSION = config.version;
  };

  # The Makefile uses $(ROOT_FS_DIR), not $(dest), so it can share code
  # with other Makefiles that also use this variable.
  makeFlags = [ "ROOT_FS_DIR=$(out)" ];

  dontInstall = true;

  enableParallelBuilding = true;

  __structuredAttrs = true;
  unsafeDiscardReferences = { out = true; };
  dontFixup = true;

  passthru = {
    inherit appvm firmware kernel nixosAllHardware packagesSysroot pkgsGui;
  };

  meta = with lib; {
    license = licenses.eupl12;
    platforms = platforms.linux;
  };
}
) {}) (_: {})

debug log:

solving 06147eb8d1b713faac9b69ffdf42138d0c3e3093 ...
found 06147eb8d1b713faac9b69ffdf42138d0c3e3093 in https://inbox.spectrum-os.org/spectrum-devel/20251119-updates-v3-14-b88a99915509@gmail.com/
found f0b7e061a1f39b3e70d337ef4fe14c98a8f022c8 in https://inbox.spectrum-os.org/spectrum-devel/20251119-updates-v3-12-b88a99915509@gmail.com/
found 26d6dc3f9a63680bf1867c9769f807dc562c81c9 in https://inbox.spectrum-os.org/spectrum-devel/20251119-updates-v3-2-b88a99915509@gmail.com/
found 84b536eda397adfab0fbb0122a5765571d7d678e in https://inbox.spectrum-os.org/spectrum-devel/20251119-updates-v3-1-b88a99915509@gmail.com/
found 1578155fa0fb9a4df3fb4884e21ed7d8d8f821dc in https://inbox.spectrum-os.org/spectrum-devel/20251121-refactor-verity-v5-1-938fc95f9752@gmail.com/ ||
	https://inbox.spectrum-os.org/spectrum-devel/20251119-refactor-verity-v4-1-9bc56d5216c0@gmail.com/
found 0ac70c7c077c0656c5820a5d8b3c7ce0e7c78e54 in https://spectrum-os.org/git/spectrum
preparing index
index prepared:
100644 0ac70c7c077c0656c5820a5d8b3c7ce0e7c78e54	host/rootfs/default.nix

applying [1/5] https://inbox.spectrum-os.org/spectrum-devel/20251121-refactor-verity-v5-1-938fc95f9752@gmail.com/
diff --git a/host/rootfs/default.nix b/host/rootfs/default.nix
index 0ac70c7c077c0656c5820a5d8b3c7ce0e7c78e54..1578155fa0fb9a4df3fb4884e21ed7d8d8f821dc 100644

Checking patch host/rootfs/default.nix...
Applied patch host/rootfs/default.nix cleanly.

skipping https://inbox.spectrum-os.org/spectrum-devel/20251119-refactor-verity-v4-1-9bc56d5216c0@gmail.com/ for 1578155fa0fb9a4df3fb4884e21ed7d8d8f821dc
index at:
100644 1578155fa0fb9a4df3fb4884e21ed7d8d8f821dc	host/rootfs/default.nix

applying [2/5] https://inbox.spectrum-os.org/spectrum-devel/20251119-updates-v3-1-b88a99915509@gmail.com/
diff --git a/host/rootfs/default.nix b/host/rootfs/default.nix
index 1578155fa0fb9a4df3fb4884e21ed7d8d8f821dc..84b536eda397adfab0fbb0122a5765571d7d678e 100644


applying [3/5] https://inbox.spectrum-os.org/spectrum-devel/20251119-updates-v3-2-b88a99915509@gmail.com/
diff --git a/host/rootfs/default.nix b/host/rootfs/default.nix
index 84b536eda397adfab0fbb0122a5765571d7d678e..26d6dc3f9a63680bf1867c9769f807dc562c81c9 100644


applying [4/5] https://inbox.spectrum-os.org/spectrum-devel/20251119-updates-v3-12-b88a99915509@gmail.com/
diff --git a/host/rootfs/default.nix b/host/rootfs/default.nix
index 26d6dc3f9a63680bf1867c9769f807dc562c81c9..f0b7e061a1f39b3e70d337ef4fe14c98a8f022c8 100644


applying [5/5] https://inbox.spectrum-os.org/spectrum-devel/20251119-updates-v3-14-b88a99915509@gmail.com/
diff --git a/host/rootfs/default.nix b/host/rootfs/default.nix
index f0b7e061a1f39b3e70d337ef4fe14c98a8f022c8..06147eb8d1b713faac9b69ffdf42138d0c3e3093 100644

Checking patch host/rootfs/default.nix...
Applied patch host/rootfs/default.nix cleanly.
Checking patch host/rootfs/default.nix...
Applied patch host/rootfs/default.nix cleanly.
Checking patch host/rootfs/default.nix...
Applied patch host/rootfs/default.nix cleanly.
Checking patch host/rootfs/default.nix...
Applied patch host/rootfs/default.nix cleanly.

index at:
100644 06147eb8d1b713faac9b69ffdf42138d0c3e3093	host/rootfs/default.nix

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).