Comments (5)
This is my flake.nix
for a rust project I am currently working on.
{
inputs = {
utils.url = "github:numtide/flake-utils";
naersk.url = "github:nmattia/naersk";
fenix.url = "github:nix-community/fenix";
};
outputs = { self, nixpkgs, utils, naersk, fenix }:
utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages."${system}";
# Specify Rust Toolchain
# Use Stable (Default)
# naersk-lib = naersk.lib."${system}";
# Use Nightly (provided by fenix)
naersk-lib = naersk.lib."${system}".override {
# Use Fenix to get nightly rust
inherit (fenix.packages.${system}.minimal) cargo rustc;
};
in rec {
# `nix build`
packages.nixman = naersk-lib.buildPackage {
pname = "nixman";
root = ./.;
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs = with pkgs; [
ncurses
openssl
];
};
defaultPackage = packages.nixman;
# `nix run`
apps.nixman = utils.lib.mkApp {
drv = packages.nixman;
};
defaultApp = apps.nixman;
# `nix develop`
devShell = pkgs.mkShell {
nativeBuildInputs = packages.nixman.nativeBuildInputs;
buildInputs = packages.nixman.buildInputs;
};
});
}
from nix-env-selector.
The way I personally use nix for development envs is rather basic but it may suffice for basic documentation.
I only install the language binaries and tooling via nix and then let the languages own build system (cargo, npm, maven) handle building the actual project.
I think for development environments this is an ok practice.
Here's a basic template for an elm development environment.
let
# pin nixpkgs to a particular commit
nixpkgsRev = "e924a8823325472a42c06bb519cc59d4c8bda614";
# a nix function to fetch a tar ball from github
githubTarball = owner: repo: rev:
builtins.fetchTarball { url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; };
# import set of packages from nixpkgs github repo at a particular revision with the config specified below
pkgs = import (githubTarball "nixos" "nixpkgs" nixpkgsRev) { };
in
{
inherit pkgs;
shell = pkgs.mkShell {
name = "elm-dev";
buildInputs = [
pkgs.elmPackages.elm
pkgs.elmPackages.elm-format
pkgs.elmPackages.elm-test
pkgs.nodejs-15_x
];
shellHook = ''
echo "start using elm"
'';
};
}
Here's one for an old node js project
let
nixpkgsRev = "1d55adbce8af68fee04f42b562f5376be5a6026c";
githubTarball = owner: repo: rev:
builtins.fetchTarball { url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; };
pkgs = import (githubTarball "nixos" "nixpkgs" nixpkgsRev) { };
in
with pkgs;{
shell = mkShell {
name = "dev env";
buildInputs = [
nodejs-10_x
(yarn.override { nodejs = nodejs-10_x; })
libpng12
];
LD_LIBRARY_PATH="${pkgs.libpng12}/lib";
shellHook = ''
echo "Start working";
echo "Run yarn serve to run the app";
'';
};
}
Mostly the template remains the same except for buildInputs which contains different tools for the language
from nix-env-selector.
@aszenz Awesome! Thank you for sharing.
from nix-env-selector.
There you go, I use flakes with the following flakes.nix
for a haskell project:
{
description = "Package build for gstreamer project";
inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, haskellNix, nixpkgs, flake-utils }:
flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system:
let
overlays = [ haskellNix.overlay
(final: prev: {
# This overlay adds our project to pkgs
streamlineProject =
final.haskell-nix.project' {
src = ./.;
compiler-nix-name = "ghc8104";
# projectFileName = "stack.yaml";
modules = [{
# Replace `extra-libraries` dependencies
packages.cuda.components.library.libs = pkgs.lib.mkForce
[ pkgs.cudatoolkit_10_2 ];
packages.cuda.components.library.pkgconfig = pkgs.lib.mkForce
[ [ pkgs.cudatoolkit_10_2 ] ];
}];
};
# Maps haskell library names to nixpkgs library names
"gstreamer-1.0" = pkgs.gst_all_1.gstreamer;
"gstreamer-plugins-bad-1.0" = pkgs.gst_all_1.gst-plugins-bad;
"gstreamer-plugins-good-1.0" = pkgs.gst_all_1.gst-plugins-good;
"gstreamer-plugins-base-1.0" = pkgs.gst_all_1.gst-plugins-base;
cuda = prev.cudatoolkit_10_2;
})
];
pkgs = import nixpkgs { inherit system overlays; config.allowUnfree = true; };
flake = pkgs.streamlineProject.flake {};
in flake // {
# Built by `nix build .`
defaultPackage = flake.packages."streamline:exe:streamline";
# This is used by `nix develop .` to open a shell for use with
# `cabal`, `hlint` and `haskell-language-server`
devShell = pkgs.streamlineProject.shellFor {
tools = {
cabal = "latest";
ghcid = "latest";
hlint = "latest";
haskell-language-server = "latest";
};
};
});
}
UPDATE: This works with a shell.nix
compatibility layer as described here: #53
from nix-env-selector.
I use https://github.com/yusdacra/nix-cargo-integration in my projects. How it looks in one of my Rust projects' flake.nix
:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixCargoIntegration = {
url = "github:yusdacra/nix-cargo-integration";
inputs.nixpkgs.follows = "nixpkgs";
};
flakeCompat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = inputs: inputs.nixCargoIntegration.lib.makeOutputs {
root = ./.;
buildPlatform = "crate2nix";
overrides = {
shell = common: prev: {
packages = prev.packages ++ [ common.pkgs.musl.dev ];
commands = prev.commands ++ [
{
name = "generate-cert";
command = ''
mkcert localhost 127.0.0.1 ::1
mv localhost+2.pem cert.pem
mv localhost+2-key.pem key.pem
'';
}
{
name = "run-with-console";
command = ''RUSTFLAGS="--cfg tokio_unstable" cargo r --features console'';
}
];
};
};
};
}
from nix-env-selector.
Related Issues (20)
- Stuck applying environment HOT 12
- Rustup packages as settings packages HOT 3
- Have the extension output logs in the Output window HOT 4
- Can't make my fhs env work HOT 1
- shell.nix exetubables don't seem to be made available after selecting shell.nix HOT 1
- [Feature]: Support shell.nix files outside of the project directory
- [BUG] Extension don't add package to PATH variable, when some active tabs need any package from shell.nix HOT 4
- "command 'nixEnvSelector.selectEnv' not found" HOT 1
- [Feature]: Support multiroot workspace HOT 2
- C/C++ Support: Can this be used to help generate the c_cpp_properties.json configuration file?
- [Documentation]: Document what `Hit environment` means
- [Feature]: Remember nix environment answer
- [Feature]: VSCode-Remote (SSH) support? HOT 6
- No longer applies shell.nix to integrated terminal? HOT 2
- Extension Development Host does not launch
- Can find packages from nix-shell, but not with nix-env-selector HOT 3
- TypeError when applying nix environment in Remote SSH HOT 3
- [Feature]: VSCodium support HOT 1
- Latest Pylance update brakes python environment HOT 1
- nix-env-selector does not work with flakes HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nix-env-selector.