Unverified Commit e1394695 authored by github-actions[bot]'s avatar github-actions[bot] Committed by GitHub
Browse files

Merge master into staging-next

parents c7aba64b 97927dfa
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@

# pkgs/by-name
/pkgs/test/nixpkgs-check-by-name @infinisil
/pkgs/by-name/README.md @infinisil
/pkgs/top-level/by-name-overlay.nix @infinisil
/.github/workflows/check-by-name.nix @infinisil

# Nixpkgs build-support
/pkgs/build-support/writers @lassulus @Profpatsch
+49 −0
Original line number Diff line number Diff line
# Checks pkgs/by-name (see pkgs/by-name/README.md)
# using the nixpkgs-check-by-name tool (see pkgs/test/nixpkgs-check-by-name)
name: Check pkgs/by-name

# The pre-built tool is fetched from a channel,
# making it work predictable on all PRs
on: pull_request

# The tool doesn't need any permissions, it only outputs success or not based on the checkout
permissions: {}

jobs:
  check:
    # This is x86_64-linux, for which the tool is always prebuilt on the nixos-* channels,
    # as specified in nixos/release-combined.nix
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: cachix/install-nix-action@v22
      - name: Determining channel to use for dependencies
        run: |
          echo "Determining which channel to use for PR base branch $GITHUB_BASE_REF"
          if [[ "$GITHUB_BASE_REF" =~ ^(release|staging|staging-next)-([0-9][0-9]\.[0-9][0-9])$ ]]; then
              # Use the release channel for all PRs to release-XX.YY, staging-XX.YY and staging-next-XX.YY
              channel=nixos-${BASH_REMATCH[2]}
              echo "PR is for a release branch, using release channel $channel"
          else
              # Use the nixos-unstable channel for all other PRs
              channel=nixos-unstable
              echo "PR is for a non-release branch, using unstable channel $channel"
          fi
          echo "channel=$channel" >> "$GITHUB_ENV"
      - name: Fetching latest version of channel
        run: |
          echo "Fetching latest version of channel $channel"
          # This is probably the easiest way to get Nix to output the path to a downloaded channel!
          nixpkgs=$(nix-instantiate --find-file nixpkgs -I nixpkgs=channel:"$channel")
          # This file only exists in channels
          rev=$(<"$nixpkgs"/.git-revision)
          echo "Channel $channel is at revision $rev"
          echo "nixpkgs=$nixpkgs" >> "$GITHUB_ENV"
          echo "rev=$rev" >> "$GITHUB_ENV"
      - name: Fetching pre-built nixpkgs-check-by-name from the channel
        run: |
          echo "Fetching pre-built nixpkgs-check-by-name from channel $channel at revision $rev"
          # Passing --max-jobs 0 makes sure that we won't build anything
          nix-build "$nixpkgs" -A tests.nixpkgs-check-by-name --max-jobs 0
      - name: Running nixpkgs-check-by-name
        run: result/bin/nixpkgs-check-by-name .
+6 −0
Original line number Diff line number Diff line
@@ -12885,6 +12885,12 @@
    githubId = 915970;
    name = "Austin Platt";
  };
  onur-ozkan = {
    name = "Onur Ozkan";
    email = "contact@onurozkan.dev";
    github = "onur-ozkan";
    githubId = 39852038;
  };
  ony = {
    name = "Mykola Orliuk";
    email = "virkony@gmail.com";
+100 −27
Original line number Diff line number Diff line
@@ -2,21 +2,20 @@

{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.virtualisation.lxd;
  preseedFormat = pkgs.formats.yaml {};
in {
  imports = [
    (mkRemovedOptionModule [ "virtualisation" "lxd" "zfsPackage" ] "Override zfs in an overlay instead to override it globally")
    (lib.mkRemovedOptionModule [ "virtualisation" "lxd" "zfsPackage" ] "Override zfs in an overlay instead to override it globally")
  ];

  ###### interface

  options = {
    virtualisation.lxd = {
      enable = mkOption {
        type = types.bool;
      enable = lib.mkOption {
        type = lib.types.bool;
        default = false;
        description = lib.mdDoc ''
          This option enables lxd, a daemon that manages
@@ -32,28 +31,28 @@ in {
        '';
      };

      package = mkOption {
        type = types.package;
      package = lib.mkOption {
        type = lib.types.package;
        default = pkgs.lxd;
        defaultText = literalExpression "pkgs.lxd";
        defaultText = lib.literalExpression "pkgs.lxd";
        description = lib.mdDoc ''
          The LXD package to use.
        '';
      };

      lxcPackage = mkOption {
        type = types.package;
      lxcPackage = lib.mkOption {
        type = lib.types.package;
        default = pkgs.lxc;
        defaultText = literalExpression "pkgs.lxc";
        defaultText = lib.literalExpression "pkgs.lxc";
        description = lib.mdDoc ''
          The LXC package to use with LXD (required for AppArmor profiles).
        '';
      };

      zfsSupport = mkOption {
        type = types.bool;
      zfsSupport = lib.mkOption {
        type = lib.types.bool;
        default = config.boot.zfs.enabled;
        defaultText = literalExpression "config.boot.zfs.enabled";
        defaultText = lib.literalExpression "config.boot.zfs.enabled";
        description = lib.mdDoc ''
          Enables lxd to use zfs as a storage for containers.

@@ -62,8 +61,8 @@ in {
        '';
      };

      recommendedSysctlSettings = mkOption {
        type = types.bool;
      recommendedSysctlSettings = lib.mkOption {
        type = lib.types.bool;
        default = false;
        description = lib.mdDoc ''
          Enables various settings to avoid common pitfalls when
@@ -75,8 +74,67 @@ in {
        '';
      };

      startTimeout = mkOption {
        type = types.int;
      preseed = lib.mkOption {
        type = lib.types.nullOr (lib.types.submodule {
          freeformType = preseedFormat.type;
        });

        default = null;

        description = lib.mdDoc ''
          Configuration for LXD preseed, see
          <https://documentation.ubuntu.com/lxd/en/latest/howto/initialize/#initialize-preseed>
          for supported values.

          Changes to this will be re-applied to LXD which will overwrite existing entities or create missing ones,
          but entities will *not* be removed by preseed.
        '';

        example = lib.literalExpression ''
          {
            networks = [
              {
                name = "lxdbr0";
                type = "bridge";
                config = {
                  "ipv4.address" = "10.0.100.1/24";
                  "ipv4.nat" = "true";
                };
              }
            ];
            profiles = [
              {
                name = "default";
                devices = {
                  eth0 = {
                    name = "eth0";
                    network = "lxdbr0";
                    type = "nic";
                  };
                  root = {
                    path = "/";
                    pool = "default";
                    size = "35GiB";
                    type = "disk";
                  };
                };
              }
            ];
            storage_pools = [
              {
                name = "default";
                driver = "dir";
                config = {
                  source = "/var/lib/lxd/storage-pools/default";
                };
              }
            ];
          }
        '';
      };

      startTimeout = lib.mkOption {
        type = lib.types.int;
        default = 600;
        apply = toString;
        description = lib.mdDoc ''
@@ -91,13 +149,13 @@ in {
          Enables the (experimental) LXD UI.
        '');

        package = mkPackageOption pkgs.lxd-unwrapped "ui" { };
        package = lib.mkPackageOption pkgs.lxd-unwrapped "ui" { };
      };
    };
  };

  ###### implementation
  config = mkIf cfg.enable {
  config = lib.mkIf cfg.enable {
    environment.systemPackages = [ cfg.package ];

    # Note: the following options are also declared in virtualisation.lxc, but
@@ -139,19 +197,19 @@ in {
      wantedBy = [ "multi-user.target" ];
      after = [
        "network-online.target"
        (mkIf config.virtualisation.lxc.lxcfs.enable "lxcfs.service")
        (lib.mkIf config.virtualisation.lxc.lxcfs.enable "lxcfs.service")
      ];
      requires = [
        "network-online.target"
        "lxd.socket"
        (mkIf config.virtualisation.lxc.lxcfs.enable "lxcfs.service")
        (lib.mkIf config.virtualisation.lxc.lxcfs.enable "lxcfs.service")
      ];
      documentation = [ "man:lxd(1)" ];

      path = [ pkgs.util-linux ]
        ++ optional cfg.zfsSupport config.boot.zfs.package;
        ++ lib.optional cfg.zfsSupport config.boot.zfs.package;

      environment = mkIf (cfg.ui.enable) {
      environment = lib.mkIf (cfg.ui.enable) {
        "LXD_UI" = cfg.ui.package;
      };

@@ -173,11 +231,26 @@ in {
        # By default, `lxd` loads configuration files from hard-coded
        # `/usr/share/lxc/config` - since this is a no-go for us, we have to
        # explicitly tell it where the actual configuration files are
        Environment = mkIf (config.virtualisation.lxc.lxcfs.enable)
        Environment = lib.mkIf (config.virtualisation.lxc.lxcfs.enable)
          "LXD_LXC_TEMPLATE_CONFIG=${pkgs.lxcfs}/share/lxc/config";
      };
    };

    systemd.services.lxd-preseed = lib.mkIf (cfg.preseed != null) {
      description = "LXD initialization with preseed file";
      wantedBy = ["multi-user.target"];
      requires = ["lxd.service"];
      after = ["lxd.service"];

      script = ''
        ${pkgs.coreutils}/bin/cat ${preseedFormat.generate "lxd-preseed.yaml" cfg.preseed} | ${cfg.package}/bin/lxd init --preseed
      '';

      serviceConfig = {
        Type = "oneshot";
      };
    };

    users.groups.lxd = {};

    users.users.root = {
@@ -185,7 +258,7 @@ in {
      subGidRanges = [ { startGid = 1000000; count = 65536; } ];
    };

    boot.kernel.sysctl = mkIf cfg.recommendedSysctlSettings {
    boot.kernel.sysctl = lib.mkIf cfg.recommendedSysctlSettings {
      "fs.inotify.max_queued_events" = 1048576;
      "fs.inotify.max_user_instances" = 1048576;
      "fs.inotify.max_user_watches" = 1048576;
@@ -197,6 +270,6 @@ in {
    };

    boot.kernelModules = [ "veth" "xt_comment" "xt_CHECKSUM" "xt_MASQUERADE" "vhost_vsock" ]
      ++ optionals (!config.networking.nftables.enable) [ "iptable_mangle" ];
      ++ lib.optionals (!config.networking.nftables.enable) [ "iptable_mangle" ];
  };
}
+1 −1
Original line number Diff line number Diff line
@@ -446,7 +446,7 @@ in {
  loki = handleTest ./loki.nix {};
  luks = handleTest ./luks.nix {};
  lvm2 = handleTest ./lvm2 {};
  lxd = pkgs.recurseIntoAttrs (handleTest ./lxd {});
  lxd = pkgs.recurseIntoAttrs (handleTest ./lxd { inherit handleTestOn; });
  lxd-image-server = handleTest ./lxd-image-server.nix {};
  #logstash = handleTest ./logstash.nix {};
  lorri = handleTest ./lorri/default.nix {};
Loading