Hi,
I’m trying to output a Nix expression to a file when building a devshell. I can accomplish this by just simply writing the expression as a string and then outputting it like so:
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
expr = ''
{ config, pkgs, ... }:
{
packages = [
pkgs.hello
];
}
'';
in
{
devShell = pkgs.mkShell {
shellHook = ''
cat <<EOT > /path/to/file.nix
${expr}
EOT
'';
};
}
);
}
However, for the sake of maintenance, it’d be nice to have my IDE apply syntax highlighting/linting to the embedded expression. Is there a way to define the above outside of a string and then convert it to a string later?