├── python ├── .envrc ├── .gitignore └── flake.nix ├── rust ├── .envrc ├── .gitignore └── flake.nix ├── svelte ├── .envrc └── flake.nix ├── python.md ├── rust.md ├── README.md ├── flake.nix └── svelte.md /python/.envrc: -------------------------------------------------------------------------------- 1 | use flake -------------------------------------------------------------------------------- /rust/.envrc: -------------------------------------------------------------------------------- 1 | use flake -------------------------------------------------------------------------------- /svelte/.envrc: -------------------------------------------------------------------------------- 1 | use flake -------------------------------------------------------------------------------- /python/.gitignore: -------------------------------------------------------------------------------- 1 | result 2 | .direnv 3 | -------------------------------------------------------------------------------- /rust/.gitignore: -------------------------------------------------------------------------------- 1 | result 2 | /target 3 | .direnv 4 | -------------------------------------------------------------------------------- /python.md: -------------------------------------------------------------------------------- 1 | # Python flake template 2 | 3 | Getting started 4 | 5 | ## Enter a Python devShell 6 | 7 | ```bash 8 | nix develop 9 | ``` 10 | 11 | Enter your Python environment as usual 12 | 13 | ```bash 14 | python 15 | ``` 16 | 17 | The dependencies listed on line 14 of `flake.nix` are available 18 | 19 | ```python 20 | import pandas as pd 21 | ... 22 | ``` 23 | 24 | -------------------------------------------------------------------------------- /rust.md: -------------------------------------------------------------------------------- 1 | # Rust flake template 2 | 3 | Getting started 4 | 5 | ## Enter a Rust devshell 6 | 7 | ```bash 8 | nix develop 9 | ``` 10 | ## Init and build your project with Cargo 11 | 12 | ```bash 13 | cargo init 14 | cargo build 15 | ``` 16 | 17 | ## Track project files 18 | 19 | ```bash 20 | git add -A 21 | ``` 22 | 23 | ## Build your project with nix 24 | 25 | ```bash 26 | nix build 27 | ``` 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flake-templates 2 | 3 | Templates that can be used with the [Nix](https://nixos.org) Flakes system. 4 | 5 | ## Rust 6 | 7 | ```sh 8 | mkdir my-project 9 | nix flake init --refresh -t github:cor/flake-templates\#rust 10 | ``` 11 | 12 | 13 | [Read the full Rust instructions here](./rust.md) 14 | 15 | ## Svelte 16 | 17 | ```sh 18 | mkdir my-project 19 | nix flake init --refresh -t github:cor/flake-templates\#svelte 20 | ``` 21 | 22 | [Read the full Svelte instructions here](./svelte.md) 23 | 24 | 25 | ## Other 26 | 27 | To see which templates are defined by this repository, run 28 | 29 | ```sh 30 | nix flake show github:cor/flake-templates 31 | ``` 32 | 33 | -------------------------------------------------------------------------------- /python/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Python flake template"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 6 | flake-parts.url = "github:hercules-ci/flake-parts"; 7 | }; 8 | outputs = inputs@{ self, nixpkgs, flake-parts, ... }: 9 | flake-parts.lib.mkFlake { inherit inputs; } { 10 | systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; 11 | perSystem = { pkgs, system, ... }: 12 | let 13 | python = pkgs.python3.withPackages (pp: with pp; [ 14 | # Add your packages here: 15 | pandas 16 | ]); 17 | in 18 | { 19 | devShells = { 20 | default = pkgs.mkShell { 21 | buildInputs = [ python ]; 22 | }; 23 | }; 24 | }; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Nix flake templates by @cor"; 3 | 4 | outputs = _: { 5 | templates = { 6 | rust = { 7 | description = 8 | "Rust flake template with `rust-analyzer`, `clippy`, and `bacon`. Built using `flake-parts` and `rust-overlay`."; 9 | path = ./rust; 10 | welcomeText = builtins.readFile ./rust.md; 11 | }; 12 | 13 | python = { 14 | description = 15 | "Python flake template with support for adding dependencies."; 16 | path = ./python; 17 | welcomeText = builtins.readFile ./python.md; 18 | }; 19 | 20 | svelte = { 21 | description = 22 | "Svelte flake template using `adapter-node` with `svelte-server`. Built using `flake-parts`."; 23 | path = ./svelte; 24 | welcomeText = builtins.readFile ./svelte.md; 25 | }; 26 | }; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /svelte.md: -------------------------------------------------------------------------------- 1 | # Svelte flake template 2 | 3 | ## Using this template 4 | 5 | ```bash 6 | mkdir my-project 7 | cd my-project 8 | nix flake init --refresh -t github:cor/flake-templates\#svelte 9 | ``` 10 | 11 | 12 | ## Initializing your project 13 | 14 | You will need to run the following commands once in order to create your Svelte app: 15 | 16 | ```bash 17 | nix develop 18 | npm create svelte@latest . 19 | echo "result" >> .gitignore 20 | echo ".direnv" >> .gitignore 21 | yarn 22 | yarn add -D @sveltejs/adapter-node 23 | ``` 24 | 25 | Then, open the file `svelte.config.js`, and change the first line from: 26 | 27 | ```javascript 28 | import adapter from '@sveltejs/adapter-auto'; 29 | ``` 30 | 31 | to 32 | 33 | ```javascript 34 | import adapter from '@sveltejs/adapter-node'; 35 | ``` 36 | 37 | (If this doesn't work, check the [adapter-node docs](https://kit.svelte.dev/docs/adapter-node)). 38 | 39 | Finally, run 40 | 41 | ```bash 42 | git init 43 | git add -A 44 | git commit -m "init" 45 | ``` 46 | 47 | You can now reproducibly build and run your Svelte project with Nix! 48 | 49 | ```bash 50 | ORIGIN=http://localhost:3000 nix run 51 | ``` 52 | 53 | ## Enter a Svelte devshell 54 | 55 | ```bash 56 | nix develop 57 | ``` 58 | 59 | ## Build your project with Nix 60 | 61 | ```bash 62 | nix build 63 | ``` 64 | -------------------------------------------------------------------------------- /svelte/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Svelte flake template"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 6 | gitignore.url = "github:hercules-ci/gitignore.nix"; 7 | flake-parts.url = "github:hercules-ci/flake-parts"; 8 | }; 9 | outputs = inputs@{ self, nixpkgs, gitignore, flake-parts, ... }: 10 | flake-parts.lib.mkFlake { inherit inputs; } { 11 | systems = 12 | [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; 13 | perSystem = { config, self', inputs', pkgs, system, lib, ... }: 14 | let 15 | inherit (gitignore.lib) gitignoreSource; 16 | packageJSON = lib.importJSON ./package.json; 17 | in { 18 | packages = rec { 19 | site-src = pkgs.mkYarnPackage rec { 20 | name = "${packageJSON.name}-site-${version}"; 21 | version = packageJSON.version; 22 | src = gitignoreSource ./.; 23 | packageJson = "${src}/package.json"; 24 | yarnLock = "${src}/yarn.lock"; 25 | buildPhase = '' 26 | yarn --offline build 27 | ''; 28 | distPhase = "true"; 29 | }; 30 | 31 | site = pkgs.writeShellApplication { 32 | name = packageJSON.name; 33 | 34 | runtimeInputs = [ site-src pkgs.nodejs ]; 35 | 36 | text = '' 37 | node ${site-src}/libexec/${packageJSON.name}/deps/${packageJSON.name}/build 38 | ''; 39 | }; 40 | 41 | default = site; 42 | }; 43 | 44 | devShells = { 45 | default = pkgs.mkShell { 46 | buildInputs = (with pkgs; [ 47 | nixfmt 48 | nodejs 49 | yarn 50 | nil 51 | nodePackages.svelte-language-server 52 | nodePackages.typescript-language-server 53 | ]); 54 | }; 55 | }; 56 | }; 57 | }; 58 | } -------------------------------------------------------------------------------- /rust/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Rust flake template"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 6 | flake-parts.url = "github:hercules-ci/flake-parts"; 7 | rust-overlay = { 8 | url = "github:oxalica/rust-overlay"; 9 | inputs.nixpkgs.follows = "nixpkgs"; 10 | }; 11 | crane.url = "github:ipetkov/crane"; 12 | }; 13 | outputs = 14 | inputs@{ 15 | self, 16 | nixpkgs, 17 | rust-overlay, 18 | flake-parts, 19 | ... 20 | }: 21 | flake-parts.lib.mkFlake { inherit inputs; } { 22 | systems = [ 23 | "x86_64-linux" 24 | "aarch64-linux" 25 | "aarch64-darwin" 26 | ]; 27 | perSystem = 28 | { 29 | config, 30 | self', 31 | inputs', 32 | pkgs, 33 | system, 34 | ... 35 | }: 36 | let 37 | crane = rec { 38 | lib = inputs.crane.mkLib pkgs; 39 | stable = lib.overrideToolchain self'.packages.rust-stable; 40 | }; 41 | in 42 | { 43 | packages = { 44 | rust-stable = inputs'.rust-overlay.packages.rust.override { 45 | extensions = [ 46 | "rust-src" 47 | "rust-analyzer" 48 | "clippy" 49 | ]; 50 | }; 51 | default = crane.stable.buildPackage { 52 | src = ./.; 53 | cargoBuildCommand = "cargo build --release"; 54 | buildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin ( 55 | with pkgs.darwin.apple_sdk.frameworks; [ Security ] 56 | ); 57 | }; 58 | }; 59 | devShells = { 60 | default = pkgs.mkShell { 61 | buildInputs = [ 62 | self'.packages.rust-stable 63 | ] 64 | ++ (with pkgs; [ 65 | bacon 66 | nil 67 | hyperfine 68 | cargo-flamegraph 69 | ]) 70 | ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ Security ])); 71 | }; 72 | }; 73 | }; 74 | }; 75 | } 76 | 77 | --------------------------------------------------------------------------------