From c9618a4d9b03939ff2673e52aad97b57acd0f45a Mon Sep 17 00:00:00 2001 From: technofab Date: Wed, 1 Oct 2025 16:43:30 +0200 Subject: [PATCH 01/12] docs: update nixmkdocs, use svg for logo and favicon, add module docs --- docs/images/favicon.png | Bin 1449 -> 0 bytes docs/images/logo.png | Bin 3523 -> 0 bytes docs/images/logo.svg | 1 + docs/options.md | 3 ++ docs/style.css | 15 ++++++ flake.lock | 22 ++------- flake.nix | 102 +++++++++++++++++--------------------- lib/module.nix | 107 +++++++++++++++++++++++++++++++++------- 8 files changed, 154 insertions(+), 96 deletions(-) delete mode 100755 docs/images/favicon.png delete mode 100755 docs/images/logo.png create mode 100755 docs/images/logo.svg create mode 100644 docs/options.md create mode 100644 docs/style.css diff --git a/docs/images/favicon.png b/docs/images/favicon.png deleted file mode 100755 index 4203f2a5d2e6c0ae9ef11f74519df55ae5b305e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1449 zcmV;a1y=frP) zX>3$g6vuz(PU*s?wn`*mv9rFtu(F73s8SVq6f>goqd^2&07=!n9Ref*6(5 z4HT0mqUkWj1yYP{2NfbJ0#O9px|`?!(<- zn4a00JAg+44qLfX9Ab3RE|x0*K%T?f@o>Fs~4I+p^k z0{v}Wy;1$JPch*2)e3;986;wM03&QuNvO=@kK3=kX?UhFW+yN#VT&l>3Ff)C{c8dR zzDN;>$Dz6w7;e9}0$PDY_le&))S@PD-~e6Z_D7=*=TEc<*n-c zC?yH_^&oyAy&KYlfGJMJ?>`@}x%$ST-vMK7RSQZm4h~=`ml;<|6VTRe4CMRjT;~B# zDppKyKeoTM7O-qpe}pUI_S{Wg*YVp|Om4n&#dEne-qdbAAec1ZBOv5Z%0)xc$GBW( zuoy|TqE<`up|c~umlJIMwN3wNm2r#vYgYv z2TomJL*tbw6~I7SHS6udah1tD5vXoFVqecdU_?~U4pHIpI5-dk4)r<>msU3kN{It} zo2XQF_kA$Wy$5&`I26<9w68LXo=5;+EHPI1nt-CW+Aak+hq8E?cf{HA{8Jv&=#(!r zd{Y6x6C62OUUzr6YZe5;jfDs|*tzSJ34qIf4bzr^lsUi>2Y69dZQ&27 zd{*F#r@m|zm7oN|4Wkj+0i<;~%s+La6=j@V`MQvB<KQhdus?+^?>0a?I7vC^hx*3G@g-u$UhndglzC+}##$-vhFcZSM5yL#0P{p%ad zsMw=1AYN#Os%hVFJa^TnKryg5-?!zGPIuk~T;t&DfGW`5w_`CfX=rTBy3w)6o&;+C zA#rBI@!VCP0ILP&Cj?xlJkP8xtV7K!zyZtB(ok8B_PQGe!VTjP`4ZTAq~DJ-_qf)) z1x&Wh2gORCmRUPzyw$(0^2E&*^AqyCD5rh-4;p2jDybsGj7v@>DHJaRy(7QvwjBqm z8!Lc^1jg58EI5erk&^_F58P$vxyx=qOLE$m?~vrt?v(GrObF&>w|Co)QA!YgU6$wG z3vf$~_kIV7p+Lm`&)DF_Iql`W0gnMiPVl6qIOuinS4)@2*Y%UbE&Wc9e83SCsZQ{# zqBBZFT>}*s0-rm!I%>~`vlM0nGmM(e|7tAnm=Pi)1zCA!#J;(wuJ||}6BbZ>;Wx8i zuJ+&6;uzIOBWwo-0ID#vIM4llpNG&rY%1->nh z0NJ2bj-J0(kdzK0dPb#l^jlc(8vAUjod=NrB~ktc|2-VUh%R%J00000NkvXXu0mjf D^0>9~ diff --git a/docs/images/logo.png b/docs/images/logo.png deleted file mode 100755 index b8ff5f84d1da75f58cdcfd3dcce417eef1dfdc71..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3523 zcmV;!4LtIRP)yV0OE`l4aR_48v>}MbQqxj*_XdX@+4w6GgEn z7K^>j^E{vKMkWmiyH2NjT@=ObrLv@AZ^UA;19D(=i!V4Fj(rTn{24$?sobd928LlC z;yCVBAQ1Q{Ef9yp@ic(v0F;-?jJlNr*vWAm0)aqZ3J{0Gv2OuJ$qH-RIgXo=JcW_^ z43=g81E8{0KH7Bpu~_U*p67WM02qdOrUXM%t7I7FbpT)%yyF7Rw;9aUSo?$LQ?5s6 z!x%mBD5A4rWzREOuw(Bb7>t(qHM6xw_TIo14^A9^<3QoF-JM7wZ-KyR(+0nhK+HH<5Qp6(H#M zElnT*FnQhuAv8sFZ$tYYRqq(-Jq#fdB z5-T!Wvr~D~==Z_hcbw?nnx-~5+P`{7Tjy@#_nbL;ka~nj9f;JIkj5IdYr6|3gSooK zj50UTJOeKH#)hevm5$@MX9@vD2u;Ci|8Djgl0&d4+zesm`mIDAd~{a8oj>{ov0^&) z+S3psp|6LBNM7RSPZQm1Yj(n5s#g4t@c|dH3~t@2q$58}wIkOA2mp9Tdx&JPPH&}r4kYI$t9ETSip^}Rod8pgk9%HG{fv>`!^+>Qaw;Kj zK%^$67_DK`9z`-ZSD9-tSEIgd7i_CLwF9Dd?5PkY4OS|Z!9l+l?!IHnBW%41qbD9E zjPiX_B82b*nX2jO)R3w8}uHT~R zH>(=Uvf4X{#-)nE%vDYJ^1puv%d)6xYRlf#S!)sW`w+OQOkwG&^sqf_$Fd*Rz|^)3 z!sQ5J*XQVah{0UFB)lWBZMUuNg!|Mn@;MWQ$qc$GJ(llp#BI$MlvNpUTeAhrf87ZE zigNluY^ytqzVAql_`3k6oVbIxSZmO7Pq!i%WmSgcf;H+?L17#Yhp4o^($u@A!ZV{b^}Xm?`s1CJ92X!$nZ*bsbULquNU*yMy~ zus3C%HUAIr#TGjK=eklBAKgZ9wJ{dII$vV1%rB%wdS55E0Vc|$P7#;gNp%%tcU20 zW?1VQ7nDdybvli~Xelb0OJezeQBk)MIs@6fdT_#>GNF|Mq`m7AVnviM(<0r528`Nu zU5chAf|G8Ho&0_JCQFGt&6jDFZlg5}Kt4%?RVz>PWrdcx#R4P#w~LlvuxjLKzDx_5 zTTC#3g?ayk)S)<#HQVklu(Huk<`xT#xDcq{m{VgeuaBOm-wevw(thKV&bdrW8HNy= zf}j83tM8N2fTD8(A~ym=OTrQhw)dr9;nGMyqI1b}#(^syj1RsGbJrtlQ4Hjv_SUj{rJ%ClZ zf@<5(51?*M`+RV?uo-0Z`W$YJ-hk<@N-+BDj9HTo#qw81k&2MJH7@_isorS(HTsL&V>=a=Ftp>pFfR>&rhI`rU=O9 z2Oduv4W74sXrg%rU37o|K-W`8Wal_& zK`~Y~;PZE%$}5a?6^n)q_a0WX&P8#j9=JM=Mw!eMTFuw=rGLkptfdAc==b82o>vql z04kQfQZB5VnHPCZJ|wZ!hA%Z3^WLF+^D|X}q1<+~G27HQYgHrXi)L?i9To@lzpUIzd ziKubSe0xf$+fBz9ya^rnXN> z2P3-}2|-tO8}VjlfvX-|pSV=8@+s)n8d7FS?b@!SSwW?JidqIkw@nQMCWEv*V3N75-l8ULF;5T%{)ZzJVT|P zvKWTd-hn%u&#F5Brtg@d6W$8tB?a@4bmtk8dWsy3hW0(G4}bxHP{1cUa-C90dINN2 z23&Q2{Ph50wRdF9N|b{V`D6yMa1^tbZ(^p$i%`OzQxc5$-!E^0pZ`E{(-rdjP}9^V zJHNBos_kpw^9&I$NGfU|tG4XRx^~-QYe||zk42)mbv}ffqc;#u*l%hv49V24Gnw!V zp@nccpT%06QxskleTc2uNt~`96~Y;s4HN1&>`J@6x!QFmN>6x`I|p&e05O=W(`LJ; z6wHJ>Z4I}rc4F8!)(Y?w$%sXeVhhy;nf z#A2ibHdIgXejkU1+<024K2WCYsrFEEYQe06GAeo}QlO zIPMmJou#tT#Gbft;lev{AOH{u1U}+8jsdW}R6Yf@1LNc4&&6eX;xB \ No newline at end of file diff --git a/docs/options.md b/docs/options.md new file mode 100644 index 0000000..4ca74a4 --- /dev/null +++ b/docs/options.md @@ -0,0 +1,3 @@ +# Options + +{% include 'options.md' %} diff --git a/docs/style.css b/docs/style.css new file mode 100644 index 0000000..b2ae4ff --- /dev/null +++ b/docs/style.css @@ -0,0 +1,15 @@ +.md-header__button.md-logo { + margin: 0; + padding-top: .2rem; + padding-bottom: .2rem; +} + +[dir="ltr"] .md-header__title { + margin-left: 0; +} + +.md-header__button.md-logo img, +.md-header__button.md-logo svg { + height: 2rem; +} + diff --git a/flake.lock b/flake.lock index 09366e0..110c517 100644 --- a/flake.lock +++ b/flake.lock @@ -169,21 +169,6 @@ "type": "github" } }, - "mkdocs-material-umami": { - "locked": { - "lastModified": 1745840856, - "narHash": "sha256-1Ad1JTMQMP6YsoIKAA+SBCE15qWrYkGue9/lXOLnu9I=", - "owner": "technofab", - "repo": "mkdocs-material-umami", - "rev": "3ac9b194450f6b779c37b8d16fec640198e5cd0a", - "type": "gitlab" - }, - "original": { - "owner": "technofab", - "repo": "mkdocs-material-umami", - "type": "gitlab" - } - }, "nix": { "inputs": { "flake-compat": [ @@ -255,11 +240,11 @@ "nix-mkdocs": { "locked": { "dir": "lib", - "lastModified": 1745841841, - "narHash": "sha256-297zPQbUlc7ZAYDoaD6mCmQxCC3Tr4YOKekRF1ArZ7g=", + "lastModified": 1757055638, + "narHash": "sha256-KHYSkEreFe4meXzSdEbknC/HwaQSNClQkc8vzHlAsMM=", "owner": "technofab", "repo": "nixmkdocs", - "rev": "c7e3c3b13ded25818e9789938387bba6f2cde690", + "rev": "7840a5febdbeaf2da90babf6c94b3d0929d2bf74", "type": "gitlab" }, "original": { @@ -368,7 +353,6 @@ "inputs": { "devenv": "devenv", "flake-parts": "flake-parts_2", - "mkdocs-material-umami": "mkdocs-material-umami", "nix-devtools": "nix-devtools", "nix-gitlab-ci": "nix-gitlab-ci", "nix-mkdocs": "nix-mkdocs", diff --git a/flake.nix b/flake.nix index 9be0e25..72e77cc 100644 --- a/flake.nix +++ b/flake.nix @@ -17,6 +17,7 @@ perSystem = { lib, pkgs, + self', config, ... }: { @@ -65,81 +66,48 @@ }; }; - doc = { + docs."default".config = { path = ./docs; - deps = pp: [ - pp.mkdocs-material - (pp.callPackage inputs.mkdocs-material-umami {}) - ]; + material = { + enable = true; + colors = { + primary = "green"; + accent = "light green"; + }; + umami = { + enable = true; + src = "https://analytics.tf/umami"; + siteId = "716d1869-9342-4b62-a770-e15d2d5c807d"; + domains = ["nixtest.projects.tf"]; + }; + }; + macros = { + enable = true; + includeDir = toString self'.packages.optionsDocs; + }; config = { site_name = "Nixtest"; + site_url = "https://nixtest.projects.tf"; repo_name = "TECHNOFAB/nixtest"; repo_url = "https://gitlab.com/TECHNOFAB/nixtest"; - edit_uri = "edit/main/docs/"; + extra_css = ["style.css"]; theme = { - name = "material"; - features = ["content.code.copy" "content.action.edit"]; icon.repo = "simple/gitlab"; - logo = "images/logo.png"; - favicon = "images/favicon.png"; - palette = [ - { - scheme = "default"; - media = "(prefers-color-scheme: light)"; - primary = "green"; - accent = "light green"; - toggle = { - icon = "material/brightness-7"; - name = "Switch to dark mode"; - }; - } - { - scheme = "slate"; - media = "(prefers-color-scheme: dark)"; - primary = "green"; - accent = "light green"; - toggle = { - icon = "material/brightness-4"; - name = "Switch to light mode"; - }; - } - ]; + logo = "images/logo.svg"; + favicon = "images/logo.svg"; }; - plugins = ["search" "material-umami"]; nav = [ {"Introduction" = "index.md";} {"Usage" = "usage.md";} {"Reference" = "reference.md";} {"CLI" = "cli.md";} {"Example Configs" = "examples.md";} + {"Options" = "options.md";} ]; markdown_extensions = [ "pymdownx.superfences" "admonition" ]; - extra.analytics = { - provider = "umami"; - site_id = "716d1869-9342-4b62-a770-e15d2d5c807d"; - src = "https://analytics.tf/umami"; - domains = "nixtest.projects.tf"; - feedback = { - title = "Was this page helpful?"; - ratings = [ - { - icon = "material/thumb-up-outline"; - name = "This page is helpful"; - data = "good"; - note = "Thanks for your feedback!"; - } - { - icon = "material/thumb-down-outline"; - name = "This page could be improved"; - data = "bad"; - note = "Thanks for your feedback! Please leave feedback by creating an issue :)"; - } - ]; - }; - }; }; }; @@ -212,7 +180,8 @@ packages = let ntlib = import ./lib {inherit pkgs lib;}; - in { + doclib = inputs.nix-mkdocs.lib {inherit lib pkgs;}; + in rec { default = pkgs.callPackage ./package.nix {}; tests = ntlib.mkNixtest { modules = ntlib.autodiscover {dir = ./tests;}; @@ -220,6 +189,24 @@ inherit pkgs ntlib; }; }; + optionsDoc = doclib.mkOptionDocs { + module = { + _module.args.pkgs = pkgs; + imports = [ + ntlib.module + ]; + }; + roots = [ + { + url = "https://gitlab.com/TECHNOFAB/nixtest/-/blob/main/lib"; + path = toString ./lib; + } + ]; + }; + optionsDocs = pkgs.runCommand "options-docs" {} '' + mkdir -p $out + ln -s ${optionsDoc} $out/options.md + ''; }; }; }; @@ -235,7 +222,6 @@ nix-gitlab-ci.url = "gitlab:technofab/nix-gitlab-ci/2.0.1?dir=lib"; nix-devtools.url = "gitlab:technofab/nix-devtools?dir=lib"; nix-mkdocs.url = "gitlab:technofab/nixmkdocs?dir=lib"; - mkdocs-material-umami.url = "gitlab:technofab/mkdocs-material-umami"; }; nixConfig = { diff --git a/lib/module.nix b/lib/module.nix index 478584c..db05055 100644 --- a/lib/module.nix +++ b/lib/module.nix @@ -13,6 +13,7 @@ removePrefix assertMsg generators + literalExpression ; nixtest-lib = import ./default.nix {inherit pkgs lib;}; @@ -27,6 +28,18 @@ _type = "unset"; }; isUnset = isType "unset"; + unsetOr = typ: + (types.either unsetType typ) + // { + inherit (typ) description getSubOptions; + }; + mkUnsetOption = opts: + mkOption (opts + // { + type = unsetOr opts.type; + default = opts.default or unset; + defaultText = literalExpression "unset"; + }); filterUnset = value: if builtins.isAttrs value && !builtins.hasAttr "_type" value @@ -45,8 +58,11 @@ ... }: { options = { - pos = mkOption { - type = types.either types.attrs unsetType; + pos = mkUnsetOption { + type = types.attrs; + description = '' + Position of test, use `__curPos` for automatic insertion of current position. + ''; default = pos; apply = val: if isUnset val @@ -57,6 +73,9 @@ }; type = mkOption { type = types.enum ["unit" "snapshot" "script"]; + description = '' + Type of test, has to be one of "unit", "snapshot" or "script". + ''; default = "unit"; apply = value: assert assertMsg (value != "script" || !isUnset config.script) @@ -76,43 +95,66 @@ }; name = mkOption { type = types.str; + description = '' + Name of this test. + ''; }; - description = mkOption { - type = types.either types.str unsetType; - default = unset; + description = mkUnsetOption { + type = types.str; + description = '' + Short description of the test. + ''; }; format = mkOption { type = types.enum ["json" "pretty"]; + description = '' + Which format to use for serializing arbitrary values. + Required since this config is serialized to JSON for passing it to Nixtest, so no Nix-values can be used directly. + + - `json`: serializes the data to json using `builtins.toJSON` + - `pretty`: serializes the data to a "pretty" format using `lib.generators.toPretty` + ''; default = "json"; }; - expected = mkOption { + expected = mkUnsetOption { type = types.anything; - default = unset; + description = '' + Expected value of the test. Remember, the values are serialized (see [here](#suitesnametestsformat)). + ''; apply = val: if isUnset val || config.format == "json" then val else generators.toPretty {} val; }; - actual = mkOption { + actual = mkUnsetOption { type = types.anything; - default = unset; + description = '' + Actual value of the test. Remember, the values are serialized (see [here](#suitesnametestsformat)). + ''; apply = val: if isUnset val || config.format == "json" then val else generators.toPretty {} val; }; - actualDrv = mkOption { - type = types.either types.package unsetType; - default = unset; + actualDrv = mkUnsetOption { + type = types.package; + description = '' + Actual value of the test, but as a derivation. + Nixtest will build this derivation when running the test, then compare the contents of the + resulting file to the [`expected`](#suitesnametestsexpected) value. + ''; apply = val: # keep unset value if isUnset val then val else builtins.unsafeDiscardStringContext (val.drvPath or ""); }; - script = mkOption { - type = types.either types.str unsetType; - default = unset; + script = mkUnsetOption { + type = types.str; + description = '' + Script to run for the test. + Nixtest will run this, failing the test if it exits with a non-zero exit code. + ''; apply = val: if isUnset val then val @@ -132,11 +174,19 @@ options = { name = mkOption { type = types.str; + description = '' + Name of the suite, uses attrset name by default. + ''; default = name; + defaultText = literalExpression name; }; - pos = mkOption { - type = types.either types.attrs unsetType; - default = unset; + pos = mkUnsetOption { + type = types.attrs; + description = '' + Position for tests, use `__curPos` for automatic insertion of current position. + This will set `pos` for every test of this suite, useful if the suite's tests are all in a single file. + ''; + example = literalExpression "__curPos"; }; tests = mkOption { type = types.listOf (types.submoduleWith { @@ -146,6 +196,9 @@ inherit testsBase; }; }); + description = '' + Define tests of this suite here. + ''; default = []; }; }; @@ -154,12 +207,18 @@ nixtestSubmodule = {config, ...}: { options = { base = mkOption { - description = "Base directory of the tests, will be removed from the test file path"; type = types.str; + description = '' + Base directory of the tests, will be removed from the test file path. + This makes it possible to show the relative path from the git repo, instead of ugly Nix store paths. + ''; default = ""; }; skip = mkOption { type = types.str; + description = '' + Tests to skip, is passed to Nixtest's `--skip` param. + ''; default = ""; }; suites = mkOption { @@ -169,12 +228,22 @@ testsBase = config.base; }; }); + description = '' + Define your test suites here, every test belongs to a suite. + ''; default = {}; apply = suites: map ( n: filterUnset (builtins.removeAttrs suites.${n} ["pos"]) ) (builtins.attrNames suites); + example = { + "Suite A".tests = [ + { + name = "Some Test"; + } + ]; + }; }; finalConfigJson = mkOption { From 56d22f4aa1c3f281a0cd26acd7aa2ed426ef6fe5 Mon Sep 17 00:00:00 2001 From: technofab Date: Wed, 1 Oct 2025 17:08:49 +0200 Subject: [PATCH 02/12] test: set SSL_CERT_FILE and NIX_SSL_CERT_FILE so test works in pure mode --- tests/lib_test.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/lib_test.nix b/tests/lib_test.nix index 969e9a2..85a3c7a 100644 --- a/tests/lib_test.nix +++ b/tests/lib_test.nix @@ -72,6 +72,8 @@ '' ${ntlib.helpers.path [pkgs.gnugrep pkgs.mktemp pkgs.coreutils]} ${ntlib.helpers.scriptHelpers} + export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt + export NIX_SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt cp -r ${./../snapshots} snapshots # start without nix & env binaries to expect errors From 5a7053afcbb211b9cf8fe87f7892bb9f6b76b678 Mon Sep 17 00:00:00 2001 From: technofab Date: Wed, 1 Oct 2025 19:42:30 +0200 Subject: [PATCH 03/12] docs: set _file so "declared in" works correctly --- lib/module.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/module.nix b/lib/module.nix index db05055..1600c50 100644 --- a/lib/module.nix +++ b/lib/module.nix @@ -205,6 +205,7 @@ }; nixtestSubmodule = {config, ...}: { + _file = ./module.nix; options = { base = mkOption { type = types.str; From 041449396326a11ec8f88354f7dbd3204016de1d Mon Sep 17 00:00:00 2001 From: technofab Date: Sun, 14 Dec 2025 14:56:40 +0100 Subject: [PATCH 04/12] refactor: replace flake-parts, devenv etc. with rensa --- .envrc | 3 +- .gitignore | 3 - .gitlab-ci.yml | 7 +- .gitlab/renovate.json5 | 23 ++ flake.lock | 383 ++-------------------------- flake.nix | 265 +++---------------- nix/packages/packages.nix | 8 + nix/repo/ci.nix | 85 ++++++ nix/repo/devShells.nix | 33 +++ nix/repo/docs.nix | 64 +++++ nix/repo/flake.lock | 100 ++++++++ nix/repo/flake.nix | 22 ++ nix/repo/soonix.nix | 34 +++ nix/repo/tests.nix | 10 + package.nix | 3 +- snapshots/pretty-snapshot.snap.json | 2 +- 16 files changed, 443 insertions(+), 602 deletions(-) create mode 100644 .gitlab/renovate.json5 create mode 100644 nix/packages/packages.nix create mode 100644 nix/repo/ci.nix create mode 100644 nix/repo/devShells.nix create mode 100644 nix/repo/docs.nix create mode 100644 nix/repo/flake.lock create mode 100644 nix/repo/flake.nix create mode 100644 nix/repo/soonix.nix create mode 100644 nix/repo/tests.nix diff --git a/.envrc b/.envrc index f990172..565a52a 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,2 @@ -use flake . --impure --accept-flake-config +source $(fetchurl https://gitlab.com/rensa-nix/direnv/-/raw/v0.3.0/direnvrc "sha256-u7+KEz684NnIZ+Vh5x5qLrt8rKdnUNexewBoeTcEVHQ=") +use ren //repo/devShells/default diff --git a/.gitignore b/.gitignore index e1f66c8..f5db43c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -.direnv/ -.devenv/ result -.pre-commit-config.yaml *.xml cover.* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6253297..7d70f67 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,5 @@ +# Generated by soonix, DO NOT EDIT include: - - component: gitlab.com/TECHNOFAB/nix-gitlab-ci/nix-gitlab-ci@2.0.0 - inputs: - version: 2.0.0 +- component: gitlab.com/TECHNOFAB/nix-gitlab-ci/nix-gitlab-ci@3.1.2 + inputs: + version: 3.1.2 diff --git a/.gitlab/renovate.json5 b/.gitlab/renovate.json5 new file mode 100644 index 0000000..67d4092 --- /dev/null +++ b/.gitlab/renovate.json5 @@ -0,0 +1,23 @@ +{ + "extends": [ + "config:recommended" + ], + "gitlabci": { + "enabled": false + }, + "lockFileMaintenance": { + "enabled": true, + "extends": [ + "schedule:monthly" + ] + }, + "nix": { + "enabled": true + }, + "postUpgradeTasks": { + "commands": [ + "nix-portable nix run .#update-package", + "nix-portable nix run .#soonix:update" + ] + } +} diff --git a/flake.lock b/flake.lock index 110c517..6d5a6ab 100644 --- a/flake.lock +++ b/flake.lock @@ -1,266 +1,12 @@ { "nodes": { - "cachix": { - "inputs": { - "devenv": [ - "devenv" - ], - "flake-compat": [ - "devenv" - ], - "git-hooks": [ - "devenv" - ], - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1742042642, - "narHash": "sha256-D0gP8srrX0qj+wNYNPdtVJsQuFzIng3q43thnHXQ/es=", - "owner": "cachix", - "repo": "cachix", - "rev": "a624d3eaf4b1d225f918de8543ed739f2f574203", - "type": "github" - }, - "original": { - "owner": "cachix", - "ref": "latest", - "repo": "cachix", - "type": "github" - } - }, - "devenv": { - "inputs": { - "cachix": "cachix", - "flake-compat": "flake-compat", - "git-hooks": "git-hooks", - "nix": "nix", - "nixpkgs": "nixpkgs_3" - }, - "locked": { - "lastModified": 1746189866, - "narHash": "sha256-3sTvuSVBFcXbqg26Qcw/ENJ1s36jtzEcZ0mHqLqvWRA=", - "owner": "cachix", - "repo": "devenv", - "rev": "5fc592d45dd056035e0fd5000893a21609c35526", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "devenv", - "type": "github" - } - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1733328505, - "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": [ - "devenv", - "nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1712014858, - "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "flake-parts_2": { - "inputs": { - "nixpkgs-lib": "nixpkgs-lib" - }, - "locked": { - "lastModified": 1743550720, - "narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "c621e8422220273271f52058f618c94e405bb0f5", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "git-hooks": { - "inputs": { - "flake-compat": [ - "devenv" - ], - "gitignore": "gitignore", - "nixpkgs": [ - "devenv", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1742649964, - "narHash": "sha256-DwOTp7nvfi8mRfuL1escHDXabVXFGT1VlPD1JHrtrco=", - "owner": "cachix", - "repo": "git-hooks.nix", - "rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "git-hooks.nix", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "devenv", - "git-hooks", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1709087332, - "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, - "libgit2": { - "flake": false, - "locked": { - "lastModified": 1697646580, - "narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=", - "owner": "libgit2", - "repo": "libgit2", - "rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5", - "type": "github" - }, - "original": { - "owner": "libgit2", - "repo": "libgit2", - "type": "github" - } - }, - "nix": { - "inputs": { - "flake-compat": [ - "devenv" - ], - "flake-parts": "flake-parts", - "libgit2": "libgit2", - "nixpkgs": "nixpkgs_2", - "nixpkgs-23-11": [ - "devenv" - ], - "nixpkgs-regression": [ - "devenv" - ], - "pre-commit-hooks": [ - "devenv" - ] - }, - "locked": { - "lastModified": 1745930071, - "narHash": "sha256-bYyjarS3qSNqxfgc89IoVz8cAFDkF9yPE63EJr+h50s=", - "owner": "domenkozar", - "repo": "nix", - "rev": "b455edf3505f1bf0172b39a735caef94687d0d9c", - "type": "github" - }, - "original": { - "owner": "domenkozar", - "ref": "devenv-2.24", - "repo": "nix", - "type": "github" - } - }, - "nix-devtools": { - "locked": { - "dir": "lib", - "lastModified": 1739971859, - "narHash": "sha256-DaY11jX7Lraw7mRUIsgPsO+aSkkewQe2D+WMZORTNPE=", - "owner": "technofab", - "repo": "nix-devtools", - "rev": "b4f059657de5ac2569afd69a8f042614d309e6bb", - "type": "gitlab" - }, - "original": { - "dir": "lib", - "owner": "technofab", - "repo": "nix-devtools", - "type": "gitlab" - } - }, - "nix-gitlab-ci": { - "locked": { - "dir": "lib", - "lastModified": 1746973171, - "narHash": "sha256-q/LhPZlhJB2gXZ5BfgU1Wep/1x1y9Sct3/JU8A2fzjg=", - "owner": "technofab", - "repo": "nix-gitlab-ci", - "rev": "dca2d724c155799e537a898cb9f948f8afae4921", - "type": "gitlab" - }, - "original": { - "dir": "lib", - "owner": "technofab", - "ref": "2.0.1", - "repo": "nix-gitlab-ci", - "type": "gitlab" - } - }, - "nix-mkdocs": { - "locked": { - "dir": "lib", - "lastModified": 1757055638, - "narHash": "sha256-KHYSkEreFe4meXzSdEbknC/HwaQSNClQkc8vzHlAsMM=", - "owner": "technofab", - "repo": "nixmkdocs", - "rev": "7840a5febdbeaf2da90babf6c94b3d0929d2bf74", - "type": "gitlab" - }, - "original": { - "dir": "lib", - "owner": "technofab", - "repo": "nixmkdocs", - "type": "gitlab" - } - }, "nixpkgs": { "locked": { - "lastModified": 1733212471, - "narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=", + "lastModified": 1765472234, + "narHash": "sha256-9VvC20PJPsleGMewwcWYKGzDIyjckEz8uWmT0vCDYK0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "55d15ad12a74eb7d4646254e13638ad0c4128776", + "rev": "2fbfb1d73d239d2402a8fe03963e37aab15abe8b", "type": "github" }, "original": { @@ -272,11 +18,11 @@ }, "nixpkgs-lib": { "locked": { - "lastModified": 1743296961, - "narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=", + "lastModified": 1754184128, + "narHash": "sha256-AjhoyBL4eSyXf01Bmc6DiuaMrJRNdWopmdnMY0Pa/M0=", "owner": "nix-community", "repo": "nixpkgs.lib", - "rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa", + "rev": "02e72200e6d56494f4a7c0da8118760736e41b60", "type": "github" }, "original": { @@ -285,113 +31,30 @@ "type": "github" } }, - "nixpkgs_2": { + "ren": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, "locked": { - "lastModified": 1717432640, - "narHash": "sha256-+f9c4/ZX5MWDOuB1rKoWj+lBNm0z0rs4CK47HBLxy1o=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "88269ab3044128b7c2f4c7d68448b2fb50456870", - "type": "github" + "dir": "lib", + "lastModified": 1758738378, + "narHash": "sha256-NjzqdvQCDDdObEBH8x/vdhbdhrIB+N9E570uCdksGHY=", + "owner": "rensa-nix", + "repo": "core", + "rev": "abe19f9f13aff41de2b63304545c87d193d19ef4", + "type": "gitlab" }, "original": { - "owner": "NixOS", - "ref": "release-24.05", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_3": { - "locked": { - "lastModified": 1733477122, - "narHash": "sha256-qamMCz5mNpQmgBwc8SB5tVMlD5sbwVIToVZtSxMph9s=", - "owner": "cachix", - "repo": "devenv-nixpkgs", - "rev": "7bd9e84d0452f6d2e63b6e6da29fe73fac951857", - "type": "github" - }, - "original": { - "owner": "cachix", - "ref": "rolling", - "repo": "devenv-nixpkgs", - "type": "github" - } - }, - "nixpkgs_4": { - "locked": { - "lastModified": 1746152631, - "narHash": "sha256-zBuvmL6+CUsk2J8GINpyy8Hs1Zp4PP6iBWSmZ4SCQ/s=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "032bc6539bd5f14e9d0c51bd79cfe9a055b094c3", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_5": { - "locked": { - "lastModified": 1745377448, - "narHash": "sha256-jhZDfXVKdD7TSEGgzFJQvEEZ2K65UMiqW5YJ2aIqxMA=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "507b63021ada5fee621b6ca371c4fca9ca46f52c", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" + "dir": "lib", + "owner": "rensa-nix", + "repo": "core", + "type": "gitlab" } }, "root": { "inputs": { - "devenv": "devenv", - "flake-parts": "flake-parts_2", - "nix-devtools": "nix-devtools", - "nix-gitlab-ci": "nix-gitlab-ci", - "nix-mkdocs": "nix-mkdocs", - "nixpkgs": "nixpkgs_4", - "systems": "systems", - "treefmt-nix": "treefmt-nix" - } - }, - "systems": { - "locked": { - "lastModified": 1689347949, - "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", - "owner": "nix-systems", - "repo": "default-linux", - "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default-linux", - "type": "github" - } - }, - "treefmt-nix": { - "inputs": { - "nixpkgs": "nixpkgs_5" - }, - "locked": { - "lastModified": 1746216483, - "narHash": "sha256-4h3s1L/kKqt3gMDcVfN8/4v2jqHrgLIe4qok4ApH5x4=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "29ec5026372e0dec56f890e50dbe4f45930320fd", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" + "nixpkgs": "nixpkgs", + "ren": "ren" } } }, diff --git a/flake.nix b/flake.nix index 72e77cc..fec8334 100644 --- a/flake.nix +++ b/flake.nix @@ -1,240 +1,39 @@ { + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + ren.url = "gitlab:rensa-nix/core?dir=lib"; + }; + outputs = { - flake-parts, - systems, + ren, + self, ... } @ inputs: - flake-parts.lib.mkFlake {inherit inputs;} { - imports = [ - inputs.devenv.flakeModule - inputs.treefmt-nix.flakeModule - inputs.nix-gitlab-ci.flakeModule - inputs.nix-devtools.flakeModule - inputs.nix-mkdocs.flakeModule + ren.buildWith + { + inherit inputs; + cellsFrom = ./nix; + transformInputs = system: i: + i + // { + pkgs = import i.nixpkgs {inherit system;}; + }; + cellBlocks = with ren.blocks; [ + (simple "devShells") + (simple "ci") + (simple "tests") + (simple "packages") + (simple "docs") + (simple "soonix") + ]; + } + { + packages = ren.select self [ + ["repo" "ci" "packages"] + ["repo" "tests"] + ["packages" "packages"] + ["repo" "docs"] + ["repo" "soonix" "packages"] ]; - systems = import systems; - flake = {}; - perSystem = { - lib, - pkgs, - self', - config, - ... - }: { - treefmt = { - projectRootFile = "flake.nix"; - programs = { - alejandra.enable = true; - mdformat.enable = true; - gofmt.enable = true; - }; - settings.formatter.mdformat.command = let - pkg = pkgs.python3.withPackages (p: [ - p.mdformat - p.mdformat-mkdocs - ]); - in "${pkg}/bin/mdformat"; - }; - devenv.shells.default = { - containers = pkgs.lib.mkForce {}; - packages = with pkgs; [gore go-junit-report]; - - languages.go = { - enable = true; - enableHardeningWorkaround = true; - }; - - pre-commit.hooks = { - treefmt = { - enable = true; - packageOverrides.treefmt = config.treefmt.build.wrapper; - }; - convco.enable = true; - }; - - task = { - enable = true; - alias = ","; - tasks = { - "test" = { - cmds = [ - "go test -v -coverprofile cover.out ./..." - "go tool cover -html cover.out -o cover.html" - ]; - }; - }; - }; - }; - - docs."default".config = { - path = ./docs; - material = { - enable = true; - colors = { - primary = "green"; - accent = "light green"; - }; - umami = { - enable = true; - src = "https://analytics.tf/umami"; - siteId = "716d1869-9342-4b62-a770-e15d2d5c807d"; - domains = ["nixtest.projects.tf"]; - }; - }; - macros = { - enable = true; - includeDir = toString self'.packages.optionsDocs; - }; - config = { - site_name = "Nixtest"; - site_url = "https://nixtest.projects.tf"; - repo_name = "TECHNOFAB/nixtest"; - repo_url = "https://gitlab.com/TECHNOFAB/nixtest"; - extra_css = ["style.css"]; - theme = { - icon.repo = "simple/gitlab"; - logo = "images/logo.svg"; - favicon = "images/logo.svg"; - }; - nav = [ - {"Introduction" = "index.md";} - {"Usage" = "usage.md";} - {"Reference" = "reference.md";} - {"CLI" = "cli.md";} - {"Example Configs" = "examples.md";} - {"Options" = "options.md";} - ]; - markdown_extensions = [ - "pymdownx.superfences" - "admonition" - ]; - }; - }; - - ci = { - stages = ["test" "build" "deploy"]; - jobs = { - "test:lib" = { - stage = "test"; - script = [ - "nix run .#tests -- --junit=junit.xml" - ]; - allow_failure = true; - artifacts = { - when = "always"; - reports.junit = "junit.xml"; - }; - }; - "test:go" = { - stage = "test"; - nix.deps = with pkgs; [go go-junit-report gocover-cobertura]; - variables = { - GOPATH = "$CI_PROJECT_DIR/.go"; - GOCACHE = "$CI_PROJECT_DIR/.go/pkg/mod"; - }; - script = [ - "go test -coverprofile=coverage.out -v 2>&1 ./... | go-junit-report -set-exit-code > report.xml" - "go tool cover -func coverage.out" - "gocover-cobertura < coverage.out > coverage.xml" - ]; - allow_failure = true; - coverage = "/\(statements\)(?:\s+)?(\d+(?:\.\d+)?%)/"; - cache.paths = [".go/pkg/mod/"]; - artifacts = { - when = "always"; - reports = { - junit = "report.xml"; - coverage_report = { - coverage_format = "cobertura"; - path = "coverage.xml"; - }; - }; - }; - }; - "docs" = { - stage = "build"; - script = [ - # sh - '' - nix build .#docs:default - mkdir -p public - cp -r result/. public/ - '' - ]; - artifacts.paths = ["public"]; - }; - "pages" = { - nix.enable = false; - image = "alpine:latest"; - stage = "deploy"; - script = ["true"]; - artifacts.paths = ["public"]; - rules = [ - { - "if" = "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"; - } - ]; - }; - }; - }; - - packages = let - ntlib = import ./lib {inherit pkgs lib;}; - doclib = inputs.nix-mkdocs.lib {inherit lib pkgs;}; - in rec { - default = pkgs.callPackage ./package.nix {}; - tests = ntlib.mkNixtest { - modules = ntlib.autodiscover {dir = ./tests;}; - args = { - inherit pkgs ntlib; - }; - }; - optionsDoc = doclib.mkOptionDocs { - module = { - _module.args.pkgs = pkgs; - imports = [ - ntlib.module - ]; - }; - roots = [ - { - url = "https://gitlab.com/TECHNOFAB/nixtest/-/blob/main/lib"; - path = toString ./lib; - } - ]; - }; - optionsDocs = pkgs.runCommand "options-docs" {} '' - mkdir -p $out - ln -s ${optionsDoc} $out/options.md - ''; - }; - }; }; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - - # flake & devenv related - flake-parts.url = "github:hercules-ci/flake-parts"; - systems.url = "github:nix-systems/default-linux"; - devenv.url = "github:cachix/devenv"; - treefmt-nix.url = "github:numtide/treefmt-nix"; - nix-gitlab-ci.url = "gitlab:technofab/nix-gitlab-ci/2.0.1?dir=lib"; - nix-devtools.url = "gitlab:technofab/nix-devtools?dir=lib"; - nix-mkdocs.url = "gitlab:technofab/nixmkdocs?dir=lib"; - }; - - nixConfig = { - extra-substituters = [ - "https://cache.nixos.org/" - "https://nix-community.cachix.org" - "https://devenv.cachix.org" - ]; - - extra-trusted-public-keys = [ - "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=" - ]; - }; } diff --git a/nix/packages/packages.nix b/nix/packages/packages.nix new file mode 100644 index 0000000..9174657 --- /dev/null +++ b/nix/packages/packages.nix @@ -0,0 +1,8 @@ +{inputs, ...}: let + inherit (inputs) self pkgs; +in { + nixtest = pkgs.callPackage "${self}/package.nix" {}; + update-package = pkgs.writeShellScriptBin "update-package" '' + ${pkgs.nix-update}/bin/nix-update nixtest --flake --version skip + ''; +} diff --git a/nix/repo/ci.nix b/nix/repo/ci.nix new file mode 100644 index 0000000..010c4ad --- /dev/null +++ b/nix/repo/ci.nix @@ -0,0 +1,85 @@ +{inputs, ...}: let + inherit (inputs) pkgs cilib; +in + cilib.mkCI { + pipelines."default" = { + stages = ["test" "build" "deploy"]; + jobs = { + "test:lib" = { + stage = "test"; + script = [ + "nix run .#tests -- --junit=junit.xml" + ]; + allow_failure = true; + artifacts = { + when = "always"; + reports.junit = "junit.xml"; + }; + }; + "test:go" = { + stage = "test"; + nix.deps = with pkgs; [gcc go go-junit-report gocover-cobertura]; + variables = { + GOPATH = "$CI_PROJECT_DIR/.go"; + GOCACHE = "$CI_PROJECT_DIR/.go/pkg/mod"; + }; + script = [ + # sh + '' + set +e + go test -coverprofile=coverage.out -v 2>&1 ./... | go-junit-report -set-exit-code > report.xml + TEST_EXIT_CODE=$? + go tool cover -func coverage.out + gocover-cobertura < coverage.out > coverage.xml + + exit $TEST_EXIT_CODE + '' + ]; + allow_failure = true; + coverage = "/\(statements\)(?:\s+)?(\d+(?:\.\d+)?%)/"; + cache.paths = [".go/pkg/mod/"]; + artifacts = { + when = "always"; + reports = { + junit = "report.xml"; + coverage_report = { + coverage_format = "cobertura"; + path = "coverage.xml"; + }; + }; + }; + }; + "build" = { + stage = "build"; + script = [ + # sh + "nix build .#nixtest" + ]; + }; + "docs" = { + stage = "build"; + script = [ + # sh + '' + nix build .#docs:default + mkdir -p public + cp -r result/. public/ + '' + ]; + artifacts.paths = ["public"]; + }; + "pages" = { + nix.enable = false; + image = "alpine:latest"; + stage = "deploy"; + script = ["true"]; + artifacts.paths = ["public"]; + rules = [ + { + "if" = "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"; + } + ]; + }; + }; + }; + } diff --git a/nix/repo/devShells.nix b/nix/repo/devShells.nix new file mode 100644 index 0000000..1f425c9 --- /dev/null +++ b/nix/repo/devShells.nix @@ -0,0 +1,33 @@ +{ + inputs, + cell, + ... +}: let + inherit (inputs) pkgs devshell treefmt; + inherit (cell) soonix; +in { + default = devshell.mkShell { + imports = [soonix.devshellModule]; + packages = with pkgs; [ + (treefmt.mkWrapper pkgs { + programs = { + alejandra.enable = true; + mdformat.enable = true; + gofmt.enable = true; + }; + settings.formatter.mdformat.command = let + pkg = pkgs.python3.withPackages (p: [ + p.mdformat + p.mdformat-mkdocs + ]); + in "${pkg}/bin/mdformat"; + }) + gcc + go + gopls + delve + go-junit-report + gocover-cobertura + ]; + }; +} diff --git a/nix/repo/docs.nix b/nix/repo/docs.nix new file mode 100644 index 0000000..f8aea5c --- /dev/null +++ b/nix/repo/docs.nix @@ -0,0 +1,64 @@ +{inputs, ...}: let + inherit (inputs) pkgs doclib ntlib; + + optionsDoc = doclib.mkOptionDocs { + module = ntlib.module; + roots = [ + { + url = "https://gitlab.com/TECHNOFAB/nixtest/-/blob/main/lib"; + path = "${inputs.self}/lib"; + } + ]; + }; + optionsDocs = pkgs.runCommand "options-docs" {} '' + mkdir -p $out + ln -s ${optionsDoc} $out/options.md + ''; +in + (doclib.mkDocs { + docs."default" = { + base = "${inputs.self}"; + path = "${inputs.self}/docs"; + material = { + enable = true; + colors = { + primary = "green"; + accent = "light green"; + }; + umami = { + enable = true; + src = "https://analytics.tf/umami"; + siteId = "716d1869-9342-4b62-a770-e15d2d5c807d"; + domains = ["nixtest.projects.tf"]; + }; + }; + macros = { + enable = true; + includeDir = toString optionsDocs; + }; + config = { + site_name = "Nixtest"; + site_url = "https://nixtest.projects.tf"; + repo_name = "TECHNOFAB/nixtest"; + repo_url = "https://gitlab.com/TECHNOFAB/nixtest"; + extra_css = ["style.css"]; + theme = { + logo = "images/logo.svg"; + icon.repo = "simple/gitlab"; + favicon = "images/logo.svg"; + }; + nav = [ + {"Introduction" = "index.md";} + {"Usage" = "usage.md";} + {"Reference" = "reference.md";} + {"CLI" = "cli.md";} + {"Example Configs" = "examples.md";} + {"Options" = "options.md";} + ]; + markdown_extensions = [ + "pymdownx.superfences" + "admonition" + ]; + }; + }; + }).packages diff --git a/nix/repo/flake.lock b/nix/repo/flake.lock new file mode 100644 index 0000000..930798e --- /dev/null +++ b/nix/repo/flake.lock @@ -0,0 +1,100 @@ +{ + "nodes": { + "devshell-lib": { + "locked": { + "dir": "lib", + "lastModified": 1758204313, + "narHash": "sha256-ainbY0Oajb1HMdvy+A8QxF/P5qwcbEzJGEY5pzKdDdc=", + "owner": "rensa-nix", + "repo": "devshell", + "rev": "7d0c4bc78d9f017a739b0c7eb2f4e563118353e6", + "type": "gitlab" + }, + "original": { + "dir": "lib", + "owner": "rensa-nix", + "repo": "devshell", + "type": "gitlab" + } + }, + "nix-gitlab-ci-lib": { + "locked": { + "dir": "lib", + "lastModified": 1765444672, + "narHash": "sha256-B0cMjRs9P50ym9Le0VUcRN69Yy6tbV13MXq81tTTEus=", + "owner": "TECHNOFAB", + "repo": "nix-gitlab-ci", + "rev": "8f88a53b5479773cd626420362631bc1da99e677", + "type": "gitlab" + }, + "original": { + "dir": "lib", + "owner": "TECHNOFAB", + "ref": "3.1.2", + "repo": "nix-gitlab-ci", + "type": "gitlab" + } + }, + "nixmkdocs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1763481845, + "narHash": "sha256-Bp0+9rDmlPWMcnKqGx+BG4+o5KO8FuDAOvXRnXrm3Fo=", + "owner": "TECHNOFAB", + "repo": "nixmkdocs", + "rev": "73d59093df94a894d25bc4bf71880b6f00faa62f", + "type": "gitlab" + }, + "original": { + "dir": "lib", + "owner": "TECHNOFAB", + "repo": "nixmkdocs", + "type": "gitlab" + } + }, + "root": { + "inputs": { + "devshell-lib": "devshell-lib", + "nix-gitlab-ci-lib": "nix-gitlab-ci-lib", + "nixmkdocs-lib": "nixmkdocs-lib", + "soonix-lib": "soonix-lib", + "treefmt-nix": "treefmt-nix" + } + }, + "soonix-lib": { + "locked": { + "dir": "lib", + "lastModified": 1763323017, + "narHash": "sha256-MJyg37d+VMfRoFiVUj16FW+zkEwQXbgK9LoFF/SHoxA=", + "owner": "TECHNOFAB", + "repo": "soonix", + "rev": "078034b01e4eaf1f9436d46721f7cbe0d96eb8b4", + "type": "gitlab" + }, + "original": { + "dir": "lib", + "owner": "TECHNOFAB", + "repo": "soonix", + "type": "gitlab" + } + }, + "treefmt-nix": { + "flake": false, + "locked": { + "lastModified": 1762938485, + "narHash": "sha256-AlEObg0syDl+Spi4LsZIBrjw+snSVU4T8MOeuZJUJjM=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "5b4ee75aeefd1e2d5a1cc43cf6ba65eba75e83e4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nix/repo/flake.nix b/nix/repo/flake.nix new file mode 100644 index 0000000..7452c07 --- /dev/null +++ b/nix/repo/flake.nix @@ -0,0 +1,22 @@ +{ + inputs = { + devshell-lib.url = "gitlab:rensa-nix/devshell?dir=lib"; + soonix-lib.url = "gitlab:TECHNOFAB/soonix?dir=lib"; + nix-gitlab-ci-lib.url = "gitlab:TECHNOFAB/nix-gitlab-ci/3.1.2?dir=lib"; + nixmkdocs-lib.url = "gitlab:TECHNOFAB/nixmkdocs?dir=lib"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + flake = false; + }; + }; + outputs = i: + i + // { + devshell = i.devshell-lib.lib {inherit (i.parent) pkgs;}; + soonix = i.soonix-lib.lib {inherit (i.parent) pkgs;}; + cilib = i.nix-gitlab-ci-lib.lib {inherit (i.parent) pkgs;}; + doclib = i.nixmkdocs-lib.lib {inherit (i.parent) pkgs;}; + ntlib = import "${i.parent.self}/lib" {inherit (i.parent) pkgs;}; + treefmt = import i.treefmt-nix; + }; +} diff --git a/nix/repo/soonix.nix b/nix/repo/soonix.nix new file mode 100644 index 0000000..9eaab59 --- /dev/null +++ b/nix/repo/soonix.nix @@ -0,0 +1,34 @@ +{ + inputs, + cell, + ... +}: let + inherit (inputs) soonix; + inherit (cell) ci; +in + (soonix.make { + hooks = { + ci = ci.soonix; + renovate = { + output = ".gitlab/renovate.json5"; + data = { + extends = ["config:recommended"]; + postUpgradeTasks.commands = [ + "nix-portable nix run .#update-package" + "nix-portable nix run .#soonix:update" + ]; + lockFileMaintenance = { + enabled = true; + extends = ["schedule:monthly"]; + }; + nix.enabled = true; + gitlabci.enabled = false; + }; + hook = { + mode = "copy"; + gitignore = false; + }; + opts.format = "json"; + }; + }; + }).config diff --git a/nix/repo/tests.nix b/nix/repo/tests.nix new file mode 100644 index 0000000..9e2e8fb --- /dev/null +++ b/nix/repo/tests.nix @@ -0,0 +1,10 @@ +{inputs, ...}: let + inherit (inputs) pkgs ntlib; +in { + tests = ntlib.mkNixtest { + modules = ntlib.autodiscover {dir = "${inputs.self}/tests";}; + args = { + inherit pkgs ntlib; + }; + }; +} diff --git a/package.nix b/package.nix index cce5967..82976d2 100644 --- a/package.nix +++ b/package.nix @@ -4,7 +4,8 @@ ... }: buildGoModule { - name = "nixtest"; + pname = "nixtest"; + version = "latest"; src = # filter everything except for cmd/ and go.mod, go.sum with lib.fileset; diff --git a/snapshots/pretty-snapshot.snap.json b/snapshots/pretty-snapshot.snap.json index d7ee4ed..6349f86 100644 --- a/snapshots/pretty-snapshot.snap.json +++ b/snapshots/pretty-snapshot.snap.json @@ -1 +1 @@ -"{\n example = \u003cfunction\u003e;\n example2 = {\n drv = \u003cderivation hello-2.12.1\u003e;\n };\n}" \ No newline at end of file +"{\n example = \u003cfunction\u003e;\n example2 = {\n drv = \u003cderivation hello-2.12.2\u003e;\n };\n}" From 318b903d122b7628181f2ae277a882e2328b1d1d Mon Sep 17 00:00:00 2001 From: technofab Date: Sun, 14 Dec 2025 15:23:19 +0100 Subject: [PATCH 05/12] chore: rename module to uppercase --- cmd/nixtest/main.go | 16 ++++++++-------- go.mod | 2 +- internal/nix/service.go | 2 +- internal/nix/service_test.go | 2 +- internal/report/console/console.go | 4 ++-- internal/report/console/console_test.go | 2 +- internal/report/junit/junit.go | 4 ++-- internal/report/junit/junit_test.go | 2 +- internal/runner/runner.go | 8 ++++---- internal/runner/runner_test.go | 4 ++-- internal/snapshot/service.go | 4 ++-- internal/snapshot/service_test.go | 2 +- internal/util/util.go | 2 +- internal/util/util_test.go | 2 +- 14 files changed, 28 insertions(+), 28 deletions(-) diff --git a/cmd/nixtest/main.go b/cmd/nixtest/main.go index fef12b1..5e71553 100644 --- a/cmd/nixtest/main.go +++ b/cmd/nixtest/main.go @@ -3,14 +3,14 @@ package main import ( "os" - "gitlab.com/technofab/nixtest/internal/config" - appnix "gitlab.com/technofab/nixtest/internal/nix" - "gitlab.com/technofab/nixtest/internal/report/console" - "gitlab.com/technofab/nixtest/internal/report/junit" - "gitlab.com/technofab/nixtest/internal/runner" - appsnap "gitlab.com/technofab/nixtest/internal/snapshot" - "gitlab.com/technofab/nixtest/internal/types" - "gitlab.com/technofab/nixtest/internal/util" + "gitlab.com/TECHNOFAB/nixtest/internal/config" + appnix "gitlab.com/TECHNOFAB/nixtest/internal/nix" + "gitlab.com/TECHNOFAB/nixtest/internal/report/console" + "gitlab.com/TECHNOFAB/nixtest/internal/report/junit" + "gitlab.com/TECHNOFAB/nixtest/internal/runner" + appsnap "gitlab.com/TECHNOFAB/nixtest/internal/snapshot" + "gitlab.com/TECHNOFAB/nixtest/internal/types" + "gitlab.com/TECHNOFAB/nixtest/internal/util" "github.com/rs/zerolog" "github.com/rs/zerolog/log" diff --git a/go.mod b/go.mod index bb9e578..b35c7f4 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module gitlab.com/technofab/nixtest +module gitlab.com/TECHNOFAB/nixtest go 1.23.0 diff --git a/internal/nix/service.go b/internal/nix/service.go index 40461f9..a3551d3 100644 --- a/internal/nix/service.go +++ b/internal/nix/service.go @@ -8,7 +8,7 @@ import ( "os/exec" "strings" - apperrors "gitlab.com/technofab/nixtest/internal/errors" + apperrors "gitlab.com/TECHNOFAB/nixtest/internal/errors" ) // Service defines operations related to Nix diff --git a/internal/nix/service_test.go b/internal/nix/service_test.go index 0df0658..781a8cd 100644 --- a/internal/nix/service_test.go +++ b/internal/nix/service_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - apperrors "gitlab.com/technofab/nixtest/internal/errors" + apperrors "gitlab.com/TECHNOFAB/nixtest/internal/errors" ) func TestHelperProcess(t *testing.T) { diff --git a/internal/report/console/console.go b/internal/report/console/console.go index 959741c..efca37f 100644 --- a/internal/report/console/console.go +++ b/internal/report/console/console.go @@ -11,8 +11,8 @@ import ( "github.com/jedib0t/go-pretty/v6/text" "github.com/rs/zerolog/log" "github.com/sergi/go-diff/diffmatchpatch" - "gitlab.com/technofab/nixtest/internal/types" - "gitlab.com/technofab/nixtest/internal/util" + "gitlab.com/TECHNOFAB/nixtest/internal/types" + "gitlab.com/TECHNOFAB/nixtest/internal/util" ) // PrintErrors prints error messages for failed tests diff --git a/internal/report/console/console_test.go b/internal/report/console/console_test.go index bbe9a6a..d562de4 100644 --- a/internal/report/console/console_test.go +++ b/internal/report/console/console_test.go @@ -12,7 +12,7 @@ import ( "time" "github.com/jedib0t/go-pretty/v6/text" - "gitlab.com/technofab/nixtest/internal/types" + "gitlab.com/TECHNOFAB/nixtest/internal/types" ) // captureOutput captures stdout and stderr during the execution of a function diff --git a/internal/report/junit/junit.go b/internal/report/junit/junit.go index a376600..be2fcb3 100644 --- a/internal/report/junit/junit.go +++ b/internal/report/junit/junit.go @@ -7,8 +7,8 @@ import ( "strings" "time" - "gitlab.com/technofab/nixtest/internal/types" - "gitlab.com/technofab/nixtest/internal/util" + "gitlab.com/TECHNOFAB/nixtest/internal/types" + "gitlab.com/TECHNOFAB/nixtest/internal/util" ) type JUnitReport struct { diff --git a/internal/report/junit/junit_test.go b/internal/report/junit/junit_test.go index fbca0aa..afccbb5 100644 --- a/internal/report/junit/junit_test.go +++ b/internal/report/junit/junit_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "gitlab.com/technofab/nixtest/internal/types" + "gitlab.com/TECHNOFAB/nixtest/internal/types" ) func formatDurationSeconds(d time.Duration) string { diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 99783e9..8ccb8df 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -9,10 +9,10 @@ import ( "time" "github.com/rs/zerolog/log" - "gitlab.com/technofab/nixtest/internal/nix" - "gitlab.com/technofab/nixtest/internal/snapshot" - "gitlab.com/technofab/nixtest/internal/types" - "gitlab.com/technofab/nixtest/internal/util" + "gitlab.com/TECHNOFAB/nixtest/internal/nix" + "gitlab.com/TECHNOFAB/nixtest/internal/snapshot" + "gitlab.com/TECHNOFAB/nixtest/internal/types" + "gitlab.com/TECHNOFAB/nixtest/internal/util" ) // Runner executes tests based on provided specifications and configuration diff --git a/internal/runner/runner_test.go b/internal/runner/runner_test.go index 2bbffa6..582c2c1 100644 --- a/internal/runner/runner_test.go +++ b/internal/runner/runner_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - apperrors "gitlab.com/technofab/nixtest/internal/errors" - "gitlab.com/technofab/nixtest/internal/types" + apperrors "gitlab.com/TECHNOFAB/nixtest/internal/errors" + "gitlab.com/TECHNOFAB/nixtest/internal/types" ) // --- Mock Service Implementations --- diff --git a/internal/snapshot/service.go b/internal/snapshot/service.go index 932ece8..72f8802 100644 --- a/internal/snapshot/service.go +++ b/internal/snapshot/service.go @@ -7,8 +7,8 @@ import ( "path/filepath" "strings" - apperrors "gitlab.com/technofab/nixtest/internal/errors" - "gitlab.com/technofab/nixtest/internal/util" + apperrors "gitlab.com/TECHNOFAB/nixtest/internal/errors" + "gitlab.com/TECHNOFAB/nixtest/internal/util" ) // Service defines operations related to test snapshots diff --git a/internal/snapshot/service_test.go b/internal/snapshot/service_test.go index 9a1f4bb..b82b070 100644 --- a/internal/snapshot/service_test.go +++ b/internal/snapshot/service_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - apperrors "gitlab.com/technofab/nixtest/internal/errors" + apperrors "gitlab.com/TECHNOFAB/nixtest/internal/errors" ) func TestDefaultService_GetPath(t *testing.T) { diff --git a/internal/util/util.go b/internal/util/util.go index 63e7252..9916a75 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -8,7 +8,7 @@ import ( "github.com/akedrou/textdiff" "github.com/akedrou/textdiff/myers" - apperrors "gitlab.com/technofab/nixtest/internal/errors" + apperrors "gitlab.com/TECHNOFAB/nixtest/internal/errors" ) func ComputeDiff(expected, actual string) (string, error) { diff --git a/internal/util/util_test.go b/internal/util/util_test.go index 0928c06..fa76a20 100644 --- a/internal/util/util_test.go +++ b/internal/util/util_test.go @@ -8,7 +8,7 @@ import ( "strings" "testing" - apperrors "gitlab.com/technofab/nixtest/internal/errors" + apperrors "gitlab.com/TECHNOFAB/nixtest/internal/errors" ) func TestComputeDiff(t *testing.T) { From dab1e2ef6f49d91174216aed8216aa98f9a071ed Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sun, 14 Dec 2025 23:15:53 +0000 Subject: [PATCH 06/12] fix(deps): update module github.com/stretchr/testify to v1.11.1 --- go.mod | 2 +- go.sum | 2 ++ package.nix | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index b35c7f4..ad45ff0 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/akedrou/textdiff v0.1.0 github.com/rs/zerolog v1.34.0 github.com/spf13/pflag v1.0.6 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 ) require ( diff --git a/go.sum b/go.sum index 84d30d0..b4025dd 100644 --- a/go.sum +++ b/go.sum @@ -38,6 +38,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/package.nix b/package.nix index 82976d2..41e5f20 100644 --- a/package.nix +++ b/package.nix @@ -19,6 +19,6 @@ buildGoModule { ]; }; subPackages = ["cmd/nixtest"]; - vendorHash = "sha256-6kARJgngmXielUoXukYdAA0QHk1mwLRvgKJhx+v1iSo="; + vendorHash = "sha256-vH9lQqLWeaNIvWEZs7uPmPL6cINBzrteOJaIMgdRXZM="; meta.mainProgram = "nixtest"; } From be32005bc74bf9bfd5856cc4c2e33bdf2bce3090 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 15 Dec 2025 00:07:32 +0000 Subject: [PATCH 07/12] fix(deps): update module github.com/spf13/pflag to v1.0.10 --- go.mod | 2 +- go.sum | 2 ++ package.nix | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index ad45ff0..8acae20 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.0 require ( github.com/akedrou/textdiff v0.1.0 github.com/rs/zerolog v1.34.0 - github.com/spf13/pflag v1.0.6 + github.com/spf13/pflag v1.0.10 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index b4025dd..c3578f4 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,8 @@ github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= diff --git a/package.nix b/package.nix index 41e5f20..8221b6d 100644 --- a/package.nix +++ b/package.nix @@ -19,6 +19,6 @@ buildGoModule { ]; }; subPackages = ["cmd/nixtest"]; - vendorHash = "sha256-vH9lQqLWeaNIvWEZs7uPmPL6cINBzrteOJaIMgdRXZM="; + vendorHash = "sha256-uyVSXUSoDfOhRxrtUd6KQWmx6I8kw3PJxKfYMZgz3h8="; meta.mainProgram = "nixtest"; } From 056851d6c6303517f79207bed1d7c64d1e584cb6 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 15 Dec 2025 07:08:30 +0000 Subject: [PATCH 08/12] fix(deps): update module github.com/jedib0t/go-pretty/v6 to v6.7.7 --- go.mod | 2 +- go.sum | 2 ++ package.nix | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 8acae20..1cf33e0 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( ) require ( - github.com/jedib0t/go-pretty/v6 v6.6.7 + github.com/jedib0t/go-pretty/v6 v6.7.7 github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/sergi/go-diff v1.3.1 diff --git a/go.sum b/go.sum index c3578f4..a286b47 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/jedib0t/go-pretty/v6 v6.6.7 h1:m+LbHpm0aIAPLzLbMfn8dc3Ht8MW7lsSO4MPItz/Uuo= github.com/jedib0t/go-pretty/v6 v6.6.7/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU= +github.com/jedib0t/go-pretty/v6 v6.7.7 h1:Y1Id3lJ3k4UB8uwWWy3l8EVFnUlx5chR5+VbsofPNX0= +github.com/jedib0t/go-pretty/v6 v6.7.7/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= diff --git a/package.nix b/package.nix index 8221b6d..ea53831 100644 --- a/package.nix +++ b/package.nix @@ -19,6 +19,6 @@ buildGoModule { ]; }; subPackages = ["cmd/nixtest"]; - vendorHash = "sha256-uyVSXUSoDfOhRxrtUd6KQWmx6I8kw3PJxKfYMZgz3h8="; + vendorHash = "sha256-TtsIoXMBjMU/AlILgWcyv5TwYuBSdoyDbKrOdnJbdKQ="; meta.mainProgram = "nixtest"; } From b0988954c70ef059dc6501b09b4d116567442a16 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 15 Dec 2025 08:09:53 +0000 Subject: [PATCH 09/12] fix(deps): update module github.com/sergi/go-diff to v1.4.0 --- go.mod | 2 +- go.sum | 2 ++ package.nix | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 1cf33e0..b0e27d6 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,6 @@ require ( github.com/jedib0t/go-pretty/v6 v6.7.7 github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/sergi/go-diff v1.3.1 + github.com/sergi/go-diff v1.4.0 golang.org/x/sys v0.33.0 // indirect ) diff --git a/go.sum b/go.sum index a286b47..ffb4c39 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,8 @@ github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY= github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= +github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw= +github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= diff --git a/package.nix b/package.nix index ea53831..b930d30 100644 --- a/package.nix +++ b/package.nix @@ -19,6 +19,6 @@ buildGoModule { ]; }; subPackages = ["cmd/nixtest"]; - vendorHash = "sha256-TtsIoXMBjMU/AlILgWcyv5TwYuBSdoyDbKrOdnJbdKQ="; + vendorHash = "sha256-6CJ1noKOcNW0lHCe0hZse7+Dcvq+A02yvAKqq+dawE8="; meta.mainProgram = "nixtest"; } From 98250aa7e7cb94633af7da483aad43098aa0109c Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 23 Dec 2025 14:09:03 +0000 Subject: [PATCH 10/12] fix(deps): update module github.com/jedib0t/go-pretty/v6 to v6.7.8 --- go.mod | 2 +- go.sum | 2 ++ package.nix | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index b0e27d6..ab355c0 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( ) require ( - github.com/jedib0t/go-pretty/v6 v6.7.7 + github.com/jedib0t/go-pretty/v6 v6.7.8 github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/sergi/go-diff v1.4.0 diff --git a/go.sum b/go.sum index ffb4c39..d15139e 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/jedib0t/go-pretty/v6 v6.6.7 h1:m+LbHpm0aIAPLzLbMfn8dc3Ht8MW7lsSO4MPIt github.com/jedib0t/go-pretty/v6 v6.6.7/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU= github.com/jedib0t/go-pretty/v6 v6.7.7 h1:Y1Id3lJ3k4UB8uwWWy3l8EVFnUlx5chR5+VbsofPNX0= github.com/jedib0t/go-pretty/v6 v6.7.7/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU= +github.com/jedib0t/go-pretty/v6 v6.7.8 h1:BVYrDy5DPBA3Qn9ICT+PokP9cvCv1KaHv2i+Hc8sr5o= +github.com/jedib0t/go-pretty/v6 v6.7.8/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= diff --git a/package.nix b/package.nix index b930d30..fb6c468 100644 --- a/package.nix +++ b/package.nix @@ -19,6 +19,6 @@ buildGoModule { ]; }; subPackages = ["cmd/nixtest"]; - vendorHash = "sha256-6CJ1noKOcNW0lHCe0hZse7+Dcvq+A02yvAKqq+dawE8="; + vendorHash = "sha256-WF/lzu9lt9SR3WiA8LLWVT1OwpE3sIOtSqf4HMIMmE8="; meta.mainProgram = "nixtest"; } From e25fb0c609811d15a529be8446c0f627a22cf452 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Thu, 1 Jan 2026 14:47:37 +0000 Subject: [PATCH 11/12] chore(deps): lock file maintenance --- flake.lock | 12 ++++++------ nix/repo/flake.lock | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/flake.lock b/flake.lock index 6d5a6ab..52851d2 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1765472234, - "narHash": "sha256-9VvC20PJPsleGMewwcWYKGzDIyjckEz8uWmT0vCDYK0=", + "lastModified": 1767116409, + "narHash": "sha256-5vKw92l1GyTnjoLzEagJy5V5mDFck72LiQWZSOnSicw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "2fbfb1d73d239d2402a8fe03963e37aab15abe8b", + "rev": "cad22e7d996aea55ecab064e84834289143e44a0", "type": "github" }, "original": { @@ -37,11 +37,11 @@ }, "locked": { "dir": "lib", - "lastModified": 1758738378, - "narHash": "sha256-NjzqdvQCDDdObEBH8x/vdhbdhrIB+N9E570uCdksGHY=", + "lastModified": 1766497301, + "narHash": "sha256-W7WeOXMUZROMtbU1qQNWy/yai+k8gG09YACFQ7ImpsQ=", "owner": "rensa-nix", "repo": "core", - "rev": "abe19f9f13aff41de2b63304545c87d193d19ef4", + "rev": "e08c48b5db1052bfb8b8dad764e05decc1af893e", "type": "gitlab" }, "original": { diff --git a/nix/repo/flake.lock b/nix/repo/flake.lock index 930798e..7d7a104 100644 --- a/nix/repo/flake.lock +++ b/nix/repo/flake.lock @@ -3,11 +3,11 @@ "devshell-lib": { "locked": { "dir": "lib", - "lastModified": 1758204313, - "narHash": "sha256-ainbY0Oajb1HMdvy+A8QxF/P5qwcbEzJGEY5pzKdDdc=", + "lastModified": 1767274074, + "narHash": "sha256-h2grM9qoSnYdqN7K8+taeMuWC2umaN/c2FCBu48frlo=", "owner": "rensa-nix", "repo": "devshell", - "rev": "7d0c4bc78d9f017a739b0c7eb2f4e563118353e6", + "rev": "5508ced269ee40ff7f5261ee3b5bf5597f7cad5d", "type": "gitlab" }, "original": { @@ -38,11 +38,11 @@ "nixmkdocs-lib": { "locked": { "dir": "lib", - "lastModified": 1763481845, - "narHash": "sha256-Bp0+9rDmlPWMcnKqGx+BG4+o5KO8FuDAOvXRnXrm3Fo=", + "lastModified": 1766404754, + "narHash": "sha256-EjBe6x6BT8ckPirMWhSf1GfaFxORYxR/Uu71FvSAm60=", "owner": "TECHNOFAB", "repo": "nixmkdocs", - "rev": "73d59093df94a894d25bc4bf71880b6f00faa62f", + "rev": "cfa9606eeeb9288e2799896d7d42b3d3860f9ccb", "type": "gitlab" }, "original": { @@ -64,11 +64,11 @@ "soonix-lib": { "locked": { "dir": "lib", - "lastModified": 1763323017, - "narHash": "sha256-MJyg37d+VMfRoFiVUj16FW+zkEwQXbgK9LoFF/SHoxA=", + "lastModified": 1767274116, + "narHash": "sha256-8+VeMokZHjOLs6fRUTj/9uxbMlHKDl384Tk6K8Qjm4k=", "owner": "TECHNOFAB", "repo": "soonix", - "rev": "078034b01e4eaf1f9436d46721f7cbe0d96eb8b4", + "rev": "56f281eea45bdcf29674adfa7962f14e490a6051", "type": "gitlab" }, "original": { @@ -81,11 +81,11 @@ "treefmt-nix": { "flake": false, "locked": { - "lastModified": 1762938485, - "narHash": "sha256-AlEObg0syDl+Spi4LsZIBrjw+snSVU4T8MOeuZJUJjM=", + "lastModified": 1767122417, + "narHash": "sha256-yOt/FTB7oSEKQH9EZMFMeuldK1HGpQs2eAzdS9hNS/o=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "5b4ee75aeefd1e2d5a1cc43cf6ba65eba75e83e4", + "rev": "dec15f37015ac2e774c84d0952d57fcdf169b54d", "type": "github" }, "original": { From c64e0cce0c5ba9d77597f20f002d1375deb8e577 Mon Sep 17 00:00:00 2001 From: technofab Date: Tue, 20 Jan 2026 20:11:18 +0100 Subject: [PATCH 12/12] feat: add support for running NixOS VM tests more easily --- docs/usage.md | 18 ++++++ lib/module.nix | 109 ++++++++++++++++++++++++++------- tests/fixtures/sample_test.nix | 33 ++++++++++ tests/lib_test.nix | 3 +- 4 files changed, 139 insertions(+), 24 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index ee7598c..71b8e2f 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -64,6 +64,7 @@ There are currently 3 types of tests: - `snapshot` -> snapshot testing, only needs `actual` and compares that to the snapshot - `unit` -> equality checking, needs `expected` and `actual` or `actualDrv` - `script` -> shell script test, needs `script` +- `vm` -> NixOS VM test, needs `vmConfig` Examples: @@ -126,6 +127,23 @@ Examples: expected = pkgs.hello; actual = pkgs.hello; } + { + name = "vm-test"; + type = "vm"; + # gets passed to pkgs.testers.nixosTest, so same params apply + # name gets automatically set, so thats not required + vmConfig = { + nodes.machine = { + services.nginx.enable = true; + }; + testScript = + # py + '' + machine.wait_for_unit("nginx.service") + machine.wait_for_open_port(80) + ''; + }; + } ] ``` diff --git a/lib/module.nix b/lib/module.nix index 1600c50..3028e30 100644 --- a/lib/module.nix +++ b/lib/module.nix @@ -14,6 +14,7 @@ assertMsg generators literalExpression + xor ; nixtest-lib = import ./default.nix {inherit pkgs lib;}; @@ -72,25 +73,17 @@ in "${fileRelative}:${toString val.line}"; }; type = mkOption { - type = types.enum ["unit" "snapshot" "script"]; + type = types.enum ["unit" "snapshot" "script" "vm"]; description = '' - Type of test, has to be one of "unit", "snapshot" or "script". + Type of test, has to be one of "unit", "snapshot", "script", or "vm". ''; default = "unit"; apply = value: - assert assertMsg (value != "script" || !isUnset config.script) + assert assertMsg (value == "script" -> !isUnset config.script) "test '${config.name}' as type 'script' requires 'script' to be set"; - assert assertMsg (value != "unit" || !isUnset config.expected) + assert assertMsg (value == "unit" -> !isUnset config.expected) "test '${config.name}' as type 'unit' requires 'expected' to be set"; - assert assertMsg ( - let - actualIsUnset = isUnset config.actual; - actualDrvIsUnset = isUnset config.actualDrv; - in - (value != "unit") - || (!actualIsUnset && actualDrvIsUnset) - || (actualIsUnset && !actualDrvIsUnset) - ) + assert assertMsg (value == "unit" -> (xor (isUnset config.actual) (isUnset config.actualDrv))) "test '${config.name}' as type 'unit' requires only 'actual' OR 'actualDrv' to be set"; value; }; name = mkOption { @@ -162,6 +155,59 @@ builtins.unsafeDiscardStringContext (pkgs.writeShellScript "nixtest-${config.name}" val).drvPath; }; + vmConfig = mkUnsetOption { + type = types.attrs; + description = '' + Configuration for `pkgs.testers.nixosText`. + ''; + example = { + nodes.machine = { + services.nginx.enable = true; + }; + testScript = + # py + '' + machine.wait_for_unit("nginx.service") + machine.wait_for_open_port(80) + ''; + }; + }; + + finalConfig = mkOption { + internal = true; + type = types.attrs; + }; + }; + config = { + finalConfig = builtins.addErrorContext "[nixtest] while processing test ${config.name}" { + inherit (config) name expected actual actualDrv; + type = + if config.type == "vm" + then "script" + else config.type; + script = + if config.type == "vm" + then + assert assertMsg ((!isUnset config.vmConfig) && (config.vmConfig ? nodes) && (config.vmConfig ? testScript)) + "test '${config.name}' as type 'vm' requires 'vmConfig' to be set and contain 'nodes' & 'testScript'"; let + inherit + (pkgs.testers.nixosTest ( + { + name = "nixtest-vm-${config.name}"; + } + // config.vmConfig + )) + driver + ; + in + builtins.unsafeDiscardStringContext + (pkgs.writeShellScript "nixtest-vm-${config.name}" '' + # use different TMPDIR to prevent race conditions: + # vde_switch: Could not bind to socket '/tmp/vde1.ctl/ctl': Address already in use + TMPDIR=$(${pkgs.coreutils}/bin/mktemp -d) ${driver}/bin/nixos-test-driver + '').drvPath + else config.script; + }; }; }; @@ -201,6 +247,17 @@ ''; default = []; }; + + finalConfig = mkOption { + internal = true; + type = types.attrs; + }; + }; + config = { + finalConfig = builtins.addErrorContext "[nixtest] while processing suite ${config.name}" { + inherit (config) name; + tests = map (test: test.finalConfig) config.tests; + }; }; }; @@ -233,11 +290,6 @@ Define your test suites here, every test belongs to a suite. ''; default = {}; - apply = suites: - map ( - n: filterUnset (builtins.removeAttrs suites.${n} ["pos"]) - ) - (builtins.attrNames suites); example = { "Suite A".tests = [ { @@ -247,6 +299,10 @@ }; }; + finalConfig = mkOption { + internal = true; + type = types.listOf types.attrs; + }; finalConfigJson = mkOption { internal = true; type = types.package; @@ -257,11 +313,18 @@ }; }; config = { - finalConfigJson = nixtest-lib.exportSuites config.suites; - app = nixtest-lib.mkBinary { - nixtests = config.finalConfigJson; - extraParams = ''--skip="${config.skip}"''; - }; + finalConfig = map (suite: filterUnset suite.finalConfig) (builtins.attrValues config.suites); + finalConfigJson = + builtins.addErrorContext "[nixtest] while exporting suites" + (nixtest-lib.exportSuites config.finalConfig); + app = + (nixtest-lib.mkBinary { + nixtests = config.finalConfigJson; + extraParams = ''--skip="${config.skip}"''; + }) + // { + rawTests = config.finalConfig; + }; }; }; in diff --git a/tests/fixtures/sample_test.nix b/tests/fixtures/sample_test.nix index dcc2fb1..e505f15 100644 --- a/tests/fixtures/sample_test.nix +++ b/tests/fixtures/sample_test.nix @@ -49,6 +49,39 @@ grep -q "test" ${builtins.toFile "test" "test"} ''; } + { + name = "test-vm"; + type = "vm"; + vmConfig = { + nodes.machine = {pkgs, ...}: { + services.nginx = { + enable = true; + virtualHosts."localhost" = { + root = pkgs.writeTextDir "index.html" "Hello from nixtest VM!"; + }; + }; + }; + testScript = + # py + '' + machine.wait_for_unit("nginx.service") + machine.wait_for_open_port(80) + machine.succeed("curl -f http://localhost | grep 'Hello from nixtest VM!'") + ''; + }; + } + { + name = "vm-fail"; + type = "vm"; + vmConfig = { + nodes.machine = {}; + testScript = + # py + '' + machine.succeed("curl -f http://localhost | grep 'Hello from nixtest VM!'") + ''; + }; + } ]; }; "other-suite".tests = [ diff --git a/tests/lib_test.nix b/tests/lib_test.nix index 85a3c7a..7ae2c81 100644 --- a/tests/lib_test.nix +++ b/tests/lib_test.nix @@ -89,9 +89,10 @@ assert "-f junit2.xml" "should create junit2.xml" assert_not_contains "$output" "executable file not found" "nix should now exist" assert_contains "$output" "suite-one" "should contain suite-one" - assert_contains "$output" "8/11 (1 SKIPPED)" "should be 8/11 total" + assert_contains "$output" "9/13 (1 SKIPPED)" "should be 9/13 total" assert_contains "$output" "ERROR" "should contain an error" assert_contains "$output" "SKIP" "should contain a skip" + assert_contains "$output" "RequestedAssertionFailed" "vm-fail test should fail" ''; } ];