Hi! Struggling a bit with some Nix syntax, and I am not able to properly figure it after lots of googling.
I have a derivation ihp-build.nix
looking like this:
{ stdenv, pkgs, ... }:
stdenv.mkDerivation rec {
name = "blog";
src = /home/lillo/kode/ihp-test;
buildInputs = [ ];
buildPhase = ''
nix-shell - -run "make build/bin/RunUnoptimizedProdServer"
nix-shell - -run "make static/prod.css static/prod.js"
'';
installPhase = ''
mkdir - p $out
cp -rv $src/* $out
'';
shellHook = ''set - o allexport; source .env; set +o allexport'';
}
I want to run a systemd process and access a build script that will exist in the $out
folder of the derivation above and treat it like a set.
Here is the initial configuration, where I optimisticly want to just get ${ihpApp.out}
, even though I understand it’s not the way. But I suppose this is in some way possible?
{ config, lib, pkgs, stdenv, ... }:
let
ihpApp = import ./ihp-build.nix;
in
{
systemd.services.ship = {
description = "IHP server on ship-nix";
enable = true;
after = [ "network.target" "postgresql.service" ];
wantedBy = [ "multi-user.target" ];
environment = {
DATABASE_URL = "postgres://lillo:userpassword@localhost:5432/ship";
SYSTEMD_LOG_LEVEL = "debug";
};
serviceConfig = {
Type = "exec";
WorkingDirectory = /home/lillo/kode/ihp-test;
User = "lillo";
ExecStart = ''
${ihpApp.src}/build/bin/RunProdServer
'';
};
};
}
This gets me the error message:
building the system configuration...
error: value is a function while a set was expected
at /nix/store/bvf99a2npxhn2zjz24j6n7hx01iqin2b-source/ihp-test.nix:70:11:
69| ExecStart = ''
70| ${ihpApp.src}/build/bin/RunProdServer
| ^
71| '';
So I think I get what I need to unblock myself next.
So I try to add pkgs
and stdenv
as arguments to the import statement to hopefully be able to access the derivation as a set.
{ config, lib, pkgs, stdenv, ... }:
let
ihpApp = import ./ihp-build.nix { inherit pkgs stdenv; };
in
It appears logical to me that the top statement exposes pkgs and stdenv, so I am not getting why I can’t pass these attributes to the ihpApp
value.
But I’m then getting stuck on this error message:
building the system configuration...
error: attribute 'stdenv' missing
at /nix/store/9dmig1pv9njj5kswvs8yvw3qp6b81zkd-source/lib/modules.nix:365:28:
364| builtins.addErrorContext (context name)
365| (args.${name} or config._module.args.${name})
| ^
366| ) (lib.functionArgs f);
(use '--show-trace' to show detailed location information)
I guess the let in statement are out of scope, but how would I get in inside the scope of the let..in
? Both help for unblocking and relevant reading resources will be highly appreciated