Compare commits

...

4 Commits

Author SHA1 Message Date
pegasust 856bc52aa7 wip before nuking nixos@Felia 2022-12-21 00:12:30 +00:00
pegasust c368007abd maybe I'm overthinking things? 2022-12-19 00:02:32 +00:00
pegasust e0adf8c39f some bonehead 2022-12-16 14:37:15 +00:00
pegasust 2e341a2409 some calculi 2022-12-16 13:57:32 +00:00
9 changed files with 202 additions and 40 deletions

View File

@ -1,33 +1,12 @@
{ {
"nodes": { "nodes": {
"home-manager": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"utils": "utils"
},
"locked": {
"lastModified": 1669071065,
"narHash": "sha256-KBpgj3JkvlPsJ3duOZqFJe6tgr+wc75t8sFmgRbBSbw=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "f7641a3ff398ccce952e19a199d775934e518c1d",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "home-manager",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1669140675, "lastModified": 1671200928,
"narHash": "sha256-npzfyfLECsJWgzK/M4gWhykP2DNAJTYjgY2BWkz/oEQ=", "narHash": "sha256-mZfzDyzojwj6I0wyooIjGIn81WtGVnx6+avU5Wv+VKU=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "2788904d26dda6cfa1921c5abb7a2466ffe3cb8c", "rev": "757b82211463dd5ba1475b6851d3731dfe14d377",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -38,24 +17,8 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"home-manager": "home-manager",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
},
"utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

29
nix/calculus/default.nix Normal file
View File

@ -0,0 +1,29 @@
{ pkgs ? import <nixpkgs> { }
, lib ? inputs.pkgs.lib
, ...
}@inputs:
builtins // rec {
mod = base: int: base - (int * (builtins.div base int));
map_ = list: fn: (builtins.map fn list);
mapAttrs_ = attrset: fn: (builtins.mapAttrs fn attrset);
# :: [T] -> (T -> null | V) -> [V]
# Filters if return null, otherwise, remap to V
filterMap_ = list: fn: (builtins.filter (e: e != null) (builtins.map fn list));
filterMap = fn: list: (filterMap_ list fn);
filter_ = list: fn: (builtins.filter fn list);
# :: [T] -> (T -> V) -> {T[int] = V;}
list2Attrs_ = list: fn_k_v: (builtins.foldl' (acc: k: acc // { "${k}" = (fn_k_v k); }) { } list);
list2Attrs = fn_k_v: list: (list2Attrs_ list fn_k_v);
# range :: int -> int -> [int]
rangeIn = lib.range;
rangeEx = start: stop: (lib.range start (stop -1));
# [T] -> int
len = builtins.length;
zip = lib.zipLists;
# [T] -> [{idx: int, val: T}]
enumerate = list: lib.zipListsWith (idx: val: { inherit idx val; }) (rangeEx 0 (len list)) list;
}

View File

@ -0,0 +1,103 @@
# An example on how this would be imported (along with test cases)
let
pkgs = import <nixpkgs> { };
inherit (pkgs) lib;
inherit (lib) runTests;
c_ = import ./default.nix { inherit pkgs lib; };
bulkExprTest = { name, fn, list_case, ... }@test: (c_.foldl'
(acc: { name, args, expected, ... }@case: acc // {
"test_${test.name}_${case.name}" = {
expr = c_.foldl' (f: x: f x) fn args;
inherit expected;
};
})
{ }
list_case);
tests = (
bulkExprTest
{
name = "filterMap_";
fn = c_.filterMap_;
list_case = [
{
name = "odd";
args = [ [ 1 2 3 4 5 6 ] (e: if (c_.mod e 2) == 0 then null else e) ];
expected = [ 1 3 5 ];
}
{
name = "even";
args = [ [ 1 2 3 4 5 6 ] (e: if (c_.mod e 2) == 1 then null else e) ];
expected = [ 2 4 6 ];
}
];
} // bulkExprTest {
name = "filterMap";
fn = c_.filterMap;
list_case = [
{
name = "odd";
args = [ (e: if (c_.mod e 2) == 0 then null else e) [ 1 2 3 4 5 6 ] ];
expected = [ 1 3 5 ];
}
{
name = "even";
args = [ (e: if (c_.mod e 2) == 1 then null else e) [ 1 2 3 4 5 6 ] ];
expected = [ 2 4 6 ];
}
];
} // bulkExprTest {
name = "list2Attrs_";
fn = c_.list2Attrs_;
list_case = [
{
name = "attach";
args = [ [ "123" "abc" "1414" ] (_x: 515) ];
expected = { "123" = 515; "abc" = 515; "1414" = 515; };
}
];
} // bulkExprTest {
name = "zip";
fn = c_.zip;
list_case = [
{
name = "equal_length";
args = [ [ 1 2 3 ] [ 4 5 6 ] ];
expected = [ [ 1 4 ] [ 2 5 ] [ 3 6 ] ];
}
{
name = "left_more";
args = [ [ 1 2 3 4 ] [ 5 6 7 ] ];
expected = [ [ 1 5 ] [ 2 6 ] [ 3 7 ] ];
}
];
} // bulkExprTest {
name = "enumerate";
fn = c_.enumerate;
list_case = [
{
name = "empty";
args = [ [ ] ];
expected = [ ];
}
{
name = "normal";
args = [ [ 51 51 11 23 17 125 ] ];
expected = [
{ idx = 0; val = 51; }
{ idx = 1; val = 51; }
{ idx = 2; val = 11; }
{ idx = 3; val = 23; }
{ idx = 4; val = 17; }
{ idx = 5; val = 125; }
];
}
];
}
);
in
{
inherit pkgs lib runTests c_;
_tests = tests;
tests = runTests tests;
}

41
nix/flake.nix Normal file
View File

@ -0,0 +1,41 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus";
# for OpenGL support on Nix
nixgl.url = "github:guibou/nixGL";
# S-tier Rust overlay for faster nightly updates
rust-overlay.url = "github:oxalica/rust-overlay";
# Allows default.nix to call onto flake.nix. Useful for nix eval and automations
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
naersk.url = "github:nix-community/naersk";
nixos-wsl.url = "github:nix-community/NixOS-WSL";
};
outputs =
{ nixpkgs
, home-manager
, flake-utils-plus
, nixgl
, rust-overlay
# , flake-compat # This is only a placeholder for version control by flake.lock
, naersk
, nixos-wsl
, ...
}:
let
# fundamental functions that should only take 2 keystrokes instead of builtins (8)
c_ = import ./calculus;
overlays = [ rust-overlay.overlays.default nixgl.overlay ];
in
{
};
}

20
nix/hosts/default.nix Normal file
View File

@ -0,0 +1,20 @@
# Each host will export optionally its nixosConfiguration, which also manages its
# own hardware-configuration
{ pkgs # nixpkgs imported
, lib # extended lib
, c_
, nixos_lib # nixpkgs/nixos/lib
, flake-utils-plus
, ...
}@inputs:
let
# ({sys: str} -> nixosConfiguration) -> nixosConfigurations-compatible-host for defaultSystems
mkHost = nixosConfigFn: c_.list2Attrs_ flake-utils-plus.lib.defaultSystems (sys: {
${sys} = nixos_lib.nixosSystem ({ system = sys; } // (nixosConfigFn { inherit sys; }));
});
in
{
Felia = mkHost { };
lizzi = mkHost { };
}

0
nix/lib/default.nix Normal file
View File

1
nix/pkgs/default.nix Normal file
View File

@ -0,0 +1 @@
# Contains the wrapper modules for programs and services available to

5
nix/types/default.nix Normal file
View File

@ -0,0 +1,5 @@
{ pkgs ? import <nixpkgs> { }
, lib ? inputs.pkgs.lib
, ...
}@inputs:
lib.recursiveUpdate lib.types { }

0
nix/users/default.nix Normal file
View File