Coder Social home page Coder Social logo

nix-shell-container's Introduction

Nix-shell-container

A nix shell running in a (thin) container

Warnings

This project is just a pretext to play with containers.

Don't expect it to work perfectly :)

Demo

demo

Use

Import this flake:

# ...
inputs.nsc.url = "github:GuilloteauQ/nix-shell-container";
# ...

(feel free to make the nixpkgs input of this flake follow yours)

Now when defining a shell use nsc.lib.mkShell

# ...
devShells.${system} = {
    myshell = nsc.lib.mkShell {
        # Your normal nix shell thingies
    };
};
# ...

By default, this function behaves like the usual mkShell.

You can activate the containerization by adding setting the argument containerize to true in the mkShell:

# ...
devShells.${system} = {
    myshell = nsc.lib.mkShell {
        containerize = true;
        # Your normal nix shell thingies
    };
};
# ...

Now running nix develop .#myshell will get you in a container with the shell environment!

(you might need to run it with sudo if the unprivileged user namespace are not available on your machine)

Pass commands

It is not possible to pass commands to the shell via nix develop .#myshell --command ... because of the way Nix manages the --command flag (see here).

The solution is to use the container shell as a package:

packages.${system} = {
    myenv = nsc.lib.mkShellContainer {
        # Your normal nix shell thingies
    };
};

To enter the container, you can run nix run .#myenv.

To execute commands in the container, you can run nix run .#myenv -- COMMAND.

Misc

The container wrapper is written in Go, and it based on the amazing talk of Liz Rice: https://www.youtube.com/watch?v=8fi7uSYlOdc

nix-shell-container's People

Contributors

guilloteauq avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.