| 26 Dec 2024 |
| pierre joined the room. | 20:16:25 |
| 27 Dec 2024 |
| nazarewk changed their display name from nazarewk to kdn. | 12:39:14 |
| pinpox changed their display name from pinpox to pinpox [DECT: 7170]. | 15:23:14 |
| 31 Dec 2024 |
| kaya changed their profile picture. | 21:49:20 |
| 1 Jan 2025 |
| NixOS Moderation Botchanged room power levels. | 14:26:32 |
| pinpox changed their display name from pinpox [DECT: 7170] to pinpox. | 18:20:17 |
| 5 Jan 2025 |
| gotha joined the room. | 07:12:39 |
| 6 Jan 2025 |
| Frédéric Christ changed their display name from Frédéric Christ 🎄23.12. - 07.01. to Frédéric Christ. | 12:31:55 |
| 8 Jan 2025 |
| vendion joined the room. | 14:37:04 |
vendion | I don't know if this is the right channel for this question, but seeing as how I'm trying to build a Go application with devenv I figure it would be worth a shot.
I have a project that I'm using devenv to manage the development environment, and I have everyithng setup already so I can build the project with devenv build but the resulting binary just gets put in the nix store by default. I'm wanting to use the installPhase hook to put the resulting binary in the project directory but I seem to hit a roadblock in doing so. By default the resulting build artifact goes to a directory like /nix/store/l91035h1q89828h3vd5nzcss483k3k3g-dbctl-0.0.1, but I can't figure out what I need to do in the installPhase of my default.nix to have the resulting build artifact go to a path like ${PROJECT_ROOT}/out.
What I do know from trial and error:
- The PWD during the
buildPhase and installPhase is /build/source
- The
$out variable is set to the path to the Nix store (e.g. /nix/store/l91035h1q89828h3vd5nzcss483k3k3g-dbctl-0.0.1)
$src doesn't seem to work either, as it results in a perms error
If it helps here is my default.nix file:
{ lib
, pkgs
, name
, version
, ...
}:
pkgs.buildGoApplication {
pname = name;
version = version;
src = builtins.path {
path = ./.;
name = "source";
};
doCheck = false;
modules = ./gomod2nix.toml;
# installPhase = ''
# pwd
# mkdir -p $src/out/bin
# mv dbctl out/bin
# '';
meta = with lib; {
description = "Database management tool for RowLogic";
homepage = "";
maintainers = [ ];
};
}
| 15:34:39 |
| 9 Jan 2025 |
Diamond (it/she) | In reply to@vendion:matrix.org
I don't know if this is the right channel for this question, but seeing as how I'm trying to build a Go application with devenv I figure it would be worth a shot.
I have a project that I'm using devenv to manage the development environment, and I have everyithng setup already so I can build the project with devenv build but the resulting binary just gets put in the nix store by default. I'm wanting to use the installPhase hook to put the resulting binary in the project directory but I seem to hit a roadblock in doing so. By default the resulting build artifact goes to a directory like /nix/store/l91035h1q89828h3vd5nzcss483k3k3g-dbctl-0.0.1, but I can't figure out what I need to do in the installPhase of my default.nix to have the resulting build artifact go to a path like ${PROJECT_ROOT}/out.
What I do know from trial and error:
- The PWD during the
buildPhase and installPhase is /build/source
- The
$out variable is set to the path to the Nix store (e.g. /nix/store/l91035h1q89828h3vd5nzcss483k3k3g-dbctl-0.0.1)
$src doesn't seem to work either, as it results in a perms error
If it helps here is my default.nix file:
{ lib
, pkgs
, name
, version
, ...
}:
pkgs.buildGoApplication {
pname = name;
version = version;
src = builtins.path {
path = ./.;
name = "source";
};
doCheck = false;
modules = ./gomod2nix.toml;
# installPhase = ''
# pwd
# mkdir -p $src/out/bin
# mv dbctl out/bin
# '';
meta = with lib; {
description = "Database management tool for RowLogic";
homepage = "";
maintainers = [ ];
};
}
installPhase should already both build and move the binary into $out/bin, so you shouldn't be overriding it like that in buildGoApplication | 00:46:45 |
Diamond (it/she) | the only case where that wouldn't be true is if you don't have a package main, but it should complain I think | 00:47:13 |
Diamond (it/she) | what's the output of tree $out after building everything without overriding any phase? | 00:47:25 |
Diamond (it/she) | also I think you're trying to modify the source directory to add the build output? you can't do that | 00:48:02 |
Diamond (it/she) | $src is immutable | 00:48:16 |
Diamond (it/she) | $src is immutable (practically it's an immutable snapshot of the source code at the point of building) | 00:48:36 |
vendion | In reply to @diamondburned:matrix.org also I think you're trying to modify the source directory to add the build output? you can't do that Yeah, that is exactly what I was trying to do. Okay I'll have to rethink my approach as I was wanting to be able to use a CI pipeline to build the artifacts and use them as downloadable releases. The end users are not using Nix so having to work out deployment strategy | 00:51:12 |
Diamond (it/she) | so based on https://devenv.sh/outputs/#defining-outputs, devenv build's functionality is merely to build the packages and print out the outputs to stdout. if you want to make it also put that to a build artifact directory (why?), you might want to use a task to wrap it | 00:51:18 |
Diamond (it/she) | In reply to@vendion:matrix.org Yeah, that is exactly what I was trying to do. Okay I'll have to rethink my approach as I was wanting to be able to use a CI pipeline to build the artifacts and use them as downloadable releases. The end users are not using Nix so having to work out deployment strategy you can put the path to a variable then give that to the artifact upload command | 00:51:44 |
Diamond (it/she) | are you using GHA? | 00:51:48 |
Diamond (it/she) | consider something like echo "build_output=$(devenv build [optional name])" >> $GITHUB_OUTPUT then give build_output to the upload-artifacts action | 00:52:25 |
vendion | No, using SourceHut and their build process | 00:52:31 |
Diamond (it/she) | consider something like echo "build_output=$(devenv build [optional name])" >> $GITHUB_OUTPUT then give build_output to the upload-artifacts action using gha variables | 00:52:32 |
Diamond (it/she) | hmm | 00:52:36 |
Diamond (it/she) | then you want an extra step to symlink the output path to a known constant path maybe | 00:53:37 |
Diamond (it/she) | something like ln -s $(devenv build [package]) /tmp/build-output | 00:53:50 |
Diamond (it/she) | or even cp -r if you hate that for some reason | 00:53:54 |
vendion | In reply to @diamondburned:matrix.org something like ln -s $(devenv build [package]) /tmp/build-output Yeah, I was just thinking that | 00:54:13 |
Diamond (it/she) | then you should be able to give it - /tmp/build-output/bin/$name | 00:54:14 |
vendion | Thanks for clarifying that, I think that approach should work for my use case. | 00:55:25 |