-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathflake.nix
139 lines (132 loc) · 4.15 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
description = "Description for the project";
inputs = {
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-24.11";
nixpkgs.follows = "nixpkgs-stable";
flake-parts.url = "github:hercules-ci/flake-parts";
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
pre-commit-hooks-nix = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
};
outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } (
{ flake-parts-lib, ... }:
let
inherit (flake-parts-lib) importApply;
in
{
imports = [
inputs.devshell.flakeModule
inputs.pre-commit-hooks-nix.flakeModule
inputs.treefmt-nix.flakeModule
(importApply ./linters.nix { inherit flake-parts-lib; })
];
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
perSystem =
{
config,
pkgs,
self',
...
}:
let
inherit (pkgs.lib)
pipe
mapAttrs
attrValues
listToAttrs
flatten
mapAttrsToList
splitString
head
toLower
;
# This attrset will be used in two places:
# * Apps
# * Devshell scripts that effectively run apps
apps = pipe ./nix/apps [
builtins.import
(x: x { inherit pkgs self'; }) # apply pkgs
# Turn nested attribute sets with packages into apps, prepending the category prefix
(mapAttrs (
k: v: # This is the outer attrset, k = "sis", v = "import ./sis { inherit pkgs;}"
pipe v [
(mapAttrs (
# This is the inner attrset, k' = setup, v' = {whatever code}
k': v': {
name = "${k}-${k'}";
value = {
type = "app";
program = v';
};
}
))
attrValues
]
))
# Turn everything into a top-level attrset
attrValues
flatten
listToAttrs
];
in
{
packages = rec {
# This package is used to pin and propagate snowcli version
snowcli = pkgs.snowflake-cli;
inherit (pkgs) poetry;
# TODO: Replace with nix package in #11
# For now specify snowcli so `nix flake check` passes
default = snowcli;
};
inherit apps;
devShells.pre-commit = config.pre-commit.devShell;
devshells.default = {
env = [ ];
# Construct commands from apps, using program description as command help
commands = mapAttrsToList (k: v: {
name = k;
help = v.program.meta.description;
category = pipe k [
(splitString "-")
head
# Add spaces to the app category
(builtins.split "([A-Z][a-z]+)") # Split on starts of camelCase
(builtins.filter (x: x != "")) # Remove empty matches
flatten
(builtins.concatStringsSep " ")
toLower
];
command = "nix run $PRJ_ROOT#${k}";
}) apps;
packages = attrValues {
inherit (pkgs)
jc
jq
mdsh
mdbook
;
inherit (self'.packages) snowcli;
};
};
};
# flake = { };
}
);
}