From 1435c2f84fd7dca01cd6d1fcb501609ade8d0f05 Mon Sep 17 00:00:00 2001 From: Adam Gaia Date: Fri, 20 Sep 2024 21:54:46 -0600 Subject: [PATCH] not sure how that was lost --- lib/default.nix | 49 +++++++++++++++++++------- templates/default/.envrc | 11 ++++++ templates/default/.gitignore | 6 ++++ templates/default/devshell.nix | 13 +++++++ templates/default/flake.lock | 64 ++++++++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 12 deletions(-) create mode 100755 templates/default/.envrc create mode 100644 templates/default/.gitignore create mode 100644 templates/default/devshell.nix create mode 100644 templates/default/flake.lock diff --git a/lib/default.nix b/lib/default.nix index 5b42ee7..858e549 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -169,11 +169,11 @@ let if builtins.pathExists (path + "/default.nix") then eachSystem ({ pkgs, ... }: loadDefault { inherit pkgs; } (path + "/default.nix")) else if builtins.pathExists (path + "/home.nix") then - eachSystem ({ pkgs, ... }: loadHomeConfig { inherit pkgs; } (path + "/home.nix")) + eachSystem ({ pkgs, ... }: loadUserConfig { inherit pkgs; } (path + "/home.nix")) else throw "user profile '${name}' does not have a configuration"; in - lib.mapAttrs loadHome entries + lib.mapAttrs loadUser entries ); flattenUsernameSystem = @@ -246,17 +246,42 @@ let ) (lib.attrsToList hosts) ); - modules = { - common = importDir (src + "/modules/common") entriesPath; - darwin = importDir (src + "/modules/darwin") entriesPath; - home = importDir (src + "/modules/home") entriesPath; - nixos = importDir (src + "/modules/nixos") entriesPath; - }; + modules = + let + path = src + "/modules"; + moduleDirs = builtins.attrNames ( + lib.filterAttrs (_name: value: value == "directory") (builtins.readDir path) + ); + in + lib.optionalAttrs (builtins.pathExists path) ( + lib.genAttrs moduleDirs (name: importDir (path + "/${name}") entriesPath) + ); in # FIXME: maybe there are two layers to this. The blueprint, and then the mapping to flake outputs. { formatter = eachSystem ( - { pkgs, perSystem, ... }: perSystem.self.formatter or pkgs.nixfmt-rfc-style + { pkgs, perSystem, ... }: + perSystem.self.formatter or (pkgs.writeShellApplication { + name = "nixfmt-rfc-style"; + + runtimeInputs = [ + pkgs.findutils + pkgs.gnugrep + pkgs.nixfmt-rfc-style + ]; + + text = '' + set -euo pipefail + + # Not a git repo, or git is not installed. Fallback + if ! git rev-parse --is-inside-work-tree; then + exec nixfmt "$@" + fi + + # By default `nix fmt` passes "." as the first argument. + git ls-files "$@" | grep '\.nix$' | xargs --no-run-if-empty nixfmt + ''; + }) ); lib = tryImport (src + "/lib") specialArgs; @@ -313,10 +338,10 @@ let userConfigurations = lib.mapAttrs (_: x: x.value) usersBySystem; inherit modules; - darwinModules = modules.darwin; - homeModules = modules.home; + darwinModules = modules.darwin or { }; + homeModules = modules.home or { }; # TODO: how to extract NixOS tests? - nixosModules = modules.nixos; + nixosModules = modules.nixos or { }; templates = importDir (src + "/templates") ( entries: diff --git a/templates/default/.envrc b/templates/default/.envrc new file mode 100755 index 0000000..9978ef0 --- /dev/null +++ b/templates/default/.envrc @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# Used by https://direnv.net + +# Automatically reload when this file changes +watch_file devshell.nix + +# Load `nix develop` +use flake + +# Extend the environment with per-user overrides +source_env_if_exists .envrc.local diff --git a/templates/default/.gitignore b/templates/default/.gitignore new file mode 100644 index 0000000..12731de --- /dev/null +++ b/templates/default/.gitignore @@ -0,0 +1,6 @@ +# direnv +.direnv/ + +# nix +result +result-* diff --git a/templates/default/devshell.nix b/templates/default/devshell.nix new file mode 100644 index 0000000..f580911 --- /dev/null +++ b/templates/default/devshell.nix @@ -0,0 +1,13 @@ +{ pkgs }: +pkgs.mkShell { + # Add build dependencies + packages = [ ]; + + # Add environment variables + env = { }; + + # Load custom bash code + shellHook = '' + + ''; +} diff --git a/templates/default/flake.lock b/templates/default/flake.lock new file mode 100644 index 0000000..2781dce --- /dev/null +++ b/templates/default/flake.lock @@ -0,0 +1,64 @@ +{ + "nodes": { + "blueprint": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "systems": "systems" + }, + "locked": { + "lastModified": 1724053269, + "narHash": "sha256-DinmPyxmUSLjBUYMe3eK0GKykwe33vWbVTmp7++P4Ng=", + "owner": "numtide", + "repo": "blueprint", + "rev": "766302be9063650ca6578e5ba09cc4260b0da29c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "blueprint", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1725103162, + "narHash": "sha256-Ym04C5+qovuQDYL/rKWSR+WESseQBbNAe5DsXNx5trY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "12228ff1752d7b7624a54e9c1af4b222b3c1073b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "blueprint": "blueprint", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +}