!tDnwWRNkmmYtMXfaZl:nixos.org

Nix Language

1519 Members
Nix programming language268 Servers

Load older messages


SenderMessageTime
22 Aug 2024
@asmundesen:matrix.orgArtur Manuel changed their profile picture.14:53:03
@benwis:matrix.org@benwis:matrix.org left the room.16:48:21
@niko:puppygock.gaynyanbinary 🏳️‍⚧️ left the room.17:19:40
@mattsturg:matrix.orgMatt Sturgeon
In reply to @asmundesen:matrix.org
moving an issue i have been having to this channel since its more on topic here than #Nix / NixOS But I recently had an issue involving a library function with mkMerge that was a consequence of not using flake-parts.

What did your implementation using mkMerge look like? What is the purpose of the function, i.e. what are you trying to achieve?

I'm sure you've worked this out by now, but mkMerge is not a general use nix function; it is only useful when working with the nixos module system.

21:51:45
@adis:blad.is@adis:blad.is I really wish stuff like mkMerge wasn't in top-level lib. It's confusing as heck. 23:28:39
23 Aug 2024
@lcavalier:matrix.orgfpf3 joined the room.00:30:24
@mattsturg:matrix.orgMatt Sturgeon

Ok, found it: https://matrix.to/#/!RRerllqmbATpmbJgCn:nixos.org/$0WVAvACN5DN8NLuPU7hmS2ZaGKNcCYMxB1jkhb99Lqk?via=nixos.org&via=matrix.org&via=tchncs.de

Artur Manuel

Looks like you are trying to convert a list of config-spec-attrsets into an attrset of nixos configurations. Currently you're passing a list of attrs to genAttrs, which won't work because genAttrs expects a list of string; the strings are also used as the attr names.

I'd recommend having an attrset of config-sepcs instead of a list, and then using mapAttrs to convert them to actual nixos-configurations.

e.g.

let
  mkHosts = builtins.mapAttrs (name: configSpec: inputs.nixpkgs.lib.nixosSystem {
    # TODO
  });
in
nixosConfigurations = mkHosts {
  "freguson" = {
    hostname = "freguson";
    username = "amadal";
    system = "x86_64-linux";
    # etc
  };
};

However, if you don't want to do that, you'll need to use listToAttrs, after maping the list such that the elements have the form { name = "attr_name"; value = "attr_value"; } (as extected by listToAttrs).

e.g.

  builtins.listToAttrs (
    builtins.map
    (configSpec: {
      name = configSpec.hostname;
      value = inputs.nixpkgs.lib.nixosSystem {
        # TODO
      };
    })
    configSpecList
  )
01:14:01
@mattsturg:matrix.orgMatt Sturgeon *

Ok, found it: https://matrix.to/#/!RRerllqmbATpmbJgCn:nixos.org/$0WVAvACN5DN8NLuPU7hmS2ZaGKNcCYMxB1jkhb99Lqk?via=nixos.org&via=matrix.org&via=tchncs.de

Artur Manuel

Looks like you are trying to convert a list of config-spec-attrsets into an attrset of nixos configurations. Currently you're passing a list of attrs to genAttrs, which won't work because genAttrs expects a list of string; the strings are also used as the attr names.

I'd recommend having an attrset of config-sepcs instead of a list, and then using mapAttrs to convert them to actual nixos-configurations.

e.g.

let
  mkHosts = builtins.mapAttrs (name: configSpec: inputs.nixpkgs.lib.nixosSystem {
    # TODO
  });
in
nixosConfigurations = mkHosts {
  "freguson" = {
    hostname = "freguson";
    username = "amadal";
    system = "x86_64-linux";
    # etc
  };
};

However, if you don't want to do that, you'll need to use listToAttrs, after maping the list such that the elements have the form { name = "attr_name"; value = "attr_value"; } (as expected by listToAttrs).

e.g.

  builtins.listToAttrs (
    builtins.map
    (configSpec: {
      name = configSpec.hostname;
      value = inputs.nixpkgs.lib.nixosSystem {
        # TODO
      };
    })
    configSpecList
  )
01:15:32
@mattsturg:matrix.orgMatt Sturgeon *

Ok, found it: https://matrix.to/#/!RRerllqmbATpmbJgCn:nixos.org/$0WVAvACN5DN8NLuPU7hmS2ZaGKNcCYMxB1jkhb99Lqk?via=nixos.org&via=matrix.org&via=tchncs.de

Artur Manuel

Looks like you are trying to convert a list of config-spec-attrsets into an attrset of nixos configurations. Currently you're passing a list of attrs to genAttrs, which won't work because genAttrs expects a list of string; the strings are also used as the attr names.

I'd recommend having an attrset of config-sepcs instead of a list, and then using mapAttrs to convert them to actual nixos-configurations.

e.g.

let
  mkHosts = builtins.mapAttrs (name: configSpec: inputs.nixpkgs.lib.nixosSystem {
    # TODO
  });
in
nixosConfigurations = mkHosts {
  "freguson" = {
    hostname = "freguson";
    username = "amadal";
    system = "x86_64-linux";
    # etc
  };
};

You could also have something like this if you don't want to define the hostname twice:

  mkHosts = builtins.mapAttrs (hostname: configSpec: mkHost ({ inherit hostname; } // configSpec));

However, if you don't want to do that, you'll need to use listToAttrs, after maping the list such that the elements have the form { name = "attr_name"; value = "attr_value"; } (as expected by listToAttrs).

e.g.

  builtins.listToAttrs (
    builtins.map
    (configSpec: {
      name = configSpec.hostname;
      value = inputs.nixpkgs.lib.nixosSystem {
        # TODO
      };
    })
    configSpecList
  )
01:17:56
@mattsturg:matrix.orgMatt Sturgeon *

Ok, found it: https://matrix.to/#/!RRerllqmbATpmbJgCn:nixos.org/$0WVAvACN5DN8NLuPU7hmS2ZaGKNcCYMxB1jkhb99Lqk?via=nixos.org&via=matrix.org&via=tchncs.de Artur Manuel

Looks like you are trying to convert a list of config-spec-attrsets into an attrset of nixos configurations. Currently you're passing a list of attrs to genAttrs, which won't work because genAttrs expects a list of string; the strings are also used as the attr names.

I'd recommend having an attrset of config-sepcs instead of a list, and then using mapAttrs to convert them to actual nixos-configurations.

e.g.

let
  mkHosts = builtins.mapAttrs (name: configSpec: inputs.nixpkgs.lib.nixosSystem {
    # TODO
  });
in
nixosConfigurations = mkHosts {
  "freguson" = {
    hostname = "freguson";
    username = "amadal";
    system = "x86_64-linux";
    # etc
  };
};

You could also have something like this if you don't want to define the hostname twice:

  mkHosts = builtins.mapAttrs (hostname: configSpec: mkHost ({ inherit hostname; } // configSpec));

However, if you don't want to do that, you'll need to use listToAttrs, after maping the list such that the elements have the form { name = "attr_name"; value = "attr_value"; } (as expected by listToAttrs).

e.g.

  builtins.listToAttrs (
    builtins.map
    (configSpec: {
      name = configSpec.hostname;
      value = inputs.nixpkgs.lib.nixosSystem {
        # TODO
      };
    })
    configSpecList
  )
01:18:38
@lmmohr:matrix.orglmmohr joined the room.01:24:13
@asmundesen:matrix.orgArtur Manuelcheers, i just found my own solution just a little over 4 hours ago but i appreciate the help! ill note the use of mapAttrs04:13:35
@brisingr05:matrix.orgbrisingr05Redacted or Malformed Event06:22:10
@brisingr05:matrix.orgbrisingr05* Is it possible to use `lib.lists.remove` to remove multiple elements from a list rather than just one? Or a similar function?06:22:39
@rolfst:matrix.orgrolfst joined the room.13:14:55
@9999years:matrix.org@9999years:matrix.org left the room.18:25:18
@benjaminedwardwebb:envs.netbenwebb left the room.19:00:10
24 Aug 2024
@shymega:one.ems.host@shymega:one.ems.host changed their display name from Dom Rodriguez (shymega) to [DEPRECATED] Dom 'shymega' Rodriguez.01:58:38
@darkwater4213:matrix.org@darkwater4213:matrix.org left the room.02:21:18
@lychee:wires.cafelychee changed their profile picture.04:25:41
@nydragon:matrix.org@nydragon:matrix.org left the room.14:16:10
@zmitchell:matrix.org@zmitchell:matrix.org left the room.19:40:37
25 Aug 2024
@lineararray:matrix.orgLinearArray changed their profile picture.05:01:29
@mattsturg:matrix.orgMatt Sturgeon

I have a function that internally calls lib.evalModules and returns the result's config.test.derivation (a types.package option that depends on several other option values).

I'm trying to write a regression test that checks whether this (correctly) fails to evaluate when some of those option dependencies are invalid. I figued I'd use builtins.tryEval and then pass the resulting .success into a test-derivation:

let
  module = { foo = null; };
  test = fnThatReturnsTest { inherit module; };
  result = builtins.tryEval test;
in
pkgs.runCommand "fail-to-eval-test" { inherit (result) success; } ''
  if [ $success ]; then
    echo "Failed to fail!"
    exit 1
  fi
  touch $out
''

However, success is always true. If I pass result.value into the derivation, however, my expression fails to evaluate (as expected).

I've also tried doing result = builtins.tryEval (builtins.deepSeq test) but this made no difference.

I could use nix-build to evaluate the result within my test-derivation's buildscript (and then check it fails and check its output), but I'd like to understand why tryEval isn't doing what I expected in this scenario.

16:07:16
@mattsturg:matrix.orgMatt Sturgeon If I copy my fnThatReturnsTest and have it instead return the invalid option (in this example .config.foo), then tryEval behaves as expected.
But it doesn't seem to work as expected when evaluating an option value that depends on an invalid option.
16:13:52
26 Aug 2024
@fabdb:mokasin.de@fabdb:mokasin.de left the room.08:45:32
@tanvir:hackliberty.org𝒕𝒂𝒏𝒗𝒊𝒓 changed their profile picture.22:38:36
27 Aug 2024
@highda:matrix.highda.spacehighda joined the room.09:26:44
@dyst:matrix.org@dyst:matrix.org left the room.11:25:22
@duckunix:matrix.orgduckunix joined the room.15:03:38

Show newer messages


Back to Room ListRoom Version: 6