commit 8dd5ce867a2d2df86b81ec79c1d5d1ee755adfdd Author: Artur Manuel Date: Wed Oct 16 00:03:53 2024 +0100 repo: init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0638531 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +**/*~ +**/#*.*# +**/.#*.* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 120000 index 0000000..cdb3817 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1 @@ +/nix/store/sx8gsjr4a1vn2afc5ii2m2d0g4ksngn8-pre-commit-config.json \ No newline at end of file diff --git a/computers/default.nix b/computers/default.nix new file mode 100644 index 0000000..1a280f4 --- /dev/null +++ b/computers/default.nix @@ -0,0 +1,11 @@ +{lib, ...}: { + flake = { + nixosConfigurations = lib.mkComputers { + toothless = { + system = "x86_64-linux"; + user = "artur"; + }; + }; + nixosModules.default = ./shared; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8e7a50a --- /dev/null +++ b/flake.lock @@ -0,0 +1,139 @@ +{ + "nodes": { + "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": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "git-hooks-nix": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1728778939, + "narHash": "sha256-WybK5E3hpGxtCYtBwpRj1E9JoiVxe+8kX83snTNaFHE=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "ff68f91754be6f3427e4986d7949e6273659be1d", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks-nix", + "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" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1719082008, + "narHash": "sha256-jHJSUH619zBQ6WdC21fFAlDxHErKVDJ5fpN0Hgx4sjs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9693852a2070b398ee123a329e68f0dab5526681", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1728888510, + "narHash": "sha256-nsNdSldaAyu6PE3YUA+YQLqUDJh+gRbBooMMekZJwvI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "git-hooks-nix": "git-hooks-nix", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0fb6d14 --- /dev/null +++ b/flake.nix @@ -0,0 +1,61 @@ +{ + description = "Alqueva is the largest lake in Portugal."; + inputs = { + nixpkgs = { + type = "github"; + owner = "nixos"; + repo = "nixpkgs"; + ref = "nixos-unstable"; + }; + flake-parts = { + type = "github"; + owner = "hercules-ci"; + repo = "flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + git-hooks-nix = { + type = "github"; + owner = "cachix"; + repo = "git-hooks.nix"; + }; + }; + outputs = inputs @ { + nixpkgs, + flake-parts, + ... + }: let + lib = nixpkgs.lib.extend (import ./lib {inherit inputs;}); + in + flake-parts.lib.mkFlake { + inherit inputs; + specialArgs = {inherit lib;}; + } { + systems = ["x86_64-linux"]; + imports = [ + ./computers + inputs.git-hooks-nix.flakeModule + ]; + perSystem = { + config, + pkgs, + ... + }: { + pre-commit = { + check.enable = true; + settings.hooks = { + alejandra.enable = true; + deadnix = { + enable = true; + args = ["-e"]; + }; + statix = { + enable = true; + args = ["fix"]; + }; + }; + }; + devShells.default = config.pre-commit.devShell; + formatter = pkgs.alejandra; + }; + }; +} diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..047f7d0 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,59 @@ +{inputs}: _: _: let + mkComputer = { + host, + system, + user, + extraModules ? [], + }: + inputs.nixpkgs.lib.nixosSystem { + inherit system; + modules = + extraModules + ++ [ + ./computers/${host} + ({config, ...}: { + config = { + nix = { + settings.extra-experimental-features = [ + "nix-command" + "flakes" + ]; + gc = { + automatic = true; + dates = "weekly"; + }; + }; + programs.fish = { + vendor = { + functions.enable = true; + config.enable = true; + completions.enable = true; + }; + enable = true; + }; + users = { + users.${user} = { + isNormalUser = true; + useDefaultShell = true; + initialPassword = "password"; + extraGroups = ["wheel" "networkmanager" "video" "audio" "input" "libvirtd"]; + name = user; + }; + defaultUserShell = config.programs.fish.package; + }; + environment.shellAliases = { + rebs = "nixos-rebuild --use-remote-sudo switch --flake .#${host}"; + rebt = "nixos-rebuild --use-remote-sudo test --flake .#${host}"; + }; + networking.hostName = host; + }; + }) + ]; + specialArgs = { + inherit inputs; + inherit (inputs) self; + }; + }; +in { + mkComputers = computers: builtins.mapAttrs (n: v: mkComputer (v // {host = n;})) computers; +}