Skip to content

Instantly share code, notes, and snippets.

@dmacvicar
Last active May 28, 2022 20:44
Show Gist options
  • Save dmacvicar/469e8c83a33bc3954868b688b235f45e to your computer and use it in GitHub Desktop.
Save dmacvicar/469e8c83a33bc3954868b688b235f45e to your computer and use it in GitHub Desktop.
nix flakes environment
use_flake
$ nix build
$ docker load <result
Loaded image: refb/devenv:latest

$ docker run -ti refb/devenv sassc
Usage: sassc [options] [INPUT] [OUTPUT]

The cool thing is that I can use the same to just get into a shell with the same environment without docker: $ nix shell

Or automatically by entering the project directory by setting up direnv in my shell:

.envrc (for use with direnv )

use_flake

and then cd into the directory.

You can pin version too. Actually there is a flake.lock being created and you can use git to version the flake origins/custom pkgs etc. Did not went that far in this example.

{
description = "A basic flake with a shell";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
contents = with pkgs; [
bashInteractive
protobuf
sassc
];
shell = pkgs.mkShell {
buildInputs = contents;
};
docker = pkgs.dockerTools.buildImage {
name = "refb/devenv";
tag = "latest";
contents = contents;
config = {
Env = with pkgs; [ "PATH=${protobuf}/bin/:${sassc}/bin/" ];
};
};
in rec {
defaultPackage = docker;
devShell = shell;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment