Skip to content

Commit 7e01298

Browse files
fix(format): fix exclusion and dont double run on ci
1 parent 5a530ee commit 7e01298

19 files changed

Lines changed: 259 additions & 159 deletions

File tree

.github/workflows/lint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Lint
33
on:
44
pull_request:
55
push:
6+
branches:
7+
- master
68

79
jobs:
810
lint:

flake.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
projectRootFile = "flake.nix";
3838
programs = {
3939
gofmt.enable = true;
40-
nixfmt = {
41-
enable = true;
42-
excludes = [ "pkgs/*" ]; # exclude generated packages
43-
};
40+
nixfmt.enable = true;
4441
};
42+
settings.formatter.nixfmt.excludes = [
43+
"pkgs/**"
44+
];
4545
};
4646
in
4747
{

lib/default.nix

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,100 @@
11
{ pkgs }:
22

33
with pkgs.lib;
4-
{
5-
# Add your library functions here
6-
#
7-
# hexint = x: hexvals.${toLower x};
4+
let
5+
jsonFormat = pkgs.formats.json { };
6+
in
7+
rec {
8+
/**
9+
Recursively clean an attribute set for JSON serialization by removing all `null` values and any attribute sets that become empty as a result.
10+
11+
Nix module options declared with `default = null` or `default = { }` are always present in the evaluated config, even when the user never sets them.
12+
Passing such a config through `builtins.toJSON` produces explicit `null` entries and empty objects in the output.
13+
Downstream applications may misinterpret these as intentionally configured values
14+
— for example, an empty `"oauth": {}` block causes Crush to attempt an OAuth token refresh on providers that don't support it.
15+
16+
# Inputs
17+
`value` : The value to clean. Typically an attribute set, but any Nix value is accepted and non-attrset, non-list values are returned as-is.
18+
19+
# Type
20+
```
21+
removeNulls :: a -> a
22+
```
23+
24+
# Examples
25+
:::{.example}
26+
## `charmLib.removeNulls` usage example
27+
28+
```nix
29+
removeNulls {
30+
name = "Ollama";
31+
api_key = null;
32+
oauth = { access_token = null; refresh_token = null; };
33+
models = [{ id = "qwen3:8b"; cost_per_1m_in = null; }];
34+
}
35+
=> {
36+
name = "Ollama";
37+
models = [{ id = "qwen3:8b"; }];
38+
}
39+
```
40+
:::
41+
*/
42+
removeNulls =
43+
let
44+
clean =
45+
value:
46+
if builtins.isAttrs value then
47+
let
48+
filtered = filterAttrs (_: v: v != null) value;
49+
cleaned = mapAttrs (_: clean) filtered;
50+
in
51+
filterAttrs (_: v: !(builtins.isAttrs v && v == { })) cleaned
52+
else if builtins.isList value then
53+
map clean value
54+
else
55+
value;
56+
in
57+
clean;
58+
59+
/**
60+
Generate a pretty-printed JSON file from an attribute set, with all `null` values and empty objects recursively removed.
61+
62+
Combines `removeNulls` with `pkgs.formats.json` (which uses `jq` under the hood) to produce a human-readable, clean JSON file suitable for use as `home.file.*.source` or `environment.etc.*.source`.
63+
64+
# Inputs
65+
`attrs` : The attribute set to serialize.
66+
67+
# Type
68+
```
69+
toCleanJSON :: AttrSet -> Derivation
70+
```
71+
72+
# Examples
73+
:::{.example}
74+
## `charmLib.toCleanJSON` usage example
75+
76+
```nix
77+
home.file.".config/crush/crush.json".source = charmLib.toCleanJSON {
78+
providers.ollama = {
79+
name = "Ollama";
80+
api_key = null;
81+
base_url = "http://localhost:11434/v1/";
82+
};
83+
};
84+
```
85+
86+
Produces a pretty-printed JSON file containing:
87+
```json
88+
{
89+
"providers": {
90+
"ollama": {
91+
"base_url": "http://localhost:11434/v1/",
92+
"name": "Ollama"
93+
}
94+
}
95+
}
96+
```
97+
:::
98+
*/
99+
toCleanJSON = attrs: jsonFormat.generate "settings.json" (removeNulls attrs);
8100
}

modules/crush/darwin.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
let
88
cfg = config.programs.crush;
99
charmLib = import ../../lib { inherit pkgs; };
10-
in {
10+
in
11+
{
1112
options = import ./options { inherit pkgs; };
1213

1314
config = lib.mkIf cfg.enable {
1415
environment.systemPackages = [ cfg.package ];
15-
environment.etc."crush/crush.json" = lib.mkIf (cfg.settings != {}) {
16+
environment.etc."crush/crush.json" = lib.mkIf (cfg.settings != { }) {
1617
source = charmLib.toCleanJSON cfg.settings;
1718
};
1819
};

modules/crush/home-manager.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
}:
77
let
88
cfg = config.programs.crush;
9+
charmLib = import ../../lib { inherit pkgs; };
910
in
1011
{
1112
options = import ./options { inherit pkgs; };
1213

1314
config = lib.mkIf cfg.enable {
1415
home.packages = [ cfg.package ];
1516
home.file.".config/crush/crush.json" = lib.mkIf (cfg.settings != { }) {
16-
text = builtins.toJSON cfg.settings;
17+
source = charmLib.toCleanJSON cfg.settings;
1718
};
1819
};
1920
}

modules/crush/nixos.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
}:
77
let
88
cfg = config.programs.crush;
9+
charmLib = import ../../lib { inherit pkgs; };
910
in
1011
{
1112
options = import ./options { inherit pkgs; };
1213

1314
config = lib.mkIf cfg.enable {
1415
environment.systemPackages = [ cfg.package ];
1516
environment.etc."crush/crush.json" = lib.mkIf (cfg.settings != { }) {
16-
text = builtins.toJSON cfg.settings;
17+
source = charmLib.toCleanJSON cfg.settings;
1718
mode = "0644";
1819
};
1920
};

pkgs/charm/default.nix

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# This file was generated by GoReleaser. DO NOT EDIT.
22
# vim: set ft=nix ts=2 sw=2 sts=2 et sta
3-
{ system ? builtins.currentSystem, pkgs, lib, fetchurl, installShellFiles }:
3+
{
4+
lib,
5+
fetchurl,
6+
installShellFiles,
7+
stdenvNoCC,
8+
}:
49
let
10+
inherit (stdenvNoCC.hostPlatform) system;
511
shaMap = {
612
i686-linux = "0k2nhni9k38p4pf8cbvm54msqxd1akfdlzsby5cqyncl3649mkd3";
713
x86_64-linux = "1scwhprx8slz6b82iw8za0zhalkfq8634pcmf73xzw799jg2xirx";
@@ -19,7 +25,8 @@ let
1925
x86_64-darwin = "https://github.com/charmbracelet/charm/releases/download/v0.12.6/charm_0.12.6_Darwin_x86_64.tar.gz";
2026
aarch64-darwin = "https://github.com/charmbracelet/charm/releases/download/v0.12.6/charm_0.12.6_Darwin_arm64.tar.gz";
2127
};
22-
in pkgs.stdenv.mkDerivation {
28+
in
29+
stdenvNoCC.mkDerivation {
2330
pname = "charm";
2431
version = "0.12.6";
2532
src = fetchurl {
@@ -38,12 +45,11 @@ in pkgs.stdenv.mkDerivation {
3845
installShellCompletion ./completions/*
3946
'';
4047

41-
system = system;
42-
4348
meta = with lib; {
44-
description = "The Charm Tool and Library 🌟";
49+
description = "The Charm Tool and Library 🌟 (deprecated: will be removed July 2026)";
4550
homepage = "https://charm.sh/";
4651
license = licenses.mit;
52+
broken = true;
4753

4854
platforms = [
4955
"aarch64-darwin"

pkgs/confettysh/default.nix

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# This file was generated by GoReleaser. DO NOT EDIT.
22
# vim: set ft=nix ts=2 sw=2 sts=2 et sta
33
{
4-
system ? builtins.currentSystem
5-
, lib
6-
, fetchurl
7-
, installShellFiles
8-
, stdenvNoCC
4+
lib,
5+
fetchurl,
6+
installShellFiles,
7+
stdenvNoCC,
98
}:
109
let
10+
inherit (stdenvNoCC.hostPlatform) system;
1111
shaMap = {
1212
i686-linux = "17ispz81zm6jab1fg1hipn30fairbwc4rwmi6295i1xyjdskikvk";
1313
x86_64-linux = "1cz49igkfmxngy0j8qcrjqgf481nciah1i8wb52s39kvwfp9w4k0";
@@ -51,8 +51,6 @@ stdenvNoCC.mkDerivation {
5151
cp -vr ./confettysh $out/bin/confettysh
5252
'';
5353

54-
system = system;
55-
5654
meta = {
5755
description = "Confetty over SSH";
5856
homepage = "https://charm.sh/";

pkgs/freeze/default.nix

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# This file was generated by GoReleaser. DO NOT EDIT.
22
# vim: set ft=nix ts=2 sw=2 sts=2 et sta
33
{
4-
system ? builtins.currentSystem
5-
, lib
6-
, fetchurl
7-
, installShellFiles
8-
, stdenvNoCC
4+
lib,
5+
fetchurl,
6+
installShellFiles,
7+
stdenvNoCC,
98
}:
109
let
10+
inherit (stdenvNoCC.hostPlatform) system;
1111
shaMap = {
1212
i686-linux = "0dyhsxb1cz3d95b45ryi2gyim592knikh86advgqvar6h369m497";
1313
x86_64-linux = "16skacpljnfcfi9v0rdmsg8dg4vds4saqah5z5q9bhf02vfxnbq1";
@@ -51,8 +51,6 @@ stdenvNoCC.mkDerivation {
5151
cp -vr ./freeze $out/bin/freeze
5252
'';
5353

54-
system = system;
55-
5654
meta = {
5755
description = "Generate images of code and terminal output.";
5856
homepage = "https://charm.sh/";

pkgs/glow/default.nix

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
# This file was generated by GoReleaser. DO NOT EDIT.
22
# vim: set ft=nix ts=2 sw=2 sts=2 et sta
33
{
4-
system ? builtins.currentSystem
5-
, lib
6-
, fetchurl
7-
, installShellFiles
8-
, stdenvNoCC
4+
lib,
5+
fetchurl,
6+
installShellFiles,
7+
stdenvNoCC,
98
}:
109
let
10+
inherit (stdenvNoCC.hostPlatform) system;
1111
shaMap = {
12-
i686-linux = "1598hvs3z4wdma6njd8xi4phlwiq9cn80ksk986gd5k4q3pc8j62";
13-
x86_64-linux = "0zy27bzlhvpgyp9a6fqigi75ikdcnyxjg0qpl6ys1ck9pq46n42r";
14-
armv7l-linux = "1s7lbplgksdfa5qwv2k7bsd8cza25prapmgfkvd4js8xh084226g";
15-
aarch64-linux = "0ggg2xww8qdpivwqdngxan053hlb5r538q28yb50dzbfrh1sf4mb";
16-
x86_64-darwin = "06qnx62hd1w3r40bw0z0n59jjv2fmacd3qm64wriji4vcny4wcwi";
17-
aarch64-darwin = "03c65cqz3bf9pbc54aqj98v7k56s50nxdv3pvif7gg6fs2kj0ji3";
12+
i686-linux = "1ygwpvrwhpajzjvd74wvj66wy01lnz9hgjiwcqjbslnnlx1vhpkm";
13+
x86_64-linux = "1m87bck6l46h2r4dyhcbm9h1cf79blb1x0x0pgsab0lamzrd8qv0";
14+
armv7l-linux = "0fx05cq8gbdv5kir05nkp8pdrlm09f5lknxamaj6b2f3f01lz2hh";
15+
aarch64-linux = "1690jnvdpbc4vh2lgs00m4bvzv3w1qlphpcnvc4jkdshrgmsnqyg";
16+
x86_64-darwin = "1lwfm17y2sxdhgd54cc74kacbz2k043kckgkxl2fhs3wjjj7ig4c";
17+
aarch64-darwin = "135vgvy8kghjfa3zk536idp92m65kh0zmlk71rxvz7z6gnsbyykg";
1818
};
1919

2020
urlMap = {
21-
i686-linux = "https://github.com/charmbracelet/glow/releases/download/v2.1.1/glow_2.1.1_Linux_i386.tar.gz";
22-
x86_64-linux = "https://github.com/charmbracelet/glow/releases/download/v2.1.1/glow_2.1.1_Linux_x86_64.tar.gz";
23-
armv7l-linux = "https://github.com/charmbracelet/glow/releases/download/v2.1.1/glow_2.1.1_Linux_arm.tar.gz";
24-
aarch64-linux = "https://github.com/charmbracelet/glow/releases/download/v2.1.1/glow_2.1.1_Linux_arm64.tar.gz";
25-
x86_64-darwin = "https://github.com/charmbracelet/glow/releases/download/v2.1.1/glow_2.1.1_Darwin_x86_64.tar.gz";
26-
aarch64-darwin = "https://github.com/charmbracelet/glow/releases/download/v2.1.1/glow_2.1.1_Darwin_arm64.tar.gz";
21+
i686-linux = "https://github.com/charmbracelet/glow/releases/download/v2.1.2/glow_2.1.2_Linux_i386.tar.gz";
22+
x86_64-linux = "https://github.com/charmbracelet/glow/releases/download/v2.1.2/glow_2.1.2_Linux_x86_64.tar.gz";
23+
armv7l-linux = "https://github.com/charmbracelet/glow/releases/download/v2.1.2/glow_2.1.2_Linux_arm.tar.gz";
24+
aarch64-linux = "https://github.com/charmbracelet/glow/releases/download/v2.1.2/glow_2.1.2_Linux_arm64.tar.gz";
25+
x86_64-darwin = "https://github.com/charmbracelet/glow/releases/download/v2.1.2/glow_2.1.2_Darwin_x86_64.tar.gz";
26+
aarch64-darwin = "https://github.com/charmbracelet/glow/releases/download/v2.1.2/glow_2.1.2_Darwin_arm64.tar.gz";
2727
};
2828
sourceRootMap = {
29-
i686-linux = "glow_2.1.1_Linux_i386";
30-
x86_64-linux = "glow_2.1.1_Linux_x86_64";
31-
armv7l-linux = "glow_2.1.1_Linux_arm";
32-
aarch64-linux = "glow_2.1.1_Linux_arm64";
33-
x86_64-darwin = "glow_2.1.1_Darwin_x86_64";
34-
aarch64-darwin = "glow_2.1.1_Darwin_arm64";
29+
i686-linux = "glow_2.1.2_Linux_i386";
30+
x86_64-linux = "glow_2.1.2_Linux_x86_64";
31+
armv7l-linux = "glow_2.1.2_Linux_arm";
32+
aarch64-linux = "glow_2.1.2_Linux_arm64";
33+
x86_64-darwin = "glow_2.1.2_Darwin_x86_64";
34+
aarch64-darwin = "glow_2.1.2_Darwin_arm64";
3535
};
3636
in
3737
stdenvNoCC.mkDerivation {
3838
pname = "glow";
39-
version = "2.1.1";
39+
version = "2.1.2";
4040
src = fetchurl {
4141
url = urlMap.${system};
4242
sha256 = shaMap.${system};
@@ -53,11 +53,9 @@ stdenvNoCC.mkDerivation {
5353
installShellCompletion ./completions/*
5454
'';
5555

56-
system = system;
57-
5856
meta = {
5957
description = "Render markdown on the CLI, with pizzazz!";
60-
homepage = "https://charm.sh/";
58+
homepage = "https://charm.land/";
6159
license = lib.licenses.mit;
6260

6361
sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];

0 commit comments

Comments
 (0)