treewide: init flakes
This commit is contained in:
commit
8ef7d74438
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
result*
|
||||
.direnv
|
||||
.pre-commit-config.yaml
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2024 rebmit
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
182
flake.lock
Normal file
182
flake.lock
Normal file
|
@ -0,0 +1,182 @@
|
|||
{
|
||||
"nodes": {
|
||||
"devshell": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1728330715,
|
||||
"narHash": "sha256-xRJ2nPOXb//u1jaBnDP56M7v5ldavjbtR6lfGqSvcKg=",
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"rev": "dd6b80932022cea34a019e2bb32f6fa9e494dfef",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1696426674,
|
||||
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1730504689,
|
||||
"narHash": "sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS+b4tfNFCwE=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "506278e768c2a08bec68eb62932193e341f55c90",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"git-hooks-nix": {
|
||||
"inputs": {
|
||||
"flake-compat": [
|
||||
"flake-compat"
|
||||
],
|
||||
"gitignore": [
|
||||
"gitignore-nix"
|
||||
],
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"nixpkgs-stable": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731363552,
|
||||
"narHash": "sha256-vFta1uHnD29VUY4HJOO/D6p6rxyObnf+InnSMT4jlMU=",
|
||||
"owner": "cachix",
|
||||
"repo": "git-hooks.nix",
|
||||
"rev": "cd1af27aa85026ac759d5d3fccf650abe7e1bbf0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "git-hooks.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"gitignore-nix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1709087332,
|
||||
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"haumea": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1708375098,
|
||||
"narHash": "sha256-DaFJp3wDHgOqx98U0SF57bXaH2Orp106c+jSdPCVu1E=",
|
||||
"owner": "nix-community",
|
||||
"repo": "haumea",
|
||||
"rev": "ec6350fd9353e7f27ce0e85d31f82e3ed73e4d70",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "haumea",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-unstable": {
|
||||
"locked": {
|
||||
"lastModified": 1731676054,
|
||||
"narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"devshell": "devshell",
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-parts": "flake-parts",
|
||||
"git-hooks-nix": "git-hooks-nix",
|
||||
"gitignore-nix": "gitignore-nix",
|
||||
"haumea": "haumea",
|
||||
"nixpkgs": [
|
||||
"nixpkgs-unstable"
|
||||
],
|
||||
"nixpkgs-unstable": "nixpkgs-unstable",
|
||||
"treefmt-nix": "treefmt-nix"
|
||||
}
|
||||
},
|
||||
"treefmt-nix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1730321837,
|
||||
"narHash": "sha256-vK+a09qq19QNu2MlLcvN4qcRctJbqWkX7ahgPZ/+maI=",
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"rev": "746901bb8dba96d154b66492a29f5db0693dbfcc",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
76
flake.nix
Normal file
76
flake.nix
Normal file
|
@ -0,0 +1,76 @@
|
|||
{
|
||||
description = "a collection of common nix expressions used by rebmit";
|
||||
|
||||
outputs =
|
||||
inputs@{ flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } (
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
selfLib = import ./lib { inherit inputs lib; };
|
||||
in
|
||||
{
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
];
|
||||
flake.lib = selfLib // {
|
||||
inherit (config) systems;
|
||||
};
|
||||
imports = [
|
||||
inputs.devshell.flakeModule
|
||||
inputs.git-hooks-nix.flakeModule
|
||||
inputs.treefmt-nix.flakeModule
|
||||
] ++ selfLib.path.buildModuleList ./flake;
|
||||
}
|
||||
);
|
||||
|
||||
inputs = {
|
||||
# flake-parts
|
||||
|
||||
flake-parts = {
|
||||
url = "github:hercules-ci/flake-parts";
|
||||
inputs.nixpkgs-lib.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
# nixpkgs
|
||||
|
||||
nixpkgs.follows = "nixpkgs-unstable";
|
||||
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
|
||||
# flake modules
|
||||
|
||||
devshell = {
|
||||
url = "github:numtide/devshell";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
git-hooks-nix = {
|
||||
url = "github:cachix/git-hooks.nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.nixpkgs-stable.follows = "nixpkgs";
|
||||
inputs.flake-compat.follows = "flake-compat";
|
||||
inputs.gitignore.follows = "gitignore-nix";
|
||||
};
|
||||
treefmt-nix = {
|
||||
url = "github:numtide/treefmt-nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
# libraries
|
||||
|
||||
gitignore-nix = {
|
||||
url = "github:hercules-ci/gitignore.nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
haumea = {
|
||||
url = "github:nix-community/haumea";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
# misc
|
||||
|
||||
flake-compat = {
|
||||
url = "github:edolstra/flake-compat";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
}
|
86
flake/modules/nixpkgs.nix
Normal file
86
flake/modules/nixpkgs.nix
Normal file
|
@ -0,0 +1,86 @@
|
|||
# Portions of this file are sourced from
|
||||
# https://github.com/linyinfeng/nur-packages/blob/73fea6901c19df2f480e734a75bc22dbabde3a53/flake-modules/nixpkgs.nix
|
||||
{
|
||||
inputs,
|
||||
flake-parts-lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (flake-parts-lib) mkPerSystemOption;
|
||||
in
|
||||
{
|
||||
options.perSystem = mkPerSystemOption (
|
||||
{
|
||||
config,
|
||||
system,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.nixpkgs;
|
||||
in
|
||||
with lib;
|
||||
{
|
||||
_file = ./nixpkgs.nix;
|
||||
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/default.nix
|
||||
options.nixpkgs = {
|
||||
path = mkOption {
|
||||
type = types.path;
|
||||
default = inputs.nixpkgs;
|
||||
defaultText = "inputs.nixpkgs";
|
||||
description = ''
|
||||
Path to nixpkgs to be imported.
|
||||
'';
|
||||
};
|
||||
localSystem = mkOption {
|
||||
type = types.attrs;
|
||||
default = {
|
||||
inherit system;
|
||||
};
|
||||
description = ''
|
||||
The system packages will be built on.
|
||||
'';
|
||||
};
|
||||
crossSystem = mkOption {
|
||||
type = with types; nullOr attrs;
|
||||
default = null;
|
||||
description = ''
|
||||
The system packages will ultimately be run on.
|
||||
'';
|
||||
};
|
||||
config = mkOption {
|
||||
type = with types; attrsOf raw;
|
||||
default = { };
|
||||
description = ''
|
||||
Allow a configuration attribute set to be passed in as an argument.
|
||||
'';
|
||||
};
|
||||
overlays = mkOption {
|
||||
type = with types; listOf raw;
|
||||
default = [ ];
|
||||
description = ''
|
||||
List of overlays layers used to extend Nixpkgs.
|
||||
'';
|
||||
};
|
||||
crossOverlays = mkOption {
|
||||
type = with types; listOf raw;
|
||||
default = [ ];
|
||||
description = ''
|
||||
List of overlays to apply to target packages only.
|
||||
'';
|
||||
};
|
||||
};
|
||||
config = {
|
||||
_module.args.pkgs = import cfg.path {
|
||||
inherit (cfg)
|
||||
localSystem
|
||||
crossSystem
|
||||
config
|
||||
overlays
|
||||
crossOverlays
|
||||
;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
9
flake/modules/passthru.nix
Normal file
9
flake/modules/passthru.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Portions of this file are sourced from
|
||||
# https://github.com/linyinfeng/nur-packages/blob/73fea6901c19df2f480e734a75bc22dbabde3a53/flake-modules/passthru.nix
|
||||
{ lib, ... }:
|
||||
{
|
||||
options.passthru = lib.mkOption {
|
||||
visible = false;
|
||||
type = with lib.types; attrsOf unspecified;
|
||||
};
|
||||
}
|
20
flake/outputs/devshell.nix
Normal file
20
flake/outputs/devshell.nix
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
perSystem =
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
devshells.default = {
|
||||
packages = with pkgs; [
|
||||
just
|
||||
];
|
||||
env = [
|
||||
(lib.nameValuePair "DEVSHELL_NO_MOTD" 1)
|
||||
];
|
||||
devshell.startup.pre-commit-hook.text = config.pre-commit.installationScript;
|
||||
};
|
||||
};
|
||||
}
|
9
flake/outputs/flake-module.nix
Normal file
9
flake/outputs/flake-module.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
{ self, ... }:
|
||||
let
|
||||
inherit (self.lib.path) buildModuleList;
|
||||
in
|
||||
{
|
||||
flake.flakeModule = {
|
||||
imports = buildModuleList ../modules;
|
||||
};
|
||||
}
|
29
flake/outputs/treefmt.nix
Normal file
29
flake/outputs/treefmt.nix
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
perSystem =
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
treefmt = {
|
||||
projectRootFile = "flake.nix";
|
||||
programs = {
|
||||
nixfmt.enable = true;
|
||||
deadnix.enable = true;
|
||||
prettier.enable = true;
|
||||
};
|
||||
};
|
||||
|
||||
devshells.default.packages = lib.singleton config.treefmt.build.wrapper;
|
||||
|
||||
pre-commit.settings.hooks = {
|
||||
treefmt = {
|
||||
enable = true;
|
||||
name = "treefmt";
|
||||
entry = lib.getExe config.treefmt.build.wrapper;
|
||||
pass_filenames = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
9
justfile
Normal file
9
justfile
Normal file
|
@ -0,0 +1,9 @@
|
|||
set shell := ["bash", "-c"]
|
||||
|
||||
[group('nix')]
|
||||
up:
|
||||
nix flake update
|
||||
|
||||
[group('nix')]
|
||||
upp input:
|
||||
nix flake lock --update-input {{input}}
|
14
lib/default.nix
Normal file
14
lib/default.nix
Normal file
|
@ -0,0 +1,14 @@
|
|||
{ inputs, lib }:
|
||||
let
|
||||
inherit (lib) makeExtensible;
|
||||
self = makeExtensible (
|
||||
self:
|
||||
let
|
||||
callLibs = file: import file { inherit inputs lib self; };
|
||||
in
|
||||
{
|
||||
path = callLibs ./path.nix;
|
||||
}
|
||||
);
|
||||
in
|
||||
self
|
42
lib/path.nix
Normal file
42
lib/path.nix
Normal file
|
@ -0,0 +1,42 @@
|
|||
# Portions of this file are sourced from
|
||||
# https://github.com/linyinfeng/dotfiles/tree/b618b0fd16fb9c79ab7199ed51c4c0f98a392cea/lib
|
||||
{
|
||||
inputs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
haumea = inputs.haumea.lib;
|
||||
|
||||
rakeLeaves =
|
||||
src:
|
||||
haumea.load {
|
||||
inherit src;
|
||||
loader = haumea.loaders.path;
|
||||
transformer =
|
||||
_cursor: dir:
|
||||
if dir ? default then
|
||||
assert (lib.attrNames dir == [ "default" ]);
|
||||
dir.default
|
||||
else
|
||||
dir;
|
||||
};
|
||||
|
||||
flattenTree =
|
||||
tree:
|
||||
let
|
||||
mkNewPrefix = prefix: name: "${if prefix == "" then "" else "${prefix}/"}${name}";
|
||||
flattenTree' =
|
||||
prefix: remain:
|
||||
if lib.isAttrs remain then
|
||||
lib.flatten (lib.mapAttrsToList (name: value: flattenTree' (mkNewPrefix prefix name) value) remain)
|
||||
else
|
||||
[ (lib.nameValuePair prefix remain) ];
|
||||
in
|
||||
lib.listToAttrs (flattenTree' "" tree);
|
||||
|
||||
buildModuleList = dir: lib.attrValues (flattenTree (rakeLeaves dir));
|
||||
in
|
||||
{
|
||||
inherit rakeLeaves flattenTree buildModuleList;
|
||||
}
|
Loading…
Reference in a new issue