Libgets is a CS50-like C library with Nix flakes, designed for learning C and Nix flakes.
- Add it to inputs in your flake.nix file.
inputs = {
nixpkgs.url = "nixpkgs/nixos-24.05";
libgets = {
url = "github:aldosierra/libgets";
inputs.nixpkgs.follows = "nixpkgs";
};
};
- Add it to the devShell buildInputs.
devShells = {
default = pkgs.mkShell {
name = "sample-env";
buildInputs = with pkgs; [ gcc libgets.packages."x86_64-linux".default ];
};
};
- Import it on your c file.
#include "libgets.h"
int main(void) {
char *name = GetString("What is your name? ");
printf("Hi, %s\n", name);
return 0;
}
Optionally you can add libgets to C_INCLUDE_PATH to include it on the standard system include directories, here is an example.
devShells = {
default = pkgs.mkShell {
name = "sample-env";
buildInputs = with pkgs; [ gcc libgets.packages."x86_64-linux".default ];
C_INCLUDE_PATH = "${libgets.packages.${system}.default}/include:$C_INCLUDE_PATH";
};
};
This will work with both #include <...> and #include "...".
#include <libgets.h>
int main(void) {
char *name = GetString("What is your name? ");
printf("Hi, %s\n", name);
return 0;
}
- Add a list of functions include it on this library.
- Add options parameters for format messages.
- Check for missing functions on the og cs50 library.