-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
executable file
·212 lines (205 loc) · 8.07 KB
/
flake.nix
File metadata and controls
executable file
·212 lines (205 loc) · 8.07 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
{
description = "Opinionated Flake for Fortran/Python/C/C++/JS Development";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs2505.url = "github:NixOS/nixpkgs/2b0d2b456e4e8452cf1c16d00118d145f31160f9"; # to use for older packages
flake-parts.url = "github:hercules-ci/flake-parts/";
devshell.url = "github:numtide/devshell/";
import-tree.url = "github:vic/import-tree/";
git-hooks-nix.url = "github:cachix/git-hooks.nix/";
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs =
{
nixpkgs2505,
flake-parts,
...
}@inputs:
let
inherit (inputs) import-tree;
getLanguageDefaultNix = (import-tree.match ".*/default\\.nix") ./nix/languages;
getEditorDefaultNix = (import-tree.match ".*/default\\.nix") ./nix/editors;
imports = builtins.concatLists [
[
inputs.flake-parts.flakeModules.easyOverlay
inputs.devshell.flakeModule
inputs.treefmt-nix.flakeModule
inputs.git-hooks-nix.flakeModule
]
getLanguageDefaultNix.imports
getEditorDefaultNix.imports
];
in
flake-parts.lib.mkFlake
{
inherit inputs;
}
{
inherit imports;
systems = [
"x86_64-linux"
];
perSystem =
{
config,
inputs',
pkgs,
system,
...
}:
let
userConfig = import ./config.nix { inherit pkgs; };
in
{
_module.args = {
pkgsOlder = import nixpkgs2505 {
inherit system inputs';
};
helper = import ./nix/helpers;
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
(import ./nix/overlays)
];
config = { };
};
};
imports = [ userConfig ]; # settings from config.nix defined by user
packages.upgrade = pkgs.writeShellScriptBin "upgrade.sh" ''
#https://stackoverflow.com/questions/2657935/checking-for-a-dirty-index-or-untracked-files-with-git
echo "This script will attempt to 'upgrade' the devflake template with the latest release (i.e. not from the main branch)"
sleep .5s
echo "This is a DESTRUCTIVE OPERATION on the following files and directories: flake.nix, flake.lock, ./nix/{languages,helpers,editors/**/default.nix}. It will replace the files IN-PLACE."
sleep .5s
echo "config.nix will NOT BE TOUCHED, but its attributes MAY CAUSE ERRORS THE NEXT TIME YOU REBUILD."
echo "Any configuration in overlays or the language-specific editor configurations will NOT BE TOUCHED, and hopefully should not cause any errors depending on how complex your configuration is"
echo "This script will copy the entire nix directory, flake.nix, flake.lock and config.nix into a folder called 'nix-backup'"
echo "This script will check if git is available from the environment, to warn of potentially untracked files. If git is not found, the script will continue assuming you have backed up everything"
echo "This script will also check for curl. If curl is not found, the script will exit before anything happens"
echo "????HAVE YOU BACKED UP YOUR STUFF YET????"
read -n 1 -p "PRESS A KEY TO CONFIRM YOU HAVE BACKED UP. YOU ASSUME THE CONSEQUENCES, IF THEY HAPPEN:" tempinputvar
# === BEGIN PROGRAM ===
# Check git exists in the shell
if ! command -v git >/dev/null 2>&1
then
echo "git could not be found"
else
git ls-files --others --error-unmatch . >/dev/null 2>&1; ec=$?
if test "$ec" = 0; then
echo "Untracked files exist in this project. Will not risk updating template. Exiting..."
exit(1)
elif test "$ec" = 1; then
echo "No untracked files"
else
echo "Error from git ls-files"
fi
fi
if ! command -v curl >/dev/null 2>&1
then
echo "curl could not be found, exiting"
exit 1
fi
# ==== CREATING BACKUP ====
echo "CREATING BACKUP"
backupdir="nix-backup"
if [ ! -e "$backupdir" ]; then
mkdir -p "$backupdir"
else
echo "nix-backup folder already exists. Delete and then re-run this script. Exiting..."
exit 1
fi
# All relevant files in the template are moved to "nix-backup"
mv flake.nix "$backupdir"
cp config.nix "$backupdir"
mv flake.lock "$backupdir"
cp statix.toml "$backupdir"
mv ./nix "$backupdir"
# === FETCHING LATEST TEMPLATE ===
echo "FETCHING LATEST TEMPLATE"
# This URL will be correct once the refactor is on main branch
#curl -sL https://api.github.com/repos/chpxu/development-flake/releases/download/TODO
nix flake init -t github:chpxu/development-flake#default
# === COPYING SOME CONFIG FILES BACK OVER THAT SHOULDN'T BREAK ANYTHING ===
# There will only be non-hidden directories and files. A simple loop will suffice
for dir in $backupdir/nix/editors/*/
do
languages=''${dir%*/}
cp $languages/* "./nix/editors"
done
cp -r $backupdir/nix/editors/languages/* ./nix/editors/languages
echo "SCRIPT HAS FINISHED RUNNING"
echo "PLEASE CHECK EVERYTHING HAS WORKED"
exit 0
'';
pre-commit.settings.hooks = {
nixfmt.enable = true;
flake-checker = {
enable = true;
after = [ "treefmt-nix" ];
};
treefmt = {
enable = true;
package = config.treefmt.build.wrapper;
};
};
treefmt = {
package = pkgs.treefmt;
flakeCheck = true;
flakeFormatter = true;
projectRootFile = "flake.nix";
programs = {
deadnix.enable = true;
statix.enable = true;
nixfmt.enable = true;
nixf-diagnose.enable = true;
yamlfmt.enable = true;
json-sort-cli.enable = true;
};
settings = {
global.excludes = [
"LICENSE"
"flake.lock"
"*/flake.lock"
".envrc"
".direnv/*"
"*/.gitignore"
".github/*"
"Pictures/*"
"result/*"
"*.png"
"*.jpg"
"*.conf"
"*.ini"
"docs/fonts/*"
"**/*.conf"
];
formatter = {
deadnix.priority = 1;
statix.priority = 2;
nixfmt = {
priority = 3;
strict = true;
indent = 4;
};
nixf-diagnose = {
priority = 99;
};
};
};
};
};
flake = {
templates = {
default = {
description = ''
Opinionated flake for sane and configurable developer environments
'';
path = ./.;
welcomeText = ''
Welcome to devflake. Edit config.nix to get started. See the README.md for more information.
'';
};
};
};
};
}