Skip to content

Commit

Permalink
not sure how that was lost
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-gaia committed Sep 21, 2024
1 parent 38855ec commit 1435c2f
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 12 deletions.
49 changes: 37 additions & 12 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions templates/default/.envrc
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions templates/default/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# direnv
.direnv/

# nix
result
result-*
13 changes: 13 additions & 0 deletions templates/default/devshell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ pkgs }:
pkgs.mkShell {
# Add build dependencies
packages = [ ];

# Add environment variables
env = { };

# Load custom bash code
shellHook = ''
'';
}
64 changes: 64 additions & 0 deletions templates/default/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1435c2f

Please sign in to comment.