NixOS and Home Manager config

feat + refactor: generic rust dev shell + template

nel.pet 6a90ef7d 8d2a2885

verified
+17 -3
flake.nix
···
home-manager,
...
} @ inputs: let
-
system = "x86_64-linux";
-
pkgs = nixpkgs.legacyPackages.${system};
+
lib = nixpkgs.lib;
+
forAllSystems = function:
+
lib.genAttrs lib.systems.flakeExposed (
+
system: (function system nixpkgs.legacyPackages.${system})
+
);
in {
homeConfigurations."nel" = home-manager.lib.homeManagerConfiguration {
-
inherit pkgs;
+
pkgs = nixpkgs.legacyPackages."x86_64-linux";
extraSpecialArgs = { inherit inputs; };
modules = [ ./homes/nel/default.nix ];
};
···
nixosConfigurations."nel-desktop" = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs; };
modules = [ ./systems/nel-desktop/configuration.nix ];
+
};
+
+
devShells = forAllSystems (system: pkgs: {
+
rust = (pkgs.callPackage ./templates/rust/shell.nix { });
+
});
+
+
templates = {
+
rust = {
+
path = ./templates/rust;
+
description = "Basic rust project with nix";
+
};
};
};
}
+2
templates/rust/.gitignore
···
+
target/
+
result/
+7
templates/rust/Cargo.lock
···
+
# This file is automatically @generated by Cargo.
+
# It is not intended for manual editing.
+
version = 3
+
+
[[package]]
+
name = "example-rust"
+
version = "0.0.1"
+8
templates/rust/Cargo.toml
···
+
[package]
+
name = "example-rust"
+
version = "0.0.1"
+
license = "MIT"
+
description = "A example rust project using nix"
+
homepage = "https://github.com/"
+
authors = []
+
edition = "2021"
+23
templates/rust/default.nix
···
+
{ lib, rustPlatform }: let
+
toml = (lib.importTOML ./Cargo.toml).package;
+
in rustPlatform.buildRustPackage {
+
pname = "example-rust";
+
inherit (toml) version;
+
+
src = lib.fileset.toSource {
+
root = ./.;
+
fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ./.)) (
+
lib.fileset.unions [
+
./Cargo.toml
+
./Cargo.lock
+
./src
+
]
+
);
+
};
+
+
cargoLock.lockFile = ./Cargo.lock;
+
+
meta = {
+
inherit (toml) homepage description;
+
};
+
}
+27
templates/rust/flake.lock
···
+
{
+
"nodes": {
+
"nixpkgs": {
+
"locked": {
+
"lastModified": 1757873102,
+
"narHash": "sha256-kYhNxLlYyJcUouNRazBufVfBInMWMyF+44xG/xar2yE=",
+
"owner": "nixos",
+
"repo": "nixpkgs",
+
"rev": "88cef159e47c0dc56f151593e044453a39a6e547",
+
"type": "github"
+
},
+
"original": {
+
"owner": "nixos",
+
"ref": "nixpkgs-unstable",
+
"repo": "nixpkgs",
+
"type": "github"
+
}
+
},
+
"root": {
+
"inputs": {
+
"nixpkgs": "nixpkgs"
+
}
+
}
+
},
+
"root": "root",
+
"version": 7
+
}
+23
templates/rust/flake.nix
···
+
{
+
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";
+
+
inputs = {
+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
+
};
+
+
outputs = { self, nixpkgs, ...}: let
+
forAllSystems = function:
+
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (
+
system: (function system nixpkgs.legacyPackages.${system})
+
);
+
in {
+
packages = forAllSystems (system: pkgs: {
+
example = pkgs.callPackage ./default.nix { };
+
default = self.packages.${pkgs.stdenv.hostPlatform.system}.example;
+
});
+
+
devShells = forAllSystems (system: pkgs: {
+
default = pkgs.callPackage ./shell.nix { };
+
});
+
};
+
}
+24
templates/rust/shell.nix
···
+
{
+
mkShell,
+
callPackage,
+
rustPlatform,
+
+
# extra tooling
+
clippy,
+
rustfmt,
+
rust-analyzer,
+
}: let
+
defaultPackage = callPackage ./default.nix { };
+
in mkShell {
+
inputsFrom = [ defaultPackage ];
+
+
env = {
+
RUST_SRC_PATH = rustPlatform.rustLibSrc;
+
};
+
+
packages = [
+
clippy
+
rustfmt
+
rust-analyzer
+
];
+
}
+3
templates/rust/src/main.rs
···
+
fn main() {
+
println!("Hello, world!");
+
}