feat(flake-parts)!: refactor to flake-parts

This commit is contained in:
winston 2023-06-14 03:09:32 +02:00
parent 5a509b5555
commit a1b282277e
Signed by: winston
GPG key ID: 3786770EDBC2B481
3 changed files with 205 additions and 144 deletions

View file

@ -7,17 +7,16 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1685836117, "lastModified": 1686575758,
"narHash": "sha256-Z1MECnYm0qznV7khdtDR2wnQgVsX/+gc716ztjtSRWU=", "narHash": "sha256-m2eeo5ClbunNt9DUXCyNyNDuH0rOZ1Xb/Njqb+zp8G0=",
"owner": "nekowinston", "owner": "caarlos0",
"repo": "caarlos0-nur", "repo": "nur",
"rev": "7494c6ec1eb21b722ef0f131fa2afa0e80e0b81a", "rev": "c87e77a4bc47b291d4f5c551dbbef52f27e13425",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nekowinston", "owner": "caarlos0",
"ref": "feat/add-apple-music-discord-module", "repo": "nur",
"repo": "caarlos0-nur",
"type": "github" "type": "github"
} }
}, },
@ -114,6 +113,24 @@
"type": "github" "type": "github"
} }
}, },
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1685662779,
"narHash": "sha256-cKDDciXGpMEjP1n6HlzKinN0H+oLmNpgeCTzYnsA2po=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "71fb97f0d875fd4de4994dfb849f2c75e17eb6c3",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-utils": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems" "systems": "systems"
@ -178,11 +195,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1686604884, "lastModified": 1686693747,
"narHash": "sha256-AkfxSmGGvNMtyXt1us9Lm8cMeIwqxpkSTeNeBQ00SL8=", "narHash": "sha256-pf0rcQeKejsBfv6NPZCXAo1gN2XtRYm2jzRwHswYeEc=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "b01eb1eb3b579c74e6a4189ef33cc3fa24c40613", "rev": "62f111ef1e50e518dbb3f0782a31dcd244a0a2d7",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -198,11 +215,11 @@
"wezterm-src": "wezterm-src" "wezterm-src": "wezterm-src"
}, },
"locked": { "locked": {
"lastModified": 1686553559, "lastModified": 1686643608,
"narHash": "sha256-3GpWAkqKzo2L1WO4e9iWom8CxpompgH6le5tP1KG80o=", "narHash": "sha256-rnUWWZF5gA+sI1pNZ+xJfyzBYsJ2mbgln4FAtgxmir4=",
"owner": "nekowinston", "owner": "nekowinston",
"repo": "nur", "repo": "nur",
"rev": "69fef37c252ac8c21aaf4192e1b7d1b87a525054", "rev": "da20835c7211634852f2617c93d167eae45d9aeb",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -218,11 +235,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1686574167, "lastModified": 1686671165,
"narHash": "sha256-hxE8z+S9E4Qw03D2VQRaJUmj9zep3FvhKz316JUZuPA=", "narHash": "sha256-q3Poq8FlulxDMCETXL0ehb9J3h5Naf5yGh1x42RXXRI=",
"owner": "Mic92", "owner": "Mic92",
"repo": "nix-index-database", "repo": "nix-index-database",
"rev": "7e83b70f31f4483c07e6939166cb667ecb8d05d5", "rev": "14eede9450dc45b92adc9f1dfac873eac7e1a5de",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -233,11 +250,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1686488075, "lastModified": 1686519857,
"narHash": "sha256-2otSBt2hbeD+5yY25NF3RhWx7l5SDt1aeU3cJ/9My4M=", "narHash": "sha256-VkBhuq67aXXiCoEmicziuDLUPPjeOTLQoj6OeVai5zM=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9401a0c780b49faf6c28adf55764f230301d0dce", "rev": "6b1b72c0f887a478a5aac355674ff6df0fc44f44",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -247,13 +264,31 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-lib": {
"locked": {
"dir": "lib",
"lastModified": 1685564631,
"narHash": "sha256-8ywr3AkblY4++3lIVxmrWZFzac7+f32ZEhH/A8pNscI=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4f53efe34b3a8877ac923b9350c874e3dcd5dc0a",
"type": "github"
},
"original": {
"dir": "lib",
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1686519857, "lastModified": 1686582075,
"narHash": "sha256-VkBhuq67aXXiCoEmicziuDLUPPjeOTLQoj6OeVai5zM=", "narHash": "sha256-vtflsfKkHtF8IduxDNtbme4cojiqvlvjp5QNYhvoHXc=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "6b1b72c0f887a478a5aac355674ff6df0fc44f44", "rev": "7e63eed145566cca98158613f3700515b4009ce3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -265,11 +300,11 @@
}, },
"nur": { "nur": {
"locked": { "locked": {
"lastModified": 1686634533, "lastModified": 1686696247,
"narHash": "sha256-YszZkcJfhQL3m2zBNT8hLpA+DNCcVxSHK2/3jNa9EMY=", "narHash": "sha256-gZL5rk1iySrvKbdw8NU5BaSDWuWA5O7ZWw+j+vxXjc4=",
"owner": "nix-community", "owner": "nix-community",
"repo": "nur", "repo": "nur",
"rev": "875deba73f2360a885d1b81c3d88218bce4c1230", "rev": "c3677b051af4921de6e184749035d08859e4ed62",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -293,11 +328,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1686213770, "lastModified": 1686668298,
"narHash": "sha256-Re6xXLEqQ/HRnThryumyGzEf3Uv0Pl4cuG50MrDofP8=", "narHash": "sha256-AADh9NqHh6X2LOem4BvI7oCkMm+JPCSCE7iIw5nn0VA=",
"owner": "cachix", "owner": "cachix",
"repo": "pre-commit-hooks.nix", "repo": "pre-commit-hooks.nix",
"rev": "182af51202998af5b64ddecaa7ff9be06425399b", "rev": "5b6b54d3f722aa95cbf4ddbe35390a0af8c0015a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -310,6 +345,7 @@
"inputs": { "inputs": {
"caarlos0-nur": "caarlos0-nur", "caarlos0-nur": "caarlos0-nur",
"darwin": "darwin", "darwin": "darwin",
"flake-parts": "flake-parts",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"home-manager": "home-manager", "home-manager": "home-manager",
"nekowinston-nur": "nekowinston-nur", "nekowinston-nur": "nekowinston-nur",
@ -425,11 +461,11 @@
"wezterm-src": { "wezterm-src": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1685453249, "lastModified": 1686577193,
"narHash": "sha256-w/iQoWng7nrE+HAg0umpq8RCU0bjw5JogR2HHufspI8=", "narHash": "sha256-9dCCT3Nd6XAZBKIlbqKQZj8ruUudtwcbd3CYJIK9Dl8=",
"ref": "refs/heads/main", "ref": "refs/heads/main",
"rev": "95e44f2199d9779e353bccf387a1eb2dbaf41f44", "rev": "baf9d970816e015bee41ed5eb9186ef7f71c454c",
"revCount": 7255, "revCount": 7256,
"submodules": true, "submodules": true,
"type": "git", "type": "git",
"url": "https://github.com/wez/wezterm" "url": "https://github.com/wez/wezterm"

170
flake.nix
View file

@ -8,10 +8,9 @@
home-manager.url = "github:nix-community/home-manager"; home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs"; home-manager.inputs.nixpkgs.follows = "nixpkgs";
# NUR
nur.url = "github:nix-community/nur"; nur.url = "github:nix-community/nur";
nekowinston-nur.url = "github:nekowinston/nur"; nekowinston-nur.url = "github:nekowinston/nur";
caarlos0-nur.url = "github:nekowinston/caarlos0-nur/feat/add-apple-music-discord-module"; caarlos0-nur.url = "github:caarlos0/nur";
caarlos0-nur.inputs.nixpkgs.follows = "nixpkgs"; caarlos0-nur.inputs.nixpkgs.follows = "nixpkgs";
sops.url = "github:Mic92/sops-nix"; sops.url = "github:Mic92/sops-nix";
@ -28,6 +27,64 @@
pre-commit-hooks.inputs.flake-utils.follows = "flake-utils"; pre-commit-hooks.inputs.flake-utils.follows = "flake-utils";
pre-commit-hooks.inputs.nixpkgs-stable.follows = "nixpkgs"; pre-commit-hooks.inputs.nixpkgs-stable.follows = "nixpkgs";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs = {flake-parts, ...} @ inputs: let
inherit (import ./lib {inherit inputs;}) mkSystems overlays;
in
flake-parts.lib.mkFlake {inherit inputs;}
{
systems = ["aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux"];
flake = mkSystems [
{
host = "sashimi";
system = "aarch64-darwin";
username = "winston";
}
{
host = "futomaki";
system = "x86_64-linux";
username = "winston";
}
{
host = "bento";
system = "x86_64-linux";
username = "w";
}
];
perSystem = {
config,
self',
inputs',
pkgs,
system,
...
}: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [overlays];
};
checks.pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
alejandra.enable = true;
commitizen.enable = true;
editorconfig-checker.enable = true;
luacheck.enable = true;
nil.enable = true;
shellcheck.enable = true;
stylua.enable = true;
};
};
devShells.default = pkgs.mkShell {
name = "nixpkgs";
inherit (self'.checks.pre-commit-check) shellHook;
nativeBuildInputs = with pkgs; [git-crypt just sops];
};
};
}; };
nixConfig = { nixConfig = {
@ -49,113 +106,4 @@
tarball-ttl = 604800; tarball-ttl = 604800;
warn-dirty = false; warn-dirty = false;
}; };
outputs = {
self,
darwin,
home-manager,
nixpkgs,
...
} @ inputs: let
overlays = final: prev: {
nur = import inputs.nur {
nurpkgs = prev;
pkgs = prev;
repoOverrides = {
caarlos0 = inputs.caarlos0-nur.packages.${prev.system};
nekowinston = inputs.nekowinston-nur.packages.${prev.system};
};
};
sway-unwrapped = inputs.swayfx.packages.${prev.system}.default;
};
commonHMConfig = {username}: ({
config,
pkgs,
...
}: {
config = {
nixpkgs.overlays = [overlays];
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
backupFileExtension = "backup";
sharedModules = [
inputs.nix-index-database.hmModules.nix-index
inputs.sops.homeManagerModules.sops
inputs.caarlos0-nur.homeManagerModules.default
inputs.nekowinston-nur.homeManagerModules.default
];
users.${username}.imports = [./home];
extraSpecialArgs = {
flakePath =
if pkgs.stdenv.isDarwin
then "/Users/${username}/.config/nixpkgs"
else "/home/${username}/.config/nixpkgs";
};
};
};
});
in
{
nixosConfigurations = {
"futomaki" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
home-manager.nixosModules.home-manager
./machines/common
./machines/futomaki
(commonHMConfig {
username = "winston";
})
];
};
"bento" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
home-manager.nixosModules.home-manager
./machines/common
./machines/bento
(commonHMConfig {
username = "w";
})
];
};
};
darwinConfigurations = {
"sashimi" = darwin.lib.darwinSystem {
system = "aarch64-darwin";
modules = [
home-manager.darwinModules.home-manager
inputs.nekowinston-nur.darwinModules.default
./machines/common
./machines/sashimi
(commonHMConfig {
username = "winston";
})
];
};
};
}
// inputs.flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
checks.pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
alejandra.enable = true;
commitizen.enable = true;
editorconfig-checker.enable = true;
luacheck.enable = true;
nil.enable = true;
shellcheck.enable = true;
stylua.enable = true;
};
};
devShells.default = pkgs.mkShell {
name = "nixpkgs";
inherit (self.checks.${system}.pre-commit-check) shellHook;
nativeBuildInputs = [pkgs.just pkgs.git-crypt pkgs.sops];
};
formatter = pkgs.alejandra;
});
} }

77
lib/default.nix Normal file
View file

@ -0,0 +1,77 @@
{inputs}: rec {
overlays = final: prev: {
nur = import inputs.nur {
nurpkgs = prev;
pkgs = prev;
repoOverrides = {
caarlos0 = inputs.caarlos0-nur.packages.${prev.system};
nekowinston = inputs.nekowinston-nur.packages.${prev.system};
};
};
sway-unwrapped = inputs.swayfx.packages.${prev.system}.default;
};
commonHMConfig = {username}: ({
config,
pkgs,
...
}: {
config = {
nixpkgs.overlays = [overlays];
home-manager = {
backupFileExtension = "backup";
useGlobalPkgs = true;
useUserPackages = true;
sharedModules = with inputs; [
nix-index-database.hmModules.nix-index
sops.homeManagerModules.sops
caarlos0-nur.homeManagerModules.default
nekowinston-nur.homeManagerModules.default
];
users.${username}.imports = [../home];
extraSpecialArgs = {
flakePath =
if pkgs.stdenv.isDarwin
then "/Users/${username}/.config/nixpkgs"
else "/home/${username}/.config/nixpkgs";
};
};
};
});
mkMerge = contents: {
_type = "merge";
inherit contents;
};
mkSystem = {
host,
system,
username,
extraModules ? [],
}: let
target =
if isLinux
then "nixosConfigurations"
else if isDarwin
then "darwinConfigurations"
else throw "Unsupported system";
builder =
if isLinux
then inputs.nixpkgs.lib.nixosSystem
else if isDarwin
then inputs.darwin.lib.darwinSystem
else throw "Unsupported system";
pkgs = inputs.nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
inherit (pkgs.stdenv) isLinux isDarwin;
in {
${target}."${host}" = builder {
inherit system;
modules =
[../machines/common ../machines/${host}]
++ lib.optionals isLinux [inputs.home-manager.nixosModules.home-manager]
++ lib.optionals isDarwin [inputs.home-manager.darwinModules.home-manager]
++ [(commonHMConfig {inherit username;})]
++ extraModules;
};
};
mkSystems = systems: mkMerge (map mkSystem systems);
}