!tDnwWRNkmmYtMXfaZl:nixos.org

Nix Language

1518 Members
Nix programming language267 Servers

Load older messages


SenderMessageTime
23 Aug 2024
@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
@aloisw:kde.org@aloisw:kde.org left the room.18:14:11
28 Aug 2024
@armeen:matrix.orgarmeen left the room.03:18:50
@armeen:matrix.orgarmeen joined the room.03:31:40
@sem:one.ems.hostsem joined the room.10:22:52
@sem:one.ems.hostsemHigh all, does someone know how I can change a number to a string? I would like to use the ${number} syntax to add a value to a string10:24:24
@sem:one.ems.hostsemsomething like builtins.toString. Couldn't find it in the nix manual10:25:16
@infinisil:matrix.orginfinisil

@sem:one.ems.host toString should work?

10:45:44
@infinisil:matrix.orginfinisil"${toString 10}" gives "10"10:46:16
@infinisil:matrix.orginfinisil

(or just toString 10)

10:46:56

Show newer messages


Back to Room ListRoom Version: 6