{"id":19024881,"url":"https://github.com/sonujose/nixos-dev","last_synced_at":"2025-06-14T03:05:11.892Z","repository":{"id":251579614,"uuid":"837767073","full_name":"sonujose/nixos-dev","owner":"sonujose","description":"nixos experiments and dev environment","archived":false,"fork":false,"pushed_at":"2024-08-20T14:40:22.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T19:12:42.710Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sonujose.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-04T01:04:22.000Z","updated_at":"2024-08-20T14:40:26.000Z","dependencies_parsed_at":"2024-08-06T03:25:59.955Z","dependency_job_id":"da2ecdca-0b45-4820-a201-40a7164cc2fe","html_url":"https://github.com/sonujose/nixos-dev","commit_stats":null,"previous_names":["sonujose/nixos-dev"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sonujose/nixos-dev","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonujose%2Fnixos-dev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonujose%2Fnixos-dev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonujose%2Fnixos-dev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonujose%2Fnixos-dev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sonujose","download_url":"https://codeload.github.com/sonujose/nixos-dev/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonujose%2Fnixos-dev/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259751950,"owners_count":22905966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T20:39:26.469Z","updated_at":"2025-06-14T03:05:11.834Z","avatar_url":"https://github.com/sonujose.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NixOs Experiments\n\n## Setup NixOs on Local\n\n```sh\ncurl -L https://nixos.org/nix/install | sh\nnix --version\n```\n\n### Ad hoc shell environments\n\nIn a Nix shell environment, you can immediately use any program packaged with Nix, without installing it permanently.\n\n```sh\nnix-shell -p cowsay lolcat\n\ncowsay Hello, Nix! | lolcat\n\n```\n\nRunning programs once, You can go even faster, by running any program directly:\n\n```sh\n~/Documents/sonu/nixos » nix-shell -p cowsay --run \"cowsay Nix\"                                                                                                                                                                    sonaojus@Mac01\n _____\n\u003c Nix \u003e\n -----\n        \\   ^__^\n         \\  (oo)\\_______\n            (__)\\       )\\/\\\n                ||----w |\n                ||     ||\n```\n\n### Nested shell sessions\n\nIf you need an additional program temporarily, you can run a nested Nix shell. The programs provided by the specified packages will be added to the current environment.\n\n### Towards reproducibility\nThese shell environments are very convenient, but the examples so far are not reproducible yet. Running these commands on another machine may fetch different versions of packages, depending on when Nix was installed there.\n\nWhat do we mean by reproducible? A fully reproducible example would give exactly the same results no matter when or where you run the command. The environment provided would be identical each\n\n```s\nnix-shell -p git --run \"git --version\" --pure -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/2a601aafdc5605a5133a2ca506a34a3a73377247.tar.gz\n```\n\nIf you’re done trying out Nix for now, you may want to free up some disk space occupied by the different versions of programs you downloaded by running the examples:\n\n```\nnix-collect-garbage\n```\n\n## Reproducible interpreted scripts\n\n```s\n#!/usr/bin/env nix-shell\n#! nix-shell -i bash --pure\n#! nix-shell -p bash cacert curl jq python3Packages.xmljson\n#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/2a601aafdc5605a5133a2ca506a34a3a73377247.tar.gz\n\ncurl https://github.com/NixOS/nixpkgs/releases.atom | xml2json | jq .\n```\n\nThe key point is that all the #! lines are processed by nix-shell before executing the script itself. The -I option sets the NIX_PATH before the environment is built, ensuring that the correct version of nixpkgs is used when resolving the packages listed with -p.\n\nSo, when nix-shell reads the script, it:\n\nSets the NIX_PATH with the -I option.\nFetches and evaluates the packages listed with -p from the specified nixpkgs archive URL.\nStarts a bash shell in a pure environment with the specified packages available.\n\n## Declarative shell environments with shell.nix\n\n```s\nlet\n  nixpkgs = fetchTarball \"https://github.com/NixOS/nixpkgs/tarball/nixos-24.05\";\n  pkgs = import nixpkgs { config = {}; overlays = []; };\nin\n\npkgs.mkShellNoCC {\n  packages = with pkgs; [\n    cowsay\n    lolcat\n  ];\n}\n```\n\n## Startup commands\nYou may want to run some commands before entering the shell environment. These commands can be placed in the shellHook attribute provided to mkShellNoCC.\n\nSet shellHook to output a colorful greeting:\n\n```sh\n\n let\n   nixpkgs = fetchTarball \"https://github.com/NixOS/nixpkgs/tarball/nixos-24.05\";\n   pkgs = import nixpkgs { config = {}; overlays = []; };\n in\n\n pkgs.mkShellNoCC {\n   packages = with pkgs; [\n     cowsay\n     lolcat\n   ];\n\n   GREETING = \"Hello, Nix!\";\n\n   shellHook = ''\n    echo $GREETING | cowsay | lolcat\n   '';\n }\n\n```s\n{ pkgs ? import \u003cnixpkgs\u003e {} }:\n\n```\nnix-shell\n\n### Evaluating Nix files\nUse nix-instantiate --eval to evaluate the expression in a Nix file.\n\necho 1 + 2 \u003e file.nix\nnix-instantiate --eval file.nix\n3\n\n### Attribute set\n\nAttribute sets and let expressions are used to assign names to values. Assignments are denoted by a single equal sign (=).\n\nWhenever you encounter an equal sign (=) in Nix language code:\n\nOn its left is the assigned name.\n\nOn its right is the value, delimited by a semicolon (;).\n\nAttribute set { ... }\nAn attribute set is a collection of name-value-pairs, where names must be unique.\n\nThe following example shows all primitive data types, lists, and attribute sets.\n\n## let ... in ...\nAlso known as “let expression” or “let binding”\n\nlet expressions allow assigning names to values for repeated use.\n\n```sh\nlet\n  b = a + 1;\n  a = 1;\nin\na + b\n```\n\nwith ...; ...\nThe with expression allows access to attributes without repeatedly referencing their attribute set.\n\nExample:\n```sh\nlet\n  a = {\n    x = 1;\n    y = 2;\n    z = 3;\n  };\nin\nwith a; [ x y z ]\n```\n\n[ 1 2 3 ]\nThe expression\n\nwith a; [ x y z ]\nis equivalent to\n\n[ a.x a.y a.z ]\n\n## inherit ...\ninherit is shorthand for assigning the value of a name from an existing scope to the same name in a nested scope. It is for convenience to avoid repeating the same name multiple times.\n\n## String interpolation ${ ... }\nPreviously known as “antiquotation”.\n\nThe value of a Nix expression can be inserted into a character string with the dollar-sign and braces (${ }).\n\nExample:\n```sh\nlet\n  name = \"Nix\";\nin\n\"hello ${name}\"\n```\n\n## Lookup paths\nAlso known as “angle bracket syntax”.\n\nExample:\n\n\u003cnixpkgs\u003e\n/nix/var/nix/profiles/per-user/root/channels/nixpkgs\nThe value of a lookup path is a file system path that depends on the value of builtins.nixPath.\n\nIn practice, \u003cnixpkgs\u003e points to the file system path of some revision of Nixpkgs.\n\nFor example, \u003cnixpkgs/lib\u003e points to the subdirectory lib of that file system path:\n\n\u003cnixpkgs/lib\u003e\n/nix/var/nix/profiles/per-user/root/channels/nixpkgs/lib\n\n## Functions\n\n```s\nlet\n f = x: x + 1;\n a = 1;\nin [ f a ]\n```\n\n## Multiple arguments\nAlso known as “curried functions”.\n\nNix functions take exactly one argument. Multiple arguments can be handled by nesting functions.\n\nSuch a nested function can be used like a function that takes multiple arguments, but offers additional flexibility.\n\n## Impurities\nSo far we have only covered what we call pure expressions: declaring data and transforming it with functions.\n\nIn practice, describing derivations requires observing the outside world.\n\nThere is only one impurity in the Nix language that is relevant here: reading files from the file system as build inputs\n\nBuild inputs are files that derivations refer to in order to describe how to derive new files. When run, a derivation will only have access to explicitly declared build inputs.\n\nThe only way to specify build inputs in the Nix language is explicitly with:\n\n- File system paths\n- Dedicated functions.\n\nNix and the Nix language refer to files by their content hash. If file contents are not known in advance, it’s unavoidable to read files during expression evaluation.\n\n## Paths\nWhenever a file system path is used in string interpolation, the contents of that file are copied to a special location in the file system, the Nix store, as a side effect.\n\nThe evaluated string then contains the Nix store path assigned to that file.\n\nExample:\n```sh\necho 123 \u003e data\n\"${./data}\"\n\"/nix/store/h1qj5h5n05b5dl5q4nldrqq8mdg7dhqk-data\"\n\n```\n\n## Fetchers\nFiles to be used as build inputs do not have to come from the file system.\n\nThe Nix language provides built-in impure functions to fetch files over the network during evaluation:\n\n```s\nbuiltins.fetchurl\n\nbuiltins.fetchTarball\n\nbuiltins.fetchGit\n\nbuiltins.fetchClosure\n```\nThese functions evaluate to a file system path in the Nix store.\n\nExample:\n\n```sh\nbuiltins.fetchurl \"https://github.com/NixOS/nix/archive/7c3ab5751568a0bc63430b33a5169c5e4784a0ff.tar.gz\"\n\"/nix/store/7dhgs330clj36384akg86140fqkgh8zf-7c3ab5751568a0bc63430b33a5169c5e4784a0ff.tar.gz\"\n```\n\nSome of them add extra convenience, such as automatically unpacking archives.\n\nExample:\n```sh\nbuiltins.fetchTarball \"https://github.com/NixOS/nix/archive/7c3ab5751568a0bc63430b33a5169c5e4784a0ff.tar.gz\"\n\"/nix/store/d59llm96vgis5fy231x6m7nrijs0ww36-source\"\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonujose%2Fnixos-dev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonujose%2Fnixos-dev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonujose%2Fnixos-dev/lists"}