!tDnwWRNkmmYtMXfaZl:nixos.org

Nix Language

1522 Members
Nix programming language268 Servers

Load older messages


SenderMessageTime
13 Oct 2024
@nikita143:matrix.orgанимешник228 changed their display name from nikita143 to анимешник228.19:26:59
@djacu:matrix.orgdjacuOk so what's the problem? There are a few typographical errors21:14:51
@boeufseche:matrix.orgboeufseche joined the room.23:19:00
14 Oct 2024
@frankc0904:matrix.orgfrank joined the room.18:58:23
15 Oct 2024
@tanvir:hackliberty.org𝒕𝒂𝒏𝒗𝒊𝒓 changed their display name from Tanvir to 𝒕𝒂𝒏𝒗𝒊𝒓.16:06:34
@tanvir:hackliberty.org𝒕𝒂𝒏𝒗𝒊𝒓 changed their profile picture.20:15:11
16 Oct 2024
@cx_:matrix.org@cx_:matrix.org left the room.19:23:11
17 Oct 2024
@darkterminal:matrix.orgdavidas joined the room.04:22:57
@barryfm:matrix.org@barryfm:matrix.org left the room.13:34:42
@dmills27:matrix.orgDominic Mills set a profile picture.17:15:01
@perpetrator1:matrix.orgmuneer joined the room.17:25:11
@bendlas:matrix.orgbendlas changed their profile picture.17:37:59
@darkterminal:matrix.orgdavidas changed their display name from David L to davidas.21:13:49
@nikitabobko:matrix.orgNikita Bobko set a profile picture.22:44:26
18 Oct 2024
@rosscomputerguy:matrix.orgTristan Ross joined the room.03:06:01
@old-mate:matrix.orgmate joined the room.04:34:12
@emilazy:matrix.orgemily is there anything clever that can be done to strip location information from an attrset value to ensure that builtins.unsafeGetAttrPos returns null for it? 14:34:09
@emilazy:matrix.orgemily builtins.mapAttrs (_: v: v) "cleans" an entire attrset 15:49:08
@emilazy:matrix.orgemily builtins.listToAttrs [ { name = "a"; value = orig.a; } ] also seems to do it 15:51:36
19 Oct 2024
@dankslush:matrix.orgradrudrod joined the room.01:54:58
@crystal_forceix:matrix.orgCrystal_ForceIX joined the room.03:28:17
@jwillikers:matrix.orgjwillikers joined the room.12:05:29
@infinisil:matrix.orginfinisil
In reply to @emilazy:matrix.org
is there anything clever that can be done to strip location information from an attrset value to ensure that builtins.unsafeGetAttrPos returns null for it?
On my phone right now, so just a guess: Perhaps deepSeq works
14:01:31
20 Oct 2024
@kourtni:matrix.orgKourtni joined the room.06:03:19
@crystal_forceix:matrix.orgCrystal_ForceIX changed their display name from crystal_forceix to Crystal_ForceIX.09:44:24
@sebastian:srx.digitalsebastian joined the room.21:22:21
@sebastian:srx.digitalsebastian

Hello everyone, is there a nice way to recursively convert the names of an attribute set from camalCase to snake_case?

I have the following:

{
  keycloak = {
    displayName = "Keycloak";
    clientId = "semaphore";
    clientSecret = "semaphore";
    providerUrl = "https://keycloak.example.com/realms/master";;
    redirectUrl = "https://semaphore.example.com/api/auth/oidc/keycloak/redirect";;
  };
}

And would need:

{
  keycloak = {
    display_name = "Keycloak";
    client_id = "semaphore";
    client_secret = "l3CVYbqO5zgewnFP02iN9VkQv5u6ngo2vccO8S3BwxU=";
    provider_url = "https://keycloak.example.com/realms/master";;
    redirect_url = "https://semaphore.example.com/api/auth/oidc/keycloak/redirect";;
  };
}

This could simplify my templating considerably and i wouldn't always have to keep the names and rewrite them manually.

I experimented once with the following, but I can't get the iteration to work properly.

let
  camelToSnake = str:
    builtins.foldl'
      (acc: c: acc + (
        if c == lib.toUpper c
        then "_" + lib.toLower c
        else c
      )) ""
      (lib.stringToCharacters str);

  camelCaseToSnakeCaseAttrs = attrs: lib.attrsets.mapAttrs (name: value:
    let
      SnakeCase = camelToSnake name;
    in
      if lib.types.isAttrs value then
        { inherit SnakeCase; } // { SnakeCase = renameAttrs value; }
      else
        { inherit SnakeCase; } // { SnakeCase = value; }
  ) attrs;

  exampleSet = {
    keycloak = {
      displayName = "Keycloak";
      clientId = "semaphore";
      clientSecret = "semaphore";
      providerUrl = "https://keycloak.example.com/realms/master";;
      redirectUrl = "https://semaphore.example.com/api/auth/oidc/keycloak/redirect";;
    };
  };
in

camelCaseToSnakeCaseAttrs exampleSet
21:40:20
@artturin:matrix.orgArtturin
In reply to @sebastian:srx.digital

Hello everyone, is there a nice way to recursively convert the names of an attribute set from camalCase to snake_case?

I have the following:

{
  keycloak = {
    displayName = "Keycloak";
    clientId = "semaphore";
    clientSecret = "semaphore";
    providerUrl = "https://keycloak.example.com/realms/master";;
    redirectUrl = "https://semaphore.example.com/api/auth/oidc/keycloak/redirect";;
  };
}

And would need:

{
  keycloak = {
    display_name = "Keycloak";
    client_id = "semaphore";
    client_secret = "l3CVYbqO5zgewnFP02iN9VkQv5u6ngo2vccO8S3BwxU=";
    provider_url = "https://keycloak.example.com/realms/master";;
    redirect_url = "https://semaphore.example.com/api/auth/oidc/keycloak/redirect";;
  };
}

This could simplify my templating considerably and i wouldn't always have to keep the names and rewrite them manually.

I experimented once with the following, but I can't get the iteration to work properly.

let
  camelToSnake = str:
    builtins.foldl'
      (acc: c: acc + (
        if c == lib.toUpper c
        then "_" + lib.toLower c
        else c
      )) ""
      (lib.stringToCharacters str);

  camelCaseToSnakeCaseAttrs = attrs: lib.attrsets.mapAttrs (name: value:
    let
      SnakeCase = camelToSnake name;
    in
      if lib.types.isAttrs value then
        { inherit SnakeCase; } // { SnakeCase = renameAttrs value; }
      else
        { inherit SnakeCase; } // { SnakeCase = value; }
  ) attrs;

  exampleSet = {
    keycloak = {
      displayName = "Keycloak";
      clientId = "semaphore";
      clientSecret = "semaphore";
      providerUrl = "https://keycloak.example.com/realms/master";;
      redirectUrl = "https://semaphore.example.com/api/auth/oidc/keycloak/redirect";;
    };
  };
in

camelCaseToSnakeCaseAttrs exampleSet

https://github.com/kaii-zen/xinomorf/blob/43092992e19fc533ef8fe67c536d0089870b9220/lib/attrsets.nix#L2
https://github.com/rummik/nixos-config/blob/f88adb6397cdbb775a1b699d866fcb43ef3611a6/users/profiles/nixvim/helpers.nix#L35

  • more at
    https://github.com/search?q=lang%3Anix+snakeTo&type=code
23:25:07
@artturin:matrix.orgArtturin* https://github.com/kaii-zen/xinomorf/blob/43092992e19fc533ef8fe67c536d0089870b9220/lib/attrsets.nix#L2 https://github.com/rummik/nixos-config/blob/f88adb6397cdbb775a1b699d866fcb43ef3611a6/users/profiles/nixvim/helpers.nix#L3 and more at https://github.com/search?q=lang%3Anix+snakeTo&type=code 23:25:29
21 Oct 2024
@tolgaerok:matrix.org@tolgaerok:matrix.org left the room.04:35:09

Show newer messages


Back to Room ListRoom Version: 6