NixOS and Home Manager config

feat + refactor: generic rust dev shell + template

nel.pet 6a90ef7d 8d2a2885

verified
+134 -3
+17 -3
flake.nix
··· 14 14 home-manager, 15 15 ... 16 16 } @ inputs: let 17 - system = "x86_64-linux"; 18 - pkgs = nixpkgs.legacyPackages.${system}; 17 + lib = nixpkgs.lib; 18 + forAllSystems = function: 19 + lib.genAttrs lib.systems.flakeExposed ( 20 + system: (function system nixpkgs.legacyPackages.${system}) 21 + ); 19 22 in { 20 23 homeConfigurations."nel" = home-manager.lib.homeManagerConfiguration { 21 - inherit pkgs; 24 + pkgs = nixpkgs.legacyPackages."x86_64-linux"; 22 25 extraSpecialArgs = { inherit inputs; }; 23 26 modules = [ ./homes/nel/default.nix ]; 24 27 }; ··· 26 29 nixosConfigurations."nel-desktop" = nixpkgs.lib.nixosSystem { 27 30 specialArgs = { inherit inputs; }; 28 31 modules = [ ./systems/nel-desktop/configuration.nix ]; 32 + }; 33 + 34 + devShells = forAllSystems (system: pkgs: { 35 + rust = (pkgs.callPackage ./templates/rust/shell.nix { }); 36 + }); 37 + 38 + templates = { 39 + rust = { 40 + path = ./templates/rust; 41 + description = "Basic rust project with nix"; 42 + }; 29 43 }; 30 44 }; 31 45 }
+2
templates/rust/.gitignore
··· 1 + target/ 2 + result/
+7
templates/rust/Cargo.lock
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 3 4 + 5 + [[package]] 6 + name = "example-rust" 7 + version = "0.0.1"
+8
templates/rust/Cargo.toml
··· 1 + [package] 2 + name = "example-rust" 3 + version = "0.0.1" 4 + license = "MIT" 5 + description = "A example rust project using nix" 6 + homepage = "https://github.com/" 7 + authors = [] 8 + edition = "2021"
+23
templates/rust/default.nix
··· 1 + { lib, rustPlatform }: let 2 + toml = (lib.importTOML ./Cargo.toml).package; 3 + in rustPlatform.buildRustPackage { 4 + pname = "example-rust"; 5 + inherit (toml) version; 6 + 7 + src = lib.fileset.toSource { 8 + root = ./.; 9 + fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ./.)) ( 10 + lib.fileset.unions [ 11 + ./Cargo.toml 12 + ./Cargo.lock 13 + ./src 14 + ] 15 + ); 16 + }; 17 + 18 + cargoLock.lockFile = ./Cargo.lock; 19 + 20 + meta = { 21 + inherit (toml) homepage description; 22 + }; 23 + }
+27
templates/rust/flake.lock
··· 1 + { 2 + "nodes": { 3 + "nixpkgs": { 4 + "locked": { 5 + "lastModified": 1757873102, 6 + "narHash": "sha256-kYhNxLlYyJcUouNRazBufVfBInMWMyF+44xG/xar2yE=", 7 + "owner": "nixos", 8 + "repo": "nixpkgs", 9 + "rev": "88cef159e47c0dc56f151593e044453a39a6e547", 10 + "type": "github" 11 + }, 12 + "original": { 13 + "owner": "nixos", 14 + "ref": "nixpkgs-unstable", 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 + }
+23
templates/rust/flake.nix
··· 1 + { 2 + description = "Rust Project Template. Stolen (and slightly modified) from the lovely Isabel. Original version available at https://github.com/tgirlcloud/nix-templates/tree/main/rust"; 3 + 4 + inputs = { 5 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 6 + }; 7 + 8 + outputs = { self, nixpkgs, ...}: let 9 + forAllSystems = function: 10 + nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed ( 11 + system: (function system nixpkgs.legacyPackages.${system}) 12 + ); 13 + in { 14 + packages = forAllSystems (system: pkgs: { 15 + example = pkgs.callPackage ./default.nix { }; 16 + default = self.packages.${pkgs.stdenv.hostPlatform.system}.example; 17 + }); 18 + 19 + devShells = forAllSystems (system: pkgs: { 20 + default = pkgs.callPackage ./shell.nix { }; 21 + }); 22 + }; 23 + }
+24
templates/rust/shell.nix
··· 1 + { 2 + mkShell, 3 + callPackage, 4 + rustPlatform, 5 + 6 + # extra tooling 7 + clippy, 8 + rustfmt, 9 + rust-analyzer, 10 + }: let 11 + defaultPackage = callPackage ./default.nix { }; 12 + in mkShell { 13 + inputsFrom = [ defaultPackage ]; 14 + 15 + env = { 16 + RUST_SRC_PATH = rustPlatform.rustLibSrc; 17 + }; 18 + 19 + packages = [ 20 + clippy 21 + rustfmt 22 + rust-analyzer 23 + ]; 24 + }
+3
templates/rust/src/main.rs
··· 1 + fn main() { 2 + println!("Hello, world!"); 3 + }