Giter Site home page Giter Site logo

nixos / nix.dev Goto Github PK

View Code? Open in Web Editor NEW
2.0K 34.0 229.0 2.02 MB

Official documentation for getting things done with Nix.

Home Page: https://nix.dev

License: Creative Commons Attribution Share Alike 4.0 International

Makefile 14.85% Python 30.52% Nix 38.63% HTML 0.68% Shell 10.76% CSS 4.56%
nix documentation nixos nixpkgs cookbook learning tutorials

nix.dev's Introduction

CI

Official documentation for getting things done with Nix.

Contributing

Content is written in MyST, a superset of CommonMark. For its syntax, see the MyST docs.

For contents and style see contribution guide.

Local preview

Run nix-shell --run devmode and open a browser at http://localhost:5500.

As you make changes your browser should auto-reload within a few seconds.

To manually test redirects:

nix-shell -p netlify-cli --run "cd result; netlify dev"

nix.dev's People

Contributors

alejandrosame avatar asymmetric avatar brianmcgee avatar brianmcgillion avatar damiencassou avatar danielsidhion avatar dependabot[bot] avatar domenkozar avatar fricklerhandwerk avatar garbas avatar ghuntley avatar github-actions[bot] avatar guillaumedesforges avatar henrik-ch avatar infinisil avatar jherland avatar jillthornhill avatar kiancm avatar lucperkins avatar mic92 avatar milibopp avatar olafklingt avatar proofconstruction avatar roberth avatar sixhobbits avatar wamirez avatar worktheclock avatar yukiisbored avatar zmitchell avatar zupo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nix.dev's Issues

Windows WSL2 doesn't support --daemon

On https://nix.dev/tutorials/install-nix.html

WSL2 (the latest version of WSL on Windows) doesn't have systemd, so I need to pass --no-daemon . I don't have a WSL install to test if that supports --daemon I'm afraid.

Seeing as WSL is intended (I think) as a single-user distro mostly anyway (each windows user gets their own linux installation), I don't think this will be a major problem.

Using fakeSha256 when updating derivations

I'm not entirely sure what the precise underlying cause is of this behavior, but I've noticed the following non-obvious gotcha when updating Nix derivations in the past:

  1. Modify a derivation somehow
    • e.g. bump a package version, either fetching a binary to patchelf, updating some Haskell dependency, etc.
  2. Forget to modify the sha256 field
    • That is to say, the valid sha256 associated with the previously working derivation remains
  3. Build the derivation
    • The derivation actually does build, leading developer to believe that their change was effective
  4. Attempt to use the derivation, observing that the result from the previously successful derivation is the one being pulled from the store

A behavioral reproduction:

  1. Clone nixpkgs and cd into the directory
    • The patches below specifically refer to the nixpkgs-unstable branch as of 13 June 2020
    • Relevant commit hash is dcb64ea42e64aaecd8e6fef65cc86245c9666818
  2. Apply the following (incorrect) patch
incorrect patch

diff --git a/pkgs/applications/misc/hello/default.nix b/pkgs/applications/misc/hello/default.nix
index 32c8c696..e3555418 100644
--- a/pkgs/applications/misc/hello/default.nix
+++ b/pkgs/applications/misc/hello/default.nix
@@ -2,7 +2,7 @@
 
 stdenv.mkDerivation rec {
   pname = "hello";
-  version = "2.10";
+  version = "2.9";
 
   src = fetchurl {
     url = "mirror://gnu/hello/${pname}-${version}.tar.gz";

  1. Run the following command and observe that the version is still 2.10
nix-shell -E '{pkgs ? import ./. {}}: pkgs.mkShell { buildInputs = [ pkgs.hello ]; }' --command 'hello --version'
  1. Drop the previous patch and apply the following (correct) patch
correct patch

diff --git a/pkgs/applications/misc/hello/default.nix b/pkgs/applications/misc/hello/default.nix
index 32c8c696..c0f60198 100644
--- a/pkgs/applications/misc/hello/default.nix
+++ b/pkgs/applications/misc/hello/default.nix
@@ -2,11 +2,11 @@
 
 stdenv.mkDerivation rec {
   pname = "hello";
-  version = "2.10";
+  version = "2.9";
 
   src = fetchurl {
     url = "mirror://gnu/hello/${pname}-${version}.tar.gz";
-    sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
+    sha256 = "19qy37gkasc4csb1d3bdiz9snn8mir2p3aj0jgzmfv0r2hi7mfzc";
   };
 
   doCheck = true;

  1. Run the following command and observe that the version is now (correctly) 2.9
nix-shell -E '{pkgs ? import ./. {}}: pkgs.mkShell { buildInputs = [ pkgs.hello ]; }' --command 'hello --version'

I think having a worked out example (like the one above) would help, but an explanation of Nix's underlying behavior here would be very nice as well.

Writing convenient unix utilities in nix

I have a conundrum! I would really appreciate some words of wisdom from nix gurus.

I am writing some data-analysis utilities that are glued together with nix and I am wondering about the best way to provide simple user-interfaces for them (e.g. from the unix shell.)

For example, I have a utility that processes profiler data files to produce textual reports (similar to perf report), and the current user-interface is like this:

$ nix-build -E '(import studio/tools/vmprofiler {}).analyze_dir(/var/run/snabb/12345/engine/vmprofile)'

but that's quite verbose and users would probably much prefer a usage like:

$ vmprofiler -i /var/run/snabb/12345/engine/vmprofile -o .

and now I am wondering how to at least partially bridge that gap so that the command-line interface won't be a barrier to adoption of the tools.

I suppose that I have at least three potential ways to make a shell script wrapper:

  • Make it use the #!nix-shell shebang to run the tools directly with the right env.
  • Make it call nix-build directly in the script (wrapper to current usage.)
  • Make it into a nix package that is installed with nix-env.

I am somewhat drawn to calling nix-build because I like the idea of copying the input data into the nix store. These tools can potentially operate on large amounts of data that requires expensive preprocessing and I'd love for nix to transparently cache this intermediate processing. So while I want to have a convenient user-interface I am also happy to have nix as a runtime dependency and to use it as effectively as possible.

Does anybody see the dilemma and have an idea for how to sort it out?

Here are a couple of the scripts I am talking about:

"The problem" is to provide command-line usage instructions that won't make people go "ugh" and also won't give up nice benefits of deep nix integration.

Incorrect (?) section about adding binary caches

In faq.rst there is a section about binary caches:

How do I add a new binary cache?
Using Nix:
$ echo "trusted-binary-caches = https://hydra.snabb.co" >> /etc/nix/nix.conf

This doesn't seem correct, because single-user Nix doesn't use /etc/nix by default (only when NIX_CONF_DIR environment variable is set to /etc/nix, tested on 1.11.15) - I'm not sure what directory it uses then.

It might make sense to add "set environment variable NIX_CONF_DIR to /etc/nix in your bashrc" to this section, but I'm not sure what other side effects in will bring.

Use poetry2nix?

I would like to demonstrate https://jupyter-sphinx.readthedocs.io , however, building it won't work "out-of-the-box" because flit is used somewhere and pypi2nix does not like that.

IMO we should avoid using pypi2nix and use poetry2nix instead as that one builds upon a common and well-functioning tool, poetry.

Of course, if this were to move into Nixpkgs we may as well use Nixpkgs' packages.

@adisbladis I suppose when PEP 517/518 is used, we need to override and set format in buildPythonPackage or does poetry2nix do this automatically?

Referencing the channel:* syntax

Hi,

I recently learned about the channel:* syntax to reference a channel without the need to specify a full URL. I used it like this

$ nix-build -I nixpkgs=channel:nixos-unstable '<nixpkgs>' -A calibre

to check if calibre builds in the nixos-unstable channel.

The Pinning Nixpkgs tutorial doesn't mention this syntax. Do you want a PR to add it?

Feedback on reproducible shells

Why might it be useful to run the bash hook every time I run the shell (I imagine it can be used as part of git workflows etc, but mentioning a 'real world' example to supplement the 'hello' demonstration would help clarify this I think

Why is the direnv command useful - I imagine developers would not need to modify their project shell.nix file that often and would probably restart the shell at least daily when they begin working on a project anyway? Or is that not a common workflow and therefore it's worth installing direnv globally on all dev machines to avoid having to restart the shell?

Github Actions tutorial

Gabriel: One nice benefit of Nix is that CI can build and cache developer environments for every project on every branch

License, CLA

The used license is more restrictive than the GPL and not even considered open source. It don't fit the ecosystem and is not compatible with the license of the nixos website.

I suggest to use the same license as the website (CC BY-SA) since the plan is to integrate the content there.

And what is the plan with the CLA? Do you want to get rich by selling the tutorials as book or add a paywall later?

I don't want to give you the copyright but share it freely with the community, so anyone could sell locally printed books if there is demand for that. That's better for the environment and more fair.

<nixpkgs>: what to do with NixOS bare machines?

That one is tricky because be design nixos-rebuild depends on $NIX_PATH.

There are a few ways forward:

a) Flakes will solve this with locking, but they are not released yet.

b) For legacy we could change nixos-rebuild to look for /etc/nixos/nixpkgs.nix and use it to import <nixpkgs>.

c) Without changing upstream, one can create a wrapper called nixos-rebuild that sets $NIX_PATH to point to a commit and calls the original nixos-rebuild command. Not ideal since it won't do the right thing on the first installation, but the second will do.

Guide on speeding up CI builds

Would be great with a guide (building on the CI with Cachix guide) that shows how to speed up CI, like minimizing rebuilds, making tests be derivations, and reducing cache fetching. This thread sparked some discussion.

Add tutorial on creating a Nix channel

It'd be nice to have a tutorial on nix.dev dedicated to both creating and consuming your own Nix channel, preferably with a kind of "progressive" logic. Maybe something along these lines:

  1. Create new channel via GitHub with a single helloWorld package (just a basic default.nix)
  2. Add the channel on the command line and build the helloWorld package (i.e. `nix-build '' -A helloWorld')
  3. Use the channel to do a real Nix build (i.e. to create a package that consumes helloWorld, maybe a Docker container or something)
  4. Update the channel to expose a pinned nixpkgs
  5. Update the channel again to include an overlay on the pinned nixpkgs
  6. Use Niv to provide pinned access to the channel.

I'd be happy to do the work, just wanted to see if others would find this helpful. And open to suggestions on content, of course.

Getting the URL of the system channel as a regular user?

How to do this? I could run:

$ sudo nix-channel --list

And add this command to sudoers.

Or set appropriate permissions for /root (701) and /root/.nix-channels (644), and read that file directly.

But both these solutions seem hacky. =)

Can't reproduce myapp Flask example

I'm following the steps in the dev-environment tutorial. I correctly get a ./result directory but:

$ ./result/bin/myapp 
Traceback (most recent call last):
  File "/nix/store/wx3vrgfya66fp5qb6bd20y1wxkhqw4sg-myapp-0.1/bin/.myapp-wrapped", line 6, in <module>
    from myapp import run
ModuleNotFoundError: No module named 'myapp'

I was expecting the application to start.

Also, the following steps don't seem to do anything:

$ nix-shell default.nix 
Sourcing python-recompile-bytecode-hook.sh
Sourcing python-remove-tests-dir-hook
Sourcing python-catch-conflicts-hook.sh
Sourcing python-remove-bin-bytecode-hook.sh
Sourcing setuptools-build-hook
Using setuptoolsBuildPhase
Using setuptoolsShellHook
Sourcing pip-install-hook
Using pipInstallPhase
Sourcing python-imports-check-hook.sh
Using pythonImportsCheckPhase
Sourcing python-namespaces-hook
Sourcing setuptools-check-hook
Using setuptoolsCheckPhase
Executing setuptoolsShellHook
Obtaining file:///tmp/flask
Installing collected packages: myapp
  Running setup.py develop for myapp
Successfully installed myapp
Finished executing setuptoolsShellHook
$ python3 main.py 
$ echo $?
0

I'm following nixos-unstable.

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.