Hi all! I am experimenting with nix flakes and adopted the following flake structure:
flake.nix:
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
};
outputs = { self, nixpkgs }@inputs:
let
inherit (self) outputs;
forAllSystems = nixpkgs.lib.genAttrs [
"aarch64-linux"
"i686-linux"
"x86_64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
in rec {
# Devshell for bootstrapping
# Acessible through 'nix develop' or 'nix-shell' (legacy)
devShells = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
import ./shell.nix { inherit pkgs; }
);
};
}
shell.nix
# Shell for bootstrapping flake-enabled nix and home-manager
# You can enter it through 'nix develop' or (legacy) 'nix-shell'
{ pkgs }: {
default = pkgs.mkShell {
nativeBuildInputs = [
pkgs.terraform
];
};
}
Say that I have a custom derivation like this:
./terraform-graph-beautifier/default.nix
{ stdenv
, lib
, go
, buildGoModule
, fetchFromGitHub
, makeWrapper
, coreutils
, runCommand
, runtimeShell
, writeText
, installShellFiles
}:
{ version, hash, vendorHash ? null, ... }:
buildGoModule rec {
pname = "terraform-graph-beautifier";
version = "0.3.3";
vendorHash = lib.fakeSha256;
src = fetchFromGitHub {
owner = "pcasteran";
repo = "terraform-graph-beautifier";
rev = "v${version}";
hash = lib.fakeSha256;
};
meta = with lib; {
description =
"Command line tool allowing to convert the barely usable output of the terraform graph command to something more meaningful and explanatory.";
homepage = "https://github.com/pcasteran/terraform-graph-beautifier";
license = licenses.apache2;
changelog = "https://github.com/pcasteran/terraform-graph-beautifier/releases/v${version}/";
...
};
}
Note: this dirivation is copied from docs, and it might also contain errors, as I have not been able to test it yet.
How do I use this as a package within shell.nix
?
I think I am just missing some fundamental part of how flakes work and can’t seem to find a good example.
I tried the following things:
- naively adding this to the
nativeBuildInputs
inshell.nix
(pkgs.callPackage ./pkgs/terraform-graph-beautifier { })
- attempted to add an custom package like this in
flake.nix
packages = forAllSystems (system:
let pkgs = nixpkgs.legacyPackages.${system};
in import ./pkgs { inherit pkgs; }
);
- serveral variations of the above two using the overlay/pkgs structure taken from GitHub - Misterio77/nix-starter-configs: Simple and documented config templates to help you get started with NixOS + home-manager + flakes. All the boilerplate you need! (great resource btw!)
If somebody could point me in the right direction, I would be very grateful!
I would be happy to contribute a working example back to the documentation, just point me where to add it.