From d78b91ea178f24a3d86d5ee29375a9b1b5a9a85f Mon Sep 17 00:00:00 2001 From: Daniel-Andrei Minca Date: Sat, 6 Jul 2024 23:38:31 +0200 Subject: [PATCH 01/10] feat(nix): implement overlays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * setup repo structure * configure overlay for 'kluctl' package first; once this works, MVP delivered * since this is the initial commit on this feature, it's obviously broken and throwing the following error ```sh error: … while evaluating a branch condition at /nix/store/7gmkl9bfx98djaamhym69wkj4r3sh1q6-source/lib/lists.nix:125:9: 124| fold' = n: 125| if n == len | ^ 126| then nul … while calling the 'length' builtin at /nix/store/7gmkl9bfx98djaamhym69wkj4r3sh1q6-source/lib/lists.nix:123:13: 122| let 123| len = length list; | ^ 124| fold' = n: (stack trace truncated; use '--show-trace' to show the full trace) error: function 'anonymous lambda' called without required argument 'pkgs' at /nix/store/2cv47br877dpnc9p1cv3x95a27nsidb0-source/overlays/kluctl/default.nix:1:1: 1| { pkgs, config, lib, ... }: | ^ 2| ``` Resolves: #9 Related: Signed-off-by: Daniel-Andrei Minca --- flake.nix | 1 + overlays/default.nix | 10 ++++++++++ overlays/kluctl/default.nix | 7 +++++++ 3 files changed, 18 insertions(+) create mode 100644 overlays/default.nix create mode 100644 overlays/kluctl/default.nix diff --git a/flake.nix b/flake.nix index f789650..052d795 100644 --- a/flake.nix +++ b/flake.nix @@ -57,6 +57,7 @@ sops-nix.homeManagerModules.sops ./hosts/common ./hosts/M-C02FX3JUML85 + (args: { nixpkgs.overlays = import ./overlays args; } ) ]; }; }; diff --git a/overlays/default.nix b/overlays/default.nix new file mode 100644 index 0000000..8aeac0b --- /dev/null +++ b/overlays/default.nix @@ -0,0 +1,10 @@ +# import all nix files in the current folder, and execute them with args as parameters +# The return value is a list of all execution results, which is the list of overlays + +args: +# execute and import all overlay files in the current directory with the given args +builtins.map + (f: (import (./. + "/${f}") args)) # execute and import the overlay file + (builtins.filter # find all overlay files in the current directory + (f: f != "default.nix") + (builtins.attrNames (builtins.readDir ./.))) diff --git a/overlays/kluctl/default.nix b/overlays/kluctl/default.nix new file mode 100644 index 0000000..e7834e8 --- /dev/null +++ b/overlays/kluctl/default.nix @@ -0,0 +1,7 @@ +{ pkgs, config, lib, ... }: + +(self: super: { + kluctl = super.kluctl.override { + version = "2.25.0"; + }; +}) From aaaf6cfec9dc83d685e17b4f7f9939cabab441b1 Mon Sep 17 00:00:00 2001 From: Daniel-Andrei Minca Date: Sun, 7 Jul 2024 00:52:33 +0200 Subject: [PATCH 02/10] fix: drop the first lines Resolves: Related: Signed-off-by: Daniel-Andrei Minca --- overlays/default.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/overlays/default.nix b/overlays/default.nix index 8aeac0b..a2f58c9 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,6 +1,3 @@ -# import all nix files in the current folder, and execute them with args as parameters -# The return value is a list of all execution results, which is the list of overlays - args: # execute and import all overlay files in the current directory with the given args builtins.map From 6e55cceaf951a5e6ba01de4e6aebcd40336f970b Mon Sep 17 00:00:00 2001 From: Daniel-Andrei Minca Date: Sun, 7 Jul 2024 00:58:38 +0200 Subject: [PATCH 03/10] fix: use overrideAttrs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * this also doesn't fly, throws the same error error: … while evaluating a branch condition at /nix/store/7gmkl9bfx98djaamhym69wkj4r3sh1q6-source/lib/lists.nix:125:9: 124| fold' = n: 125| if n == len | ^ 126| then nul … while calling the 'length' builtin at /nix/store/7gmkl9bfx98djaamhym69wkj4r3sh1q6-source/lib/lists.nix:123:13: 122| let 123| len = length list; | ^ 124| fold' = n: (stack trace truncated; use '--show-trace' to show the full trace) error: function 'anonymous lambda' called without required argument 'pkgs' at /nix/store/92vr1hwi6r3yvadis7fdllvqfzb27n4k-source/overlays/kluctl/default.nix:1:1: 1| { pkgs, config, lib, ... }: | ^ 2| Resolves: Related: Signed-off-by: Daniel-Andrei Minca --- overlays/kluctl/default.nix | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/overlays/kluctl/default.nix b/overlays/kluctl/default.nix index e7834e8..afe3a54 100644 --- a/overlays/kluctl/default.nix +++ b/overlays/kluctl/default.nix @@ -1,7 +1,12 @@ { pkgs, config, lib, ... }: (self: super: { - kluctl = super.kluctl.override { - version = "2.25.0"; + kluctl = super.kluctl.overrideAttrs { + src = pkgs.fetchFromGitHub { + owner = "kluctl"; + repo = "kluctl"; + rev = "v2.25.0"; + hash = ""; + }; }; }) From 1abf8c161219d7eae00ffbcd60ff9ecdee047724 Mon Sep 17 00:00:00 2001 From: Daniel-Andrei Minca Date: Sun, 7 Jul 2024 01:12:37 +0200 Subject: [PATCH 04/10] fix: override buildGoModule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * applied Kevin's trick (thanks Kevin!) * https://kevinmacksa.me/post/20240128-nix-develop/ error: … while evaluating a branch condition at /nix/store/7gmkl9bfx98djaamhym69wkj4r3sh1q6-source/lib/lists.nix:125:9: 124| fold' = n: 125| if n == len | ^ 126| then nul … while calling the 'length' builtin at /nix/store/7gmkl9bfx98djaamhym69wkj4r3sh1q6-source/lib/lists.nix:123:13: 122| let 123| len = length list; | ^ 124| fold' = n: (stack trace truncated; use '--show-trace' to show the full trace) error: function 'anonymous lambda' called without required argument 'pkgs' at /nix/store/689c81khgfny2578misrv97mhf1m1hk6-source/overlays/kluctl/default.nix:1:1: 1| { pkgs, config, lib, ... }: | ^ 2| Resolves: Related: Signed-off-by: Daniel-Andrei Minca --- overlays/kluctl/default.nix | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/overlays/kluctl/default.nix b/overlays/kluctl/default.nix index afe3a54..6da49d3 100644 --- a/overlays/kluctl/default.nix +++ b/overlays/kluctl/default.nix @@ -1,12 +1,16 @@ { pkgs, config, lib, ... }: -(self: super: { - kluctl = super.kluctl.overrideAttrs { - src = pkgs.fetchFromGitHub { - owner = "kluctl"; - repo = "kluctl"; - rev = "v2.25.0"; - hash = ""; - }; +(final: prev: { + kluctl = prev.kluctl.override { + buildGoModule = previousArgs: prev.buildGoModule (previousArgs // rec { + version = "2.25.0"; + src = prev.fetchFromGitHub { + owner = "kluctl"; + repo = "kluctl"; + rev = "refs/tags/v${version}"; + hash = ""; + }; + }); }; }) + From 30ca434b9efa019a99d27d80623a478a89df1053 Mon Sep 17 00:00:00 2001 From: Daniel-Andrei Minca Date: Sun, 7 Jul 2024 01:28:43 +0200 Subject: [PATCH 05/10] fix: move overlays within home-manager module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix the hash * program is now successfully compiling * thanks to Kevin for writing this piece * https://kevinmacksa.me/post/20240128-nix-develop/ * if `args` is not consumed by nixpkgs.overlays through the `import` function, the following error will be thrown error: … while evaluating a branch condition at /nix/store/7gmkl9bfx98djaamhym69wkj4r3sh1q6-source/lib/lists.nix:125:9: 124| fold' = n: 125| if n == len | ^ 126| then nul … while calling the 'length' builtin at /nix/store/7gmkl9bfx98djaamhym69wkj4r3sh1q6-source/lib/lists.nix:123:13: 122| let 123| len = length list; | ^ 124| fold' = n: (stack trace truncated; use '--show-trace' to show the full trace) error: A definition for option `nixpkgs.overlays' is not of type `null or (list of (nixpkgs overlay))'. Definition values: - In `/nix/store/263gwwg2y9jxammp2yrrkpjwkqi1bnjv-source/hosts/M-C02FX3JUML85/home.nix': Resolves: Related: Signed-off-by: Daniel-Andrei Minca --- flake.nix | 1 - overlays/kluctl/default.nix | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 052d795..f789650 100644 --- a/flake.nix +++ b/flake.nix @@ -57,7 +57,6 @@ sops-nix.homeManagerModules.sops ./hosts/common ./hosts/M-C02FX3JUML85 - (args: { nixpkgs.overlays = import ./overlays args; } ) ]; }; }; diff --git a/overlays/kluctl/default.nix b/overlays/kluctl/default.nix index 6da49d3..722cc99 100644 --- a/overlays/kluctl/default.nix +++ b/overlays/kluctl/default.nix @@ -8,7 +8,7 @@ owner = "kluctl"; repo = "kluctl"; rev = "refs/tags/v${version}"; - hash = ""; + hash = "sha256-WtTBkc9mop+bfMcVLI8k4Bqmift5JG9riF+QbDeiR9c="; }; }); }; From 0dd38f54aa9fbaa3a2fdc6f7f95227f590d03d4d Mon Sep 17 00:00:00 2001 From: Daniel-Andrei Minca Date: Sun, 7 Jul 2024 10:54:00 +0200 Subject: [PATCH 06/10] fix: replace rec with let-in * `rec` is slow and has a lot of downsides; replace with `let-in` expression to avoid other strange issues what I was facing, for instance this error was thrown previously error: hash mismatch in fixed-output derivation '/nix/store/yw5l1d80v05y5bgdmc2yz4r1s2hqfvi7-kluctl-2.25.0-go-modules.drv': specified: sha256-EEOVd15f1SK8InSIG+TuVwWibkf+ePJ5AGZpiMD+RaQ= got: sha256-TckT39wQn4dclcYSfxootv1Lw5+iYxY6/wwdUc1+Z6s= error: 1 dependencies of derivation '/nix/store/f2dpnsp3zh52i5l6iaafrq45wc9370k6-kluctl-2.25.0.drv' failed to build error: 1 dependencies of derivation '/nix/store/f98mgwkpz9mq6cf8h34533khik8vy7iq-home-manager-applications.drv' failed to build error: 1 dependencies of derivation '/nix/store/lqx96ba7yjswfjfmsljb370ppci3hsch-home-manager-fonts.drv' failed to build error: 1 dependencies of derivation '/nix/store/vrssavvbiyjbiq4yb2psd9yis8zjlyyv-home-manager-path.drv' failed to build error: 1 dependencies of derivation '/nix/store/1cdk98lgzjyybirwq318zcxb81zlbdzh-home-manager-generation.drv' failed to build * this error is still present with the `let-in` expression ... Resolves: Related: Signed-off-by: Daniel-Andrei Minca --- overlays/kluctl/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/overlays/kluctl/default.nix b/overlays/kluctl/default.nix index 722cc99..f994391 100644 --- a/overlays/kluctl/default.nix +++ b/overlays/kluctl/default.nix @@ -2,15 +2,15 @@ (final: prev: { kluctl = prev.kluctl.override { - buildGoModule = previousArgs: prev.buildGoModule (previousArgs // rec { + buildGoModule = previousArgs: let self = prev.buildGoModule (previousArgs // { version = "2.25.0"; src = prev.fetchFromGitHub { owner = "kluctl"; repo = "kluctl"; - rev = "refs/tags/v${version}"; + rev = "refs/tags/v${self.version}"; hash = "sha256-WtTBkc9mop+bfMcVLI8k4Bqmift5JG9riF+QbDeiR9c="; }; - }); + }); in self; }; }) From 58080e5f7930bf044d97120128ce1adcbabdc038 Mon Sep 17 00:00:00 2001 From: Daniel-Andrei Minca Date: Sun, 7 Jul 2024 16:08:25 +0200 Subject: [PATCH 07/10] fix: override the vendorHash * this is a terrible hack but unfortunately it's necessary because buildGoModule computes the vendorHash after installing all Go modules * although overriding the vendorHash works just fine, there's still something wrong because the overlay is not applied properly, as per kluctl --version kluctl version v2.22.1 Resolves: Related: NixOS/nixpkgs#86349 Signed-off-by: Daniel-Andrei Minca --- overlays/kluctl/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/overlays/kluctl/default.nix b/overlays/kluctl/default.nix index f994391..45a1fe2 100644 --- a/overlays/kluctl/default.nix +++ b/overlays/kluctl/default.nix @@ -4,6 +4,7 @@ kluctl = prev.kluctl.override { buildGoModule = previousArgs: let self = prev.buildGoModule (previousArgs // { version = "2.25.0"; + vendorHash = "sha256-TckT39wQn4dclcYSfxootv1Lw5+iYxY6/wwdUc1+Z6s="; src = prev.fetchFromGitHub { owner = "kluctl"; repo = "kluctl"; From 9ece96e0e705e1da0c884af966c4e01c6539c5f8 Mon Sep 17 00:00:00 2001 From: Daniel-Andrei Minca Date: Tue, 22 Oct 2024 22:40:54 +0200 Subject: [PATCH 08/10] fix: adjust flake to consume overlay Resolves: Related: Signed-off-by: Daniel-Andrei Minca --- flake.nix | 11 +++++++++-- hosts/M-C02FX3JUML85/home.nix | 3 ++- overlays/kluctl/default.nix | 10 ++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/flake.nix b/flake.nix index f789650..d4c589c 100644 --- a/flake.nix +++ b/flake.nix @@ -43,7 +43,9 @@ defaultPackage.x86_64-darwin = home-manager.defaultPackage.x86_64-darwin; homeConfigurations = { "dminca" = home-manager.lib.homeManagerConfiguration { - pkgs = import nixpkgs { system = "aarch64-darwin"; }; + pkgs = import nixpkgs { + system = "aarch64-darwin"; + }; modules = [ sops-nix.homeManagerModules.sops ./hosts/common @@ -52,7 +54,12 @@ }; "DanielAndrei.Minca" = home-manager.lib.homeManagerConfiguration { - pkgs = import nixpkgs { system = "x86_64-darwin"; }; + pkgs = import nixpkgs { + system = "x86_64-darwin"; + overlays = [ + (builtins.trace "Importing overlay" (import ./overlays/kluctl)) + ]; + }; modules = [ sops-nix.homeManagerModules.sops ./hosts/common diff --git a/hosts/M-C02FX3JUML85/home.nix b/hosts/M-C02FX3JUML85/home.nix index 16e9b65..54f14e9 100644 --- a/hosts/M-C02FX3JUML85/home.nix +++ b/hosts/M-C02FX3JUML85/home.nix @@ -44,7 +44,8 @@ docker-client helm-ls helm-docs - kluctl + (builtins.trace "Using myPackage" pkgs.kluctlNew) + kluctlNew fx ######## # Apps # diff --git a/overlays/kluctl/default.nix b/overlays/kluctl/default.nix index 45a1fe2..a5e00ea 100644 --- a/overlays/kluctl/default.nix +++ b/overlays/kluctl/default.nix @@ -1,16 +1,14 @@ -{ pkgs, config, lib, ... }: - (final: prev: { - kluctl = prev.kluctl.override { + kluctlNew = prev.kluctl.override { buildGoModule = previousArgs: let self = prev.buildGoModule (previousArgs // { - version = "2.25.0"; + version = "2.25.1"; vendorHash = "sha256-TckT39wQn4dclcYSfxootv1Lw5+iYxY6/wwdUc1+Z6s="; src = prev.fetchFromGitHub { owner = "kluctl"; repo = "kluctl"; rev = "refs/tags/v${self.version}"; - hash = "sha256-WtTBkc9mop+bfMcVLI8k4Bqmift5JG9riF+QbDeiR9c="; - }; + hash = "sha256-EfzMDOIp/dfnpLTnaUkZ1sfGVtQqUgeGyHNiWIwSxQ4="; + }; }); in self; }; }) From ac62edf56a0c5c1885b42e97604405ad60c26447 Mon Sep 17 00:00:00 2001 From: Daniel-Andrei Minca Date: Tue, 22 Oct 2024 22:41:18 +0200 Subject: [PATCH 09/10] fix: remove redundant overlay importer * this function was supposed to load all overlays sitting under `./overlays/` , turns out it's givig more of a headacke Resolves: Related: Signed-off-by: Daniel-Andrei Minca --- overlays/default.nix | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 overlays/default.nix diff --git a/overlays/default.nix b/overlays/default.nix deleted file mode 100644 index a2f58c9..0000000 --- a/overlays/default.nix +++ /dev/null @@ -1,7 +0,0 @@ -args: -# execute and import all overlay files in the current directory with the given args -builtins.map - (f: (import (./. + "/${f}") args)) # execute and import the overlay file - (builtins.filter # find all overlay files in the current directory - (f: f != "default.nix") - (builtins.attrNames (builtins.readDir ./.))) From 041cecd86c9ab3bbe959a0f95695f1a26b540a47 Mon Sep 17 00:00:00 2001 From: Daniel-Andrei Minca Date: Tue, 22 Oct 2024 22:57:26 +0200 Subject: [PATCH 10/10] fix: overlay is used * even though the overlay is now used and compiled, hitting an infinite hashing mismatch issue error: hash mismatch in fixed-output derivation '/nix/store/gsdgyx2wdlqlxl555n532vgyn5j5bkhb-kluctl-2.25.1-go-modules.drv': specified: sha256-TckT39wQn4dclcYSfxootv1Lw5+iYxY6/wwdUc1+Z6s= got: sha256-iE4fPRq2kalP53AO3YaaqbRMH4Cl6XB5UseJmepoW+4= [0/9 built (1 failed), 0.0 MiB DL] building kluctl-2.25.1-go-modules (installPhase): Running phase: installPhase^Z error: 1 dependencies of derivation '/nix/store/4x4nz1a1ik137jpmcjaqi1yc9yzpiw6g-kluctl-2.25.1.drv' failed to build error: 1 dependencies of derivation '/nix/store/h8yslr3m7vw83z2hsyadxwb380rbm5bc-home-manager-applications.drv' failed to build error: 1 dependencies of derivation '/nix/store/p011vblrj14f7qhbdx496d9mak4pdg4s-home-manager-fonts.drv' failed to build error: 1 dependencies of derivation '/nix/store/vvwrs9c678wwnypvkzjfxspv1nalmgdc-home-manager-path.drv' failed to build error: 1 dependencies of derivation '/nix/store/wc39y38f1pcbz571hp2bp980frf0w7g4-home-manager-generation.drv' failed to build Resolves: Related: Signed-off-by: Daniel-Andrei Minca --- flake.nix | 2 +- hosts/M-C02FX3JUML85/home.nix | 3 +-- overlays/kluctl/default.nix | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index d4c589c..6e24399 100644 --- a/flake.nix +++ b/flake.nix @@ -57,7 +57,7 @@ pkgs = import nixpkgs { system = "x86_64-darwin"; overlays = [ - (builtins.trace "Importing overlay" (import ./overlays/kluctl)) + (import ./overlays/kluctl) ]; }; modules = [ diff --git a/hosts/M-C02FX3JUML85/home.nix b/hosts/M-C02FX3JUML85/home.nix index 54f14e9..16e9b65 100644 --- a/hosts/M-C02FX3JUML85/home.nix +++ b/hosts/M-C02FX3JUML85/home.nix @@ -44,8 +44,7 @@ docker-client helm-ls helm-docs - (builtins.trace "Using myPackage" pkgs.kluctlNew) - kluctlNew + kluctl fx ######## # Apps # diff --git a/overlays/kluctl/default.nix b/overlays/kluctl/default.nix index a5e00ea..d78a675 100644 --- a/overlays/kluctl/default.nix +++ b/overlays/kluctl/default.nix @@ -1,5 +1,5 @@ (final: prev: { - kluctlNew = prev.kluctl.override { + kluctl = prev.kluctl.override { buildGoModule = previousArgs: let self = prev.buildGoModule (previousArgs // { version = "2.25.1"; vendorHash = "sha256-TckT39wQn4dclcYSfxootv1Lw5+iYxY6/wwdUc1+Z6s=";