hlb-08092025

hello-world
Login

hello-world

Part2: "Hello GNU"

Using the Nix-Shell, this part will show how to compile a simple C program that runs in the home directory.

There are other ways to do this, so why use a nix-shell ?

Nix-shell: step 1, in a src/ directory

Create a hello.c file with the following contents

#include <stdio.h>

int main() {
    printf("Hello, Gnu!\n");
    return 0;
}

step 2

Create a shell.nix file with the following contents

with import <nixpkgs> {};

mkShell {
  buildInputs = [ gcc ];
}

step 3

Run the following command

nix-shell --command 'gcc hello.c -o hello'

step 4

Test the program

./hello

And you should see:

Hello, Gnu!

Finish!


Project Files
.
├── pics
│   ├── helix.png
│   └── hello-world.png
└── src
    ├── hello
    ├── hello.c
    ├── main.fs
    └── shell.nix

This completes the presentation ... Any Questions ?