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

Merge master into staging-next

parents b76567c2 8da188f8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -123,7 +123,8 @@ let
    inherit (self.derivations) lazyDerivation optionalDrvAttr;
    inherit (self.meta) addMetaAttrs dontDistribute setName updateName
      appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
      hiPrioSet getLicenseFromSpdxId getLicenseFromSpdxIdOr getExe getExe';
      hiPrioSet licensesSpdx getLicenseFromSpdxId getLicenseFromSpdxIdOr
      getExe getExe';
    inherit (self.filesystem) pathType pathIsDirectory pathIsRegularFile
      packagesFromDirectoryRecursive;
    inherit (self.sources) cleanSourceFilter
+37 −5
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@

let
  inherit (lib) matchAttrs any all isDerivation getBin assertMsg;
  inherit (lib.attrsets) mapAttrs' filterAttrs;
  inherit (builtins) isString match typeOf;

in
@@ -286,11 +287,39 @@ rec {
    ((!pkg?meta.platforms) || any (platformMatch platform) pkg.meta.platforms) &&
    all (elem: !platformMatch platform elem) (pkg.meta.badPlatforms or []);

  /**
    Mapping of SPDX ID to the attributes in lib.licenses.

    For SPDX IDs, see https://spdx.org/licenses.
    Note that some SPDX licenses might be missing.

    # Examples
    :::{.example}
    ## `lib.meta.licensesSpdx` usage example

    ```nix
    lib.licensesSpdx.MIT == lib.licenses.mit
    => true
    lib.licensesSpdx."MY LICENSE"
    => error: attribute 'MY LICENSE' missing
    ```

    :::
  */
  licensesSpdx =
    mapAttrs'
    (_key: license: {
      name = license.spdxId;
      value = license;
    })
    (filterAttrs (_key: license: license ? spdxId) lib.licenses);

  /**
    Get the corresponding attribute in lib.licenses from the SPDX ID
    or warn and fallback to `{ shortName = <license string>; }`.

    For SPDX IDs, see https://spdx.org/licenses
    For SPDX IDs, see https://spdx.org/licenses.
    Note that some SPDX licenses might be missing.

    # Type

@@ -325,7 +354,8 @@ rec {
    Get the corresponding attribute in lib.licenses from the SPDX ID
    or fallback to the given default value.

    For SPDX IDs, see https://spdx.org/licenses
    For SPDX IDs, see https://spdx.org/licenses.
    Note that some SPDX licenses might be missing.

    # Inputs

@@ -361,10 +391,12 @@ rec {
  */
  getLicenseFromSpdxIdOr =
    let
      spdxLicenses = lib.mapAttrs (id: ls: assert lib.length ls == 1; builtins.head ls)
        (lib.groupBy (l: lib.toLower l.spdxId) (lib.filter (l: l ? spdxId) (lib.attrValues lib.licenses)));
      lowercaseLicenses = lib.mapAttrs' (name: value: {
        name = lib.toLower name;
        inherit value;
      }) licensesSpdx;
    in licstr: default:
      spdxLicenses.${ lib.toLower licstr } or default;
      lowercaseLicenses.${ lib.toLower licstr } or default;

  /**
    Get the path to the main program of a package based on meta.mainProgram
+6 −0
Original line number Diff line number Diff line
@@ -17418,6 +17418,12 @@
    githubId = 5265630;
    name = "Michael Köppl";
  };
  returntoreality = {
    email = "linus@lotz.li";
    github = "retuntoreality";
    githubId = 255667;
    name = "Linus Karl";
  };
  revol-xut = {
    email = "revol-xut@protonmail.com";
    name = "Tassilo Tanneberger";
+4 −0
Original line number Diff line number Diff line
@@ -305,6 +305,10 @@

- `programs.vim.defaultEditor` now only works if `programs.vim.enable` is enabled.

- The `indi-full` package no longer contains non-free drivers.
  To get the old collection of drivers use `indi-full-nonfree` or create your own collection of drivers by overriding indi-with-drivers.
  E.g.: `pkgs.indi-with-drivers.override {extraDrivers = with pkgs.indi-3rdparty; [indi-gphoto];}`

- `/share/vim-plugins` now only gets linked if `programs.vim.enable` is enabled

- The `tracy` package no longer works on X11, since it's moved to Wayland
+52 −10
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
  ...
}:
let
  inherit (lib) literalExpression types mkBefore;
  inherit (lib) literalExpression types;

  cfg = config.services.ollama;
  ollamaPackage = cfg.package.override { inherit (cfg) acceleration; };
@@ -50,7 +50,6 @@ in
          The user will automatically be created, if this option is set to a non-null value.
        '';
      };

      group = lib.mkOption {
        type = with types; nullOr str;
        default = cfg.user;
@@ -71,7 +70,6 @@ in
          The home directory that the ollama service is started in.
        '';
      };

      models = lib.mkOption {
        type = types.str;
        default = "${cfg.home}/models";
@@ -98,6 +96,7 @@ in
          Which port the ollama server listens to.
        '';
      };

      acceleration = lib.mkOption {
        type = types.nullOr (
          types.enum [
@@ -136,6 +135,7 @@ in
          ) for details.
        '';
      };

      environmentVariables = lib.mkOption {
        type = types.attrsOf types.str;
        default = { };
@@ -155,7 +155,10 @@ in
        type = types.listOf types.str;
        default = [ ];
        description = ''
          The models to download as soon as the service starts.
          Download these models using `ollama pull` as soon as `ollama.service` has started.

          This creates a systemd unit `ollama-model-loader.service`.

          Search for models of your choice from: https://ollama.com/library
        '';
      };
@@ -164,6 +167,7 @@ in
        default = false;
        description = ''
          Whether to open the firewall for ollama.

          This adds `services.ollama.port` to `networking.firewall.allowedTCPPorts`.
        '';
      };
@@ -200,6 +204,7 @@ in
          Group = cfg.group;
        }
        // {
          Type = "exec";
          DynamicUser = true;
          ExecStart = "${lib.getExe ollamaPackage} serve";
          WorkingDirectory = cfg.home;
@@ -255,13 +260,50 @@ in
          ];
          UMask = "0077";
        };
      postStart = mkBefore ''
        set -x
        export OLLAMA_HOST=${lib.escapeShellArg cfg.host}:${builtins.toString cfg.port}
        for model in ${lib.escapeShellArgs cfg.loadModels}
        do
          ${lib.escapeShellArg (lib.getExe ollamaPackage)} pull "$model"
    };

    systemd.services.ollama-model-loader = lib.mkIf (cfg.loadModels != [ ]) {
      description = "Download ollama models in the background";
      wantedBy = [
        "multi-user.target"
        "ollama.service"
      ];
      after = [ "ollama.service" ];
      bindsTo = [ "ollama.service" ];
      environment = config.systemd.services.ollama.environment;
      serviceConfig = {
        Type = "exec";
        DynamicUser = true;
        Restart = "on-failure";
        # bounded exponential backoff
        RestartSec = "1s";
        RestartMaxDelaySec = "2h";
        RestartSteps = "10";
      };

      script = ''
        total=${toString (builtins.length cfg.loadModels)}
        failed=0

        for model in ${lib.escapeShellArgs cfg.loadModels}; do
          '${lib.getExe ollamaPackage}' pull "$model" &
        done

        for job in $(jobs -p); do
          set +e
          wait $job
          exit_code=$?
          set -e

          if [ $exit_code != 0 ]; then
            failed=$((failed + 1))
          fi
        done

        if [ $failed != 0 ]; then
          echo "error: $failed out of $total attempted model downloads failed" >&2
          exit 1
        fi
      '';
    };

Loading