Skip to content

Commit 4959133

Browse files
[READY] treewide: refactor overlay structure (socallinuxexpo#995)
2 parents 652e7d8 + bac4911 commit 4959133

File tree

33 files changed

+273
-63
lines changed

33 files changed

+273
-63
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ jobs:
2626
- uses: DeterminateSystems/nix-installer-action@main
2727
- uses: DeterminateSystems/magic-nix-cache-action@main
2828
- run: nix build -L .#massflash
29-
- run: nix build -L .#scaleInventory
29+
- run: nix build -L .#scale-inventory
3030
- run: nix build -L .#serverspec

flake.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
disko.inputs.nixpkgs.follows = "nixpkgs-unstable";
66
disko.url = "github:nix-community/disko";
77
nixpkgs-2505.url = "github:NixOS/nixpkgs";
8+
nixpkgs-lib.url = "github:nix-community/nixpkgs.lib";
89
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
910
nixpkgs.follows = "nixpkgs-unstable";
1011
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs-unstable";

nix/dev-shells/default.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mapAttrs (const (
5656
pkg-config
5757
gcc
5858
stdenv
59-
scale-network.makeDhcpd
59+
scale-network.make-dhcpd
6060
scale-network.serverspec
6161
];
6262

@@ -66,9 +66,9 @@ mapAttrs (const (
6666
perlPackages.Expect
6767
perlPackages.TermReadKey
6868
perlPackages.NetSFTPForeign
69-
scale-network.perlNetArp
70-
scale-network.perlNetInterface
71-
scale-network.perlNetPing
69+
scale-network.perl-net-arp
70+
scale-network.perl-net-interface
71+
scale-network.perl-net-ping
7272
ghostscript
7373
];
7474
in

nix/library/default.nix

Lines changed: 188 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,207 @@
11
inputs:
22
let
3-
inherit (inputs.nixpkgs-unstable) lib;
3+
4+
inherit (builtins)
5+
readDir
6+
;
7+
8+
inherit (inputs.nixpkgs-lib) lib;
49

510
inherit (lib.attrsets)
11+
attrNames
12+
filterAttrs
613
mapAttrs'
714
nameValuePair
815
;
916

17+
inherit (lib.fixedPoints)
18+
fix
19+
;
20+
21+
inherit (lib.lists)
22+
toList
23+
;
24+
1025
inherit (lib.strings)
26+
concatMapStrings
27+
concatStringsSep
1128
splitString
1229
substring
1330
toLower
1431
toUpper
15-
concatMapStrings
1632
;
33+
34+
inherit (lib.trivial)
35+
const
36+
flip
37+
pipe
38+
;
39+
1740
in
18-
rec {
41+
fix (finalLibrary: {
42+
43+
path = fix (finalPath: {
44+
45+
/**
46+
Filter the contents of a directory path for directories only.
47+
48+
# Inputs
49+
50+
`contents`
51+
52+
: 1\. The contents of a directory path.
53+
54+
# Type
55+
56+
```
57+
filterDirectories :: AttrSet -> AttrSet
58+
```
59+
60+
# Examples
61+
:::{.example}
62+
## `lib.path.filterDirectories` usage example
63+
64+
```nix
65+
x = {
66+
"default.nix" = "regular";
67+
djacu = "directory";
68+
programs = "directory";
69+
services = "directory";
70+
}
71+
filterDirectories x
72+
=> {
73+
djacu = "directory";
74+
programs = "directory";
75+
services = "directory";
76+
}
77+
```
78+
79+
:::
80+
*/
81+
filterDirectories = filterAttrs (const (fileType: fileType == "directory"));
82+
83+
/**
84+
Get list of directories names under parent.
85+
86+
# Inputs
87+
88+
`path`
89+
90+
: 1\. The parent path.
91+
92+
# Type
93+
94+
```
95+
getDirectoryNames :: Path -> [String]
96+
```
97+
98+
# Examples
99+
:::{.example}
100+
## `lib.path.getDirectoryNames` usage example
101+
102+
```nix
103+
getDirectoryNames ./home-modules
104+
=> [
105+
"djacu"
106+
"programs"
107+
"services"
108+
]
109+
```
110+
*/
111+
getDirectoryNames = flip pipe [
112+
finalPath.getDirectories
113+
attrNames
114+
];
115+
116+
/**
117+
Get attribute set of directories under parent.
118+
119+
# Inputs
120+
121+
`path`
122+
123+
: 1\. The parent path.
124+
125+
# Type
126+
127+
```
128+
getDirectories :: Path -> AttrSet
129+
```
130+
131+
# Examples
132+
:::{.example}
133+
## `lib.path.getDirectories` usage example
134+
135+
```nix
136+
getDirectories ./home-modules
137+
=> {
138+
djacu = "directory";
139+
programs = "directory";
140+
services = "directory";
141+
}
142+
```
143+
*/
144+
getDirectories = flip pipe [
145+
readDir
146+
finalPath.filterDirectories
147+
];
148+
149+
/**
150+
Join a parent path to one or more children.
151+
152+
# Inputs
153+
154+
`parent`
155+
156+
: 1\. A parent path.
157+
158+
`paths`
159+
160+
: 2\. The paths to append.
161+
162+
# Type
163+
164+
```
165+
joinParentToPaths :: Path -> String | [ String ] -> String
166+
```
167+
168+
# Examples
169+
:::{.example}
170+
## `lib.path.joinParentToPaths` usage example
171+
172+
```nix
173+
joinParentToPaths ./home-modules "users"
174+
=> /home/djacu/dev/djacu/theonecfg/home-modules/users
175+
joinParentToPaths ./home-modules [ "users" djacu" "module.nix" "]
176+
=> /home/djacu/dev/djacu/theonecfg/home-modules/users/djacu/module.nix
177+
```
178+
179+
:::
180+
*/
181+
joinParentToPaths = parent: paths: parent + ("/" + concatStringsSep "/" (toList paths));
182+
183+
});
184+
185+
strings = fix (finalStrings: {
186+
187+
mutFirstChar =
188+
f: s:
189+
let
190+
firstChar = f (substring 0 1 s);
191+
rest = substring 1 (-1) s;
192+
in
193+
firstChar + rest;
19194

20-
mutFirstChar =
21-
f: s:
22-
let
23-
firstChar = f (substring 0 1 s);
24-
rest = substring 1 (-1) s;
25-
in
26-
firstChar + rest;
195+
kebabToCamel =
196+
s:
197+
finalStrings.mutFirstChar toLower (
198+
concatMapStrings (finalStrings.mutFirstChar toUpper) (splitString "-" s)
199+
);
27200

28-
kebabToCamel =
29-
s: mutFirstChar toLower (concatMapStrings (mutFirstChar toUpper) (splitString "-" s));
201+
attrNamesKebabToCamel = mapAttrs' (
202+
name: value: nameValuePair (finalStrings.kebabToCamel name) value
203+
);
30204

31-
attrNamesKebabToCamel = mapAttrs' (name: value: nameValuePair (kebabToCamel name) value);
205+
});
32206

33-
}
207+
})

nix/nixos-configurations/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let
1616
mkDefault
1717
;
1818

19-
inherit (inputs.self.library)
19+
inherit (inputs.self.library.strings)
2020
kebabToCamel
2121
;
2222
in

nix/nixos-modules/services/bind-master.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let
3737
IN NS coreexpo.scale.lan.
3838
IN NS coreconf.scale.lan.
3939
''
40-
(builtins.readFile "${pkgs.scale-network.scaleInventory}/config/db.scale.lan.records")
40+
(builtins.readFile "${pkgs.scale-network.scale-inventory}/config/db.scale.lan.records")
4141
]
4242
);
4343
named10Rev = pkgs.writeText "named-10.rev" (
@@ -55,7 +55,7 @@ let
5555
IN NS coreexpo.scale.lan.
5656
IN NS coreconf.scale.lan.
5757
''
58-
(builtins.readFile "${pkgs.scale-network.scaleInventory}/config/db.ipv4.arpa.records")
58+
(builtins.readFile "${pkgs.scale-network.scale-inventory}/config/db.ipv4.arpa.records")
5959
]
6060
);
6161
named2001Rev = pkgs.writeText "named-2001.470.f026-48.rev" (
@@ -73,7 +73,7 @@ let
7373
IN NS coreexpo.scale.lan.
7474
IN NS coreconf.scale.lan.
7575
''
76-
(builtins.readFile "${pkgs.scale-network.scaleInventory}/config/db.ipv6.arpa.records")
76+
(builtins.readFile "${pkgs.scale-network.scale-inventory}/config/db.ipv6.arpa.records")
7777
]
7878
);
7979
namedConf = pkgs.writeText "named.conf" ''

nix/nixos-modules/services/kea-master.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ in
4242
let
4343
dhcp4PopulateConfig = pkgs.runCommand "replace" { } ''
4444
mkdir $out
45-
cp ${pkgs.scale-network.scaleInventory}/config/dhcp4-server.conf $TMP/dhcp4-server.conf
45+
cp ${pkgs.scale-network.scale-inventory}/config/dhcp4-server.conf $TMP/dhcp4-server.conf
4646
substituteInPlace "$TMP/dhcp4-server.conf" \
4747
--replace-fail '@@INTERFACE@@' '${config.scale-network.facts.eth}'
4848
cp $TMP/dhcp4-server.conf $out
@@ -56,7 +56,7 @@ in
5656
let
5757
dhcp6PopulateConfig = pkgs.runCommand "replace" { } ''
5858
mkdir $out
59-
cp ${pkgs.scale-network.scaleInventory}/config/dhcp6-server.conf $TMP/dhcp6-server.conf
59+
cp ${pkgs.scale-network.scale-inventory}/config/dhcp6-server.conf $TMP/dhcp6-server.conf
6060
substituteInPlace "$TMP/dhcp6-server.conf" \
6161
--replace-fail '@@SERVERADDRESS@@' '${builtins.head (lib.splitString "/" config.scale-network.facts.ipv6)}' \
6262
--replace-fail '@@INTERFACE@@' '${config.scale-network.facts.eth}'

nix/nixos-modules/services/monitoring.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let
2323

2424
unfilteredList = (
2525
builtins.split "\n" (
26-
builtins.readFile "${pkgs.scale-network.scaleInventory}/config/all-network-devices"
26+
builtins.readFile "${pkgs.scale-network.scale-inventory}/config/all-network-devices"
2727
)
2828
);
2929
filteredList = (builtins.filter (line: line != [ ] && line != "") unfilteredList);
@@ -62,13 +62,13 @@ in
6262
{
6363
job_name = "ap";
6464
static_configs = builtins.fromJSON (
65-
builtins.readFile "${pkgs.scale-network.scaleInventory}/config/prom-aps.json"
65+
builtins.readFile "${pkgs.scale-network.scale-inventory}/config/prom-aps.json"
6666
);
6767
}
6868
{
6969
job_name = "pi";
7070
static_configs = builtins.fromJSON (
71-
builtins.readFile "${pkgs.scale-network.scaleInventory}/config/prom-pis.json"
71+
builtins.readFile "${pkgs.scale-network.scale-inventory}/config/prom-pis.json"
7272
);
7373
}
7474
{

nix/nixos-modules/services/mrtg.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ in
4949
let
5050
unfilteredList = (
5151
builtins.split "\n" (
52-
builtins.readFile "${pkgs.scale-network.scaleInventory}/config/all-network-devices"
52+
builtins.readFile "${pkgs.scale-network.scale-inventory}/config/all-network-devices"
5353
)
5454
);
5555
filteredList = (builtins.filter (line: line != [ ] && line != "") unfilteredList);

0 commit comments

Comments
 (0)