├── .envrc ├── elixir ├── general │ ├── .envrc │ ├── flake.lock │ └── flake.nix ├── library │ ├── .envrc │ ├── flake.nix │ └── flake.lock └── phoenix │ ├── .envrc │ ├── nix │ ├── docker-image.nix │ ├── shell.nix │ ├── overlay.nix │ └── release.nix │ ├── flake.lock │ └── flake.nix ├── python └── general │ ├── .envrc │ ├── flake.nix │ └── flake.lock ├── README.md ├── shell └── general │ ├── flake.nix │ └── flake.lock ├── flake.lock └── flake.nix /.envrc: -------------------------------------------------------------------------------- 1 | use flake 2 | -------------------------------------------------------------------------------- /elixir/general/.envrc: -------------------------------------------------------------------------------- 1 | use flake 2 | -------------------------------------------------------------------------------- /elixir/library/.envrc: -------------------------------------------------------------------------------- 1 | use flake 2 | -------------------------------------------------------------------------------- /elixir/phoenix/.envrc: -------------------------------------------------------------------------------- 1 | use flake 2 | -------------------------------------------------------------------------------- /python/general/.envrc: -------------------------------------------------------------------------------- 1 | use flake 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nix-dev-templates 2 | 3 | A collection of Nix flake templates for development. 4 | 5 | ## Usage 6 | 7 | ```console 8 | nix flake init --template github:nix-giant/nix-dev-templates#name 9 | ``` 10 | 11 | An example: 12 | 13 | ```console 14 | nix flake init --template github:nix-giant/nix-dev-templates#elixir 15 | ``` 16 | 17 | ## Similar projects 18 | 19 | - [the-nix-way/dev-templates](https://github.com/the-nix-way/dev-templates) 20 | - [MordragT/nix-templates](https://github.com/MordragT/nix-templates) 21 | 22 | ## License 23 | 24 | MIT 25 | -------------------------------------------------------------------------------- /shell/general/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Shell development environment"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs"; 6 | flake-utils.url = "github:numtide/flake-utils"; 7 | }; 8 | 9 | outputs = 10 | { 11 | self, 12 | nixpkgs, 13 | flake-utils, 14 | ... 15 | }: 16 | flake-utils.lib.eachDefaultSystem ( 17 | system: 18 | let 19 | pkgs = import nixpkgs { inherit system; }; 20 | in 21 | { 22 | devShells.default = with pkgs; mkShell { packages = [ bash ]; }; 23 | } 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1724282355, 6 | "narHash": "sha256-Dd2quv2bDzwrNuMoFZh1WOU4d409vWe7HwhbJMk7rsA=", 7 | "owner": "NixOS", 8 | "repo": "nixpkgs", 9 | "rev": "e088f57f278e170fa7ff2a8c9a8689fe4987e612", 10 | "type": "github" 11 | }, 12 | "original": { 13 | "owner": "NixOS", 14 | "ref": "release-24.05", 15 | "repo": "nixpkgs", 16 | "type": "github" 17 | } 18 | }, 19 | "root": { 20 | "inputs": { 21 | "nixpkgs": "nixpkgs" 22 | } 23 | } 24 | }, 25 | "root": "root", 26 | "version": 7 27 | } 28 | -------------------------------------------------------------------------------- /python/general/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Python development environment"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs"; 6 | flake-utils.url = "github:numtide/flake-utils"; 7 | }; 8 | 9 | outputs = 10 | { 11 | self, 12 | nixpkgs, 13 | flake-utils, 14 | ... 15 | }: 16 | flake-utils.lib.eachDefaultSystem ( 17 | system: 18 | let 19 | pkgs = import nixpkgs { inherit system; }; 20 | in 21 | { 22 | devShells.default = 23 | with pkgs; 24 | mkShell { 25 | packages = [ 26 | python3 27 | poetry 28 | ]; 29 | }; 30 | } 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /elixir/phoenix/nix/docker-image.nix: -------------------------------------------------------------------------------- 1 | { 2 | nixpkgs, 3 | release, 4 | hostSystem, 5 | dockerTools, 6 | glibcLocalesUtf8, 7 | coreutils, 8 | curl, 9 | ... 10 | }: 11 | let 12 | hostPkgs = import nixpkgs { system = hostSystem; }; 13 | name = release.pname; 14 | in 15 | (dockerTools.override { writePython3 = hostPkgs.buildPackages.writers.writePython3; }) 16 | .streamLayeredImage 17 | { 18 | inherit name; 19 | tag = "latest"; 20 | 21 | contents = [ 22 | dockerTools.caCertificates 23 | dockerTools.binSh 24 | 25 | coreutils 26 | 27 | # healthcheck related packages 28 | curl 29 | ]; 30 | 31 | config = { 32 | Env = [ 33 | "LOCALE_ARCHIVE=${glibcLocalesUtf8}/lib/locale/locale-archive" 34 | "LC_ALL=en_US.UTF-8" 35 | "TERM=vt100" 36 | ]; 37 | WorkingDir = release; 38 | Cmd = [ 39 | "${release}/bin/server" 40 | "start" 41 | ]; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /elixir/library/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Elixir development environment for library"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs"; 6 | flake-utils.url = "github:numtide/flake-utils"; 7 | }; 8 | 9 | outputs = 10 | { 11 | self, 12 | nixpkgs, 13 | flake-utils, 14 | }: 15 | flake-utils.lib.eachDefaultSystem ( 16 | system: 17 | let 18 | pkgs = import nixpkgs { inherit system; }; 19 | in 20 | { 21 | devShells.default = 22 | with pkgs; 23 | mkShell { 24 | packages = [ beam.packages.erlang_26.elixir_1_15 ]; 25 | 26 | shellHook = '' 27 | # limit mix to current project 28 | mkdir -p .nix-mix 29 | export MIX_HOME=$PWD/.nix-mix 30 | export PATH=$MIX_HOME/bin:$PATH 31 | export PATH=$MIX_HOME/escripts:$PATH 32 | 33 | # limit history to current project 34 | export ERL_AFLAGS="-kernel shell_history enabled -kernel shell_history_path '\"$PWD/.erlang-history\"'" 35 | ''; 36 | }; 37 | } 38 | ); 39 | } 40 | -------------------------------------------------------------------------------- /elixir/phoenix/nix/shell.nix: -------------------------------------------------------------------------------- 1 | { 2 | stdenv, 3 | lib, 4 | mkShell, 5 | myEnv, 6 | libnotify, 7 | inotify-tools, 8 | terminal-notifier, 9 | apple-sdk, 10 | ... 11 | }: 12 | mkShell { 13 | packages = [ 14 | myEnv.beamPackages.erlang 15 | myEnv.beamPackages.elixir 16 | myEnv.nodePackages.nodejs 17 | ] 18 | ++ 19 | # Linux only 20 | lib.optionals stdenv.isLinux [ 21 | # for ExUnit notifier 22 | libnotify 23 | 24 | # for package - file_system 25 | inotify-tools 26 | ] 27 | ++ 28 | # Darwin only 29 | lib.optionals stdenv.isDarwin [ 30 | # for ExUnit notifier 31 | terminal-notifier 32 | 33 | # for package - file_system 34 | apple-sdk 35 | ]; 36 | 37 | shellHook = '' 38 | # limit mix to current project 39 | mkdir -p .nix-mix 40 | export MIX_HOME=$PWD/.nix-mix 41 | export PATH=$MIX_HOME/bin:$PATH 42 | export PATH=$MIX_HOME/escripts:$PATH 43 | 44 | # limit hex to current project 45 | mkdir -p .nix-hex 46 | export HEX_HOME=$PWD/.nix-hex 47 | export ERL_LIBS=$HEX_HOME/lib/erlang/lib 48 | export PATH=$HEX_HOME/bin:$PATH 49 | 50 | # limit history to current project 51 | export ERL_AFLAGS="-kernel shell_history enabled -kernel shell_history_path '\"$PWD/.erlang-history\"'" 52 | ''; 53 | } 54 | -------------------------------------------------------------------------------- /elixir/general/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-utils": { 4 | "inputs": { 5 | "systems": "systems" 6 | }, 7 | "locked": { 8 | "lastModified": 1710146030, 9 | "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", 10 | "owner": "numtide", 11 | "repo": "flake-utils", 12 | "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "numtide", 17 | "repo": "flake-utils", 18 | "type": "github" 19 | } 20 | }, 21 | "nixpkgs": { 22 | "locked": { 23 | "lastModified": 1724292855, 24 | "narHash": "sha256-C/mr8i+5vDwgC5K5UhG5ruGUxyoonTam5QcABXamaHU=", 25 | "owner": "NixOS", 26 | "repo": "nixpkgs", 27 | "rev": "f6d65d2d63588777c5d869707efcf71c3f382e18", 28 | "type": "github" 29 | }, 30 | "original": { 31 | "owner": "NixOS", 32 | "repo": "nixpkgs", 33 | "type": "github" 34 | } 35 | }, 36 | "root": { 37 | "inputs": { 38 | "flake-utils": "flake-utils", 39 | "nixpkgs": "nixpkgs" 40 | } 41 | }, 42 | "systems": { 43 | "locked": { 44 | "lastModified": 1681028828, 45 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 46 | "owner": "nix-systems", 47 | "repo": "default", 48 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 49 | "type": "github" 50 | }, 51 | "original": { 52 | "owner": "nix-systems", 53 | "repo": "default", 54 | "type": "github" 55 | } 56 | } 57 | }, 58 | "root": "root", 59 | "version": 7 60 | } 61 | -------------------------------------------------------------------------------- /elixir/library/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-utils": { 4 | "inputs": { 5 | "systems": "systems" 6 | }, 7 | "locked": { 8 | "lastModified": 1710146030, 9 | "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", 10 | "owner": "numtide", 11 | "repo": "flake-utils", 12 | "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "numtide", 17 | "repo": "flake-utils", 18 | "type": "github" 19 | } 20 | }, 21 | "nixpkgs": { 22 | "locked": { 23 | "lastModified": 1724292855, 24 | "narHash": "sha256-C/mr8i+5vDwgC5K5UhG5ruGUxyoonTam5QcABXamaHU=", 25 | "owner": "NixOS", 26 | "repo": "nixpkgs", 27 | "rev": "f6d65d2d63588777c5d869707efcf71c3f382e18", 28 | "type": "github" 29 | }, 30 | "original": { 31 | "owner": "NixOS", 32 | "repo": "nixpkgs", 33 | "type": "github" 34 | } 35 | }, 36 | "root": { 37 | "inputs": { 38 | "flake-utils": "flake-utils", 39 | "nixpkgs": "nixpkgs" 40 | } 41 | }, 42 | "systems": { 43 | "locked": { 44 | "lastModified": 1681028828, 45 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 46 | "owner": "nix-systems", 47 | "repo": "default", 48 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 49 | "type": "github" 50 | }, 51 | "original": { 52 | "owner": "nix-systems", 53 | "repo": "default", 54 | "type": "github" 55 | } 56 | } 57 | }, 58 | "root": "root", 59 | "version": 7 60 | } 61 | -------------------------------------------------------------------------------- /python/general/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-utils": { 4 | "inputs": { 5 | "systems": "systems" 6 | }, 7 | "locked": { 8 | "lastModified": 1710146030, 9 | "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", 10 | "owner": "numtide", 11 | "repo": "flake-utils", 12 | "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "numtide", 17 | "repo": "flake-utils", 18 | "type": "github" 19 | } 20 | }, 21 | "nixpkgs": { 22 | "locked": { 23 | "lastModified": 1724292855, 24 | "narHash": "sha256-C/mr8i+5vDwgC5K5UhG5ruGUxyoonTam5QcABXamaHU=", 25 | "owner": "NixOS", 26 | "repo": "nixpkgs", 27 | "rev": "f6d65d2d63588777c5d869707efcf71c3f382e18", 28 | "type": "github" 29 | }, 30 | "original": { 31 | "owner": "NixOS", 32 | "repo": "nixpkgs", 33 | "type": "github" 34 | } 35 | }, 36 | "root": { 37 | "inputs": { 38 | "flake-utils": "flake-utils", 39 | "nixpkgs": "nixpkgs" 40 | } 41 | }, 42 | "systems": { 43 | "locked": { 44 | "lastModified": 1681028828, 45 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 46 | "owner": "nix-systems", 47 | "repo": "default", 48 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 49 | "type": "github" 50 | }, 51 | "original": { 52 | "owner": "nix-systems", 53 | "repo": "default", 54 | "type": "github" 55 | } 56 | } 57 | }, 58 | "root": "root", 59 | "version": 7 60 | } 61 | -------------------------------------------------------------------------------- /shell/general/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-utils": { 4 | "inputs": { 5 | "systems": "systems" 6 | }, 7 | "locked": { 8 | "lastModified": 1710146030, 9 | "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", 10 | "owner": "numtide", 11 | "repo": "flake-utils", 12 | "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "numtide", 17 | "repo": "flake-utils", 18 | "type": "github" 19 | } 20 | }, 21 | "nixpkgs": { 22 | "locked": { 23 | "lastModified": 1724292855, 24 | "narHash": "sha256-C/mr8i+5vDwgC5K5UhG5ruGUxyoonTam5QcABXamaHU=", 25 | "owner": "NixOS", 26 | "repo": "nixpkgs", 27 | "rev": "f6d65d2d63588777c5d869707efcf71c3f382e18", 28 | "type": "github" 29 | }, 30 | "original": { 31 | "owner": "NixOS", 32 | "repo": "nixpkgs", 33 | "type": "github" 34 | } 35 | }, 36 | "root": { 37 | "inputs": { 38 | "flake-utils": "flake-utils", 39 | "nixpkgs": "nixpkgs" 40 | } 41 | }, 42 | "systems": { 43 | "locked": { 44 | "lastModified": 1681028828, 45 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 46 | "owner": "nix-systems", 47 | "repo": "default", 48 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 49 | "type": "github" 50 | }, 51 | "original": { 52 | "owner": "nix-systems", 53 | "repo": "default", 54 | "type": "github" 55 | } 56 | } 57 | }, 58 | "root": "root", 59 | "version": 7 60 | } 61 | -------------------------------------------------------------------------------- /elixir/general/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Elixir development environment"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs"; 6 | flake-utils.url = "github:numtide/flake-utils"; 7 | }; 8 | 9 | outputs = 10 | { 11 | self, 12 | nixpkgs, 13 | flake-utils, 14 | }: 15 | flake-utils.lib.eachDefaultSystem ( 16 | system: 17 | let 18 | pkgs = import nixpkgs { inherit system; }; 19 | in 20 | { 21 | devShells.default = 22 | with pkgs; 23 | mkShell { 24 | packages = [ 25 | beam.packages.erlang_26.elixir_1_15 26 | ] 27 | ++ 28 | # Linux only 29 | lib.optionals stdenv.isLinux [ 30 | # for ExUnit notifier 31 | libnotify 32 | 33 | # for package - file_system 34 | inotify-tools 35 | ] 36 | ++ 37 | # Darwin only 38 | lib.optionals stdenv.isDarwin [ 39 | # for ExUnit notifier 40 | terminal-notifier 41 | 42 | # for package - file_system 43 | apple-sdk 44 | ]; 45 | 46 | shellHook = '' 47 | # limit mix to current project 48 | mkdir -p .nix-mix 49 | export MIX_HOME=$PWD/.nix-mix 50 | export PATH=$MIX_HOME/bin:$PATH 51 | export PATH=$MIX_HOME/escripts:$PATH 52 | 53 | # limit history to current project 54 | export ERL_AFLAGS="-kernel shell_history enabled -kernel shell_history_path '\"$PWD/.erlang-history\"'" 55 | ''; 56 | }; 57 | } 58 | ); 59 | } 60 | -------------------------------------------------------------------------------- /elixir/phoenix/nix/overlay.nix: -------------------------------------------------------------------------------- 1 | _final: prev: 2 | let 3 | pkgs = prev; 4 | 5 | buildBeamPackages = 6 | scope: 7 | let 8 | beamPackages = with scope; packagesWith interpreters.erlang_27; 9 | 10 | erlang = beamPackages.erlang; 11 | elixir = beamPackages.elixir_1_17; 12 | 13 | fetchMixDeps = pkgs.beamUtils.fetchMixDeps.override { inherit elixir; }; 14 | buildMixRelease = pkgs.beamUtils.buildMixRelease.override { inherit erlang elixir; }; 15 | in 16 | { 17 | inherit 18 | erlang 19 | elixir 20 | fetchMixDeps 21 | buildMixRelease 22 | ; 23 | }; 24 | 25 | buildNodePackages = scope: rec { 26 | nodejs = scope.nodejs_20; 27 | 28 | fetchNpmDeps = 29 | { 30 | pname, 31 | version, 32 | src, 33 | hash, 34 | postBuild ? "", 35 | }: 36 | let 37 | inherit (scope) stdenv buildPackages fetchNpmDeps; 38 | npmHooks = buildPackages.npmHooks.override { inherit nodejs; }; 39 | in 40 | stdenv.mkDerivation { 41 | name = "${pname}-${version}"; 42 | inherit src; 43 | npmDeps = fetchNpmDeps { 44 | name = "${pname}-cache-${version}"; 45 | inherit src hash; 46 | }; 47 | nativeBuildInputs = [ 48 | nodejs 49 | npmHooks.npmConfigHook 50 | ]; 51 | postBuild = postBuild; 52 | installPhase = '' 53 | mkdir -p "$out" 54 | cp -r package.json package-lock.json node_modules "$out" 55 | ''; 56 | }; 57 | }; 58 | in 59 | rec { 60 | myEnv = { 61 | beamPackages = (buildBeamPackages pkgs.beam) // { 62 | minimal = buildBeamPackages pkgs.beam_minimal; 63 | }; 64 | nodePackages = buildNodePackages pkgs; 65 | }; 66 | 67 | myCallPackage = pkgs.lib.callPackageWith (pkgs // { inherit myEnv; }); 68 | } 69 | -------------------------------------------------------------------------------- /elixir/phoenix/nix/release.nix: -------------------------------------------------------------------------------- 1 | { 2 | self, 3 | lib, 4 | myEnv, 5 | nix-gitignore, 6 | ... 7 | }: 8 | let 9 | # TODO: adjust pname, version and src 10 | pname = "example"; 11 | version = "0.1.0"; 12 | src = nix-gitignore.gitignoreSource [ 13 | "/flake.nix" 14 | "/flake.lock" 15 | # TODO: add extra patterns besides ones specified by .gitignore, such as /fly.toml 16 | ] ../.; 17 | 18 | inherit (myEnv.beamPackages.minimal) fetchMixDeps buildMixRelease; 19 | inherit (myEnv.nodePackages) nodejs fetchNpmDeps; 20 | 21 | mixDeps = fetchMixDeps { 22 | pname = "${pname}-mix-deps"; 23 | inherit version src; 24 | # TODO: replace fake hash 25 | hash = lib.fakeHash; 26 | }; 27 | 28 | npmDeps = fetchNpmDeps { 29 | pname = "${pname}-npm-deps"; 30 | inherit version; 31 | src = "${src}/assets"; 32 | # TODO: replace fake hash 33 | hash = lib.fakeHash; 34 | postBuild = '' 35 | # fix broken local packages 36 | local_packages=( 37 | "phoenix" 38 | "phoenix_html" 39 | "phoenix_live_view" 40 | ) 41 | for package in ''\${local_packages[@]}; do 42 | path=node_modules/$package 43 | if [[ -L $path ]]; then 44 | echo "fixing local package - $package" 45 | rm $path 46 | cp -r ${mixDeps}/deps/$package node_modules/ 47 | fi 48 | done 49 | ''; 50 | }; 51 | in 52 | buildMixRelease { 53 | inherit pname version src; 54 | 55 | inherit mixDeps; 56 | nativeBuildInputs = [ nodejs ]; 57 | 58 | removeCookie = false; 59 | 60 | preBuild = lib.concatStringsSep "\n" [ 61 | # create a fake .git for the access of current commit hash via `git rev-parse HEAD` 62 | ( 63 | let 64 | rev = if self ? rev then self.rev else throw "Refusing to build a release from a dirty Git tree."; 65 | in 66 | '' 67 | mkdir -p .git 68 | mkdir -p .git/objects 69 | mkdir -p .git/refs 70 | echo "${rev}" > .git/HEAD 71 | '' 72 | ) 73 | 74 | # link node_modules 75 | '' 76 | ln -s ${npmDeps}/node_modules assets/node_modules 77 | '' 78 | ]; 79 | 80 | postBuild = '' 81 | HOME=$(pwd) mix assets.deploy 82 | ''; 83 | } 84 | -------------------------------------------------------------------------------- /elixir/phoenix/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "beam-utils": { 4 | "inputs": { 5 | "flake-utils": [ 6 | "flake-utils" 7 | ], 8 | "nixpkgs": [ 9 | "nixpkgs" 10 | ] 11 | }, 12 | "locked": { 13 | "lastModified": 1706528755, 14 | "narHash": "sha256-pz9h5si4AWyX+MqGNr1mw02qLA0D+7qtmYPzk+KnQcc=", 15 | "owner": "nix-giant", 16 | "repo": "beam-utils", 17 | "rev": "f18fc4d3c35b8a29b07cb27a35b257f39d212367", 18 | "type": "github" 19 | }, 20 | "original": { 21 | "owner": "nix-giant", 22 | "repo": "beam-utils", 23 | "type": "github" 24 | } 25 | }, 26 | "flake-utils": { 27 | "inputs": { 28 | "systems": "systems" 29 | }, 30 | "locked": { 31 | "lastModified": 1710146030, 32 | "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", 33 | "owner": "numtide", 34 | "repo": "flake-utils", 35 | "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", 36 | "type": "github" 37 | }, 38 | "original": { 39 | "owner": "numtide", 40 | "repo": "flake-utils", 41 | "type": "github" 42 | } 43 | }, 44 | "nixpkgs": { 45 | "locked": { 46 | "lastModified": 1724292855, 47 | "narHash": "sha256-C/mr8i+5vDwgC5K5UhG5ruGUxyoonTam5QcABXamaHU=", 48 | "owner": "NixOS", 49 | "repo": "nixpkgs", 50 | "rev": "f6d65d2d63588777c5d869707efcf71c3f382e18", 51 | "type": "github" 52 | }, 53 | "original": { 54 | "owner": "NixOS", 55 | "repo": "nixpkgs", 56 | "type": "github" 57 | } 58 | }, 59 | "root": { 60 | "inputs": { 61 | "beam-utils": "beam-utils", 62 | "flake-utils": "flake-utils", 63 | "nixpkgs": "nixpkgs" 64 | } 65 | }, 66 | "systems": { 67 | "locked": { 68 | "lastModified": 1681028828, 69 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 70 | "owner": "nix-systems", 71 | "repo": "default", 72 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 73 | "type": "github" 74 | }, 75 | "original": { 76 | "owner": "nix-systems", 77 | "repo": "default", 78 | "type": "github" 79 | } 80 | } 81 | }, 82 | "root": "root", 83 | "version": 7 84 | } 85 | -------------------------------------------------------------------------------- /elixir/phoenix/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Elixir development environment for Phoenix project"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs"; 6 | flake-utils.url = "github:numtide/flake-utils"; 7 | beam-utils = { 8 | url = "github:nix-giant/beam-utils"; 9 | inputs.nixpkgs.follows = "nixpkgs"; 10 | inputs.flake-utils.follows = "flake-utils"; 11 | }; 12 | }; 13 | 14 | outputs = 15 | { 16 | self, 17 | nixpkgs, 18 | flake-utils, 19 | beam-utils, 20 | ... 21 | }@inputs: 22 | flake-utils.lib.eachDefaultSystem ( 23 | system: 24 | let 25 | pkgs = import nixpkgs { 26 | inherit system; 27 | overlays = [ 28 | beam-utils.overlays.default 29 | (import ./nix/overlay.nix) 30 | ]; 31 | }; 32 | in 33 | { 34 | devShells = { 35 | default = pkgs.myCallPackage ./nix/shell.nix { }; 36 | }; 37 | 38 | # # Overview 39 | # 40 | # To get an overview of all available packages, run: 41 | # 42 | # $ nix flake show 43 | # 44 | # You'll see `release` and something like `docker-image-triggered-by-`. 45 | # 46 | # # Examples 47 | # 48 | # To build a `x86_64-linux` release or a `x86_64-linux` docker image, run: 49 | # 50 | # $ nix build '.#packages.x86_64-linux.release' 51 | # $ nix build '.#packages.x86_64-linux.docker-image-triggered-by-x86_64-linux' 52 | # 53 | # To build a `x86_64-linux` docker image on different platform (let's say `aarch64-darwin`), run: 54 | # 55 | # $ nix build '.#packages.x86_64-linux.docker-image-triggered-by-aarch64-darwin' 56 | # 57 | packages = 58 | let 59 | release = pkgs.myCallPackage ./nix/release.nix ({ } // inputs); 60 | 61 | buildDockerImage = 62 | hostSystem: pkgs.myCallPackage ./nix/docker-image.nix ({ inherit release hostSystem; } // inputs); 63 | 64 | docker-images = builtins.listToAttrs ( 65 | map (hostSystem: { 66 | name = "docker-image-triggered-by-${hostSystem}"; 67 | value = buildDockerImage hostSystem; 68 | }) flake-utils.lib.defaultSystems 69 | ); 70 | in 71 | { inherit release; } // docker-images; 72 | } 73 | ); 74 | } 75 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "A collection of Nix flake templates for development."; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs/release-24.05"; 6 | }; 7 | 8 | outputs = 9 | { self, nixpkgs }: 10 | let 11 | overlays = [ 12 | ( 13 | final: prev: 14 | let 15 | pkgs = prev; 16 | exec = pkg: "${prev.${pkg}}/bin/${pkg}"; 17 | in 18 | { 19 | format = prev.writeScriptBin "format" '' 20 | ${pkgs.nixfmt-rfc-style}/bin/nixfmt * 21 | ''; 22 | update = prev.writeScriptBin "update" '' 23 | for dir in `ls -d */*`; do # Iterate through all the templates 24 | ( 25 | cd $dir 26 | ${exec "nix"} flake update # Update flake.lock 27 | ${exec "nix"} flake check # Make sure things work after the update 28 | ) 29 | done 30 | ''; 31 | dvt = prev.writeScriptBin "dvt" '' 32 | if [ -z $1 ]; then 33 | echo "no template specified" 34 | exit 1 35 | fi 36 | 37 | TEMPLATE=$1 38 | 39 | ${exec "nix"} \ 40 | --experimental-features 'nix-command flakes' \ 41 | flake init \ 42 | --template \ 43 | "github:c4710n/nix-dev-templates#''${TEMPLATE}" 44 | ''; 45 | } 46 | ) 47 | ]; 48 | 49 | supportedSystems = [ 50 | "x86_64-linux" 51 | "aarch64-linux" 52 | "x86_64-darwin" 53 | "aarch64-darwin" 54 | ]; 55 | forEachSupportedSystem = 56 | f: 57 | nixpkgs.lib.genAttrs supportedSystems ( 58 | system: f { pkgs = import nixpkgs { inherit system overlays; }; } 59 | ); 60 | in 61 | { 62 | devShells = forEachSupportedSystem ( 63 | { pkgs }: 64 | { 65 | default = pkgs.mkShell { 66 | packages = with pkgs; [ 67 | format 68 | update 69 | ]; 70 | }; 71 | } 72 | ); 73 | 74 | packages = forEachSupportedSystem ( 75 | { pkgs }: 76 | rec { 77 | default = dvt; 78 | inherit (pkgs) dvt; 79 | } 80 | ); 81 | 82 | } 83 | 84 | // 85 | 86 | { 87 | templates = { 88 | shell = { 89 | path = ./shell/general; 90 | description = "Shell development environment"; 91 | }; 92 | 93 | elixir = { 94 | path = ./elixir/general; 95 | description = "Elixir development environment"; 96 | }; 97 | 98 | elixir-library = { 99 | path = ./elixir/library; 100 | description = "Elixir development environment for library"; 101 | }; 102 | 103 | elixir-phoenix = { 104 | path = ./elixir/phoenix; 105 | description = "Elixir development environment for Phoenix project"; 106 | }; 107 | 108 | python = { 109 | path = ./python/general; 110 | description = "Python development environment"; 111 | }; 112 | }; 113 | }; 114 | } 115 | --------------------------------------------------------------------------------