From c74a3611c986e78fc48514fd46b28d37eec7bd8d Mon Sep 17 00:00:00 2001 From: pegasust Date: Tue, 30 Aug 2022 14:29:44 +0000 Subject: [PATCH 1/7] initial commit --- README.md | 7 + devel/configuration.nix | 49 +++++ devel/flake.lock | 26 +++ devel/flake.nix | 14 ++ devel/nixos-wsl/.envrc | 7 + .../.github/ISSUE_TEMPLATE/bug_report.md | 26 +++ .../.github/ISSUE_TEMPLATE/feature_request.md | 16 ++ devel/nixos-wsl/.github/release-drafter.yml | 17 ++ devel/nixos-wsl/.github/workflows/main.yml | 78 +++++++ .../.github/workflows/release-drafter.yml | 19 ++ .../.github/workflows/update-flakes.yml | 50 +++++ devel/nixos-wsl/.gitignore | 2 + devel/nixos-wsl/LICENSE | 202 ++++++++++++++++++ devel/nixos-wsl/README.md | 112 ++++++++++ devel/nixos-wsl/default.nix | 13 ++ devel/nixos-wsl/flake.lock | 59 +++++ devel/nixos-wsl/flake.nix | 56 +++++ devel/nixos-wsl/modules/build-tarball.nix | 97 +++++++++ devel/nixos-wsl/modules/docker-desktop.nix | 41 ++++ devel/nixos-wsl/modules/docker-native.nix | 40 ++++ devel/nixos-wsl/modules/installer.nix | 73 +++++++ devel/nixos-wsl/modules/interop.nix | 88 ++++++++ devel/nixos-wsl/modules/wsl-distro.nix | 139 ++++++++++++ devel/nixos-wsl/syschdemd.nix | 28 +++ devel/nixos-wsl/syschdemd.sh | 78 +++++++ 25 files changed, 1337 insertions(+) create mode 100644 README.md create mode 100755 devel/configuration.nix create mode 100644 devel/flake.lock create mode 100644 devel/flake.nix create mode 100644 devel/nixos-wsl/.envrc create mode 100644 devel/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md create mode 100644 devel/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md create mode 100644 devel/nixos-wsl/.github/release-drafter.yml create mode 100644 devel/nixos-wsl/.github/workflows/main.yml create mode 100644 devel/nixos-wsl/.github/workflows/release-drafter.yml create mode 100644 devel/nixos-wsl/.github/workflows/update-flakes.yml create mode 100644 devel/nixos-wsl/.gitignore create mode 100644 devel/nixos-wsl/LICENSE create mode 100644 devel/nixos-wsl/README.md create mode 100644 devel/nixos-wsl/default.nix create mode 100644 devel/nixos-wsl/flake.lock create mode 100644 devel/nixos-wsl/flake.nix create mode 100644 devel/nixos-wsl/modules/build-tarball.nix create mode 100644 devel/nixos-wsl/modules/docker-desktop.nix create mode 100644 devel/nixos-wsl/modules/docker-native.nix create mode 100644 devel/nixos-wsl/modules/installer.nix create mode 100644 devel/nixos-wsl/modules/interop.nix create mode 100644 devel/nixos-wsl/modules/wsl-distro.nix create mode 100644 devel/nixos-wsl/syschdemd.nix create mode 100644 devel/nixos-wsl/syschdemd.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc84144 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Nix + +Monorepo that contains my commonly used personal environments. +I hope to incorporate my configs at [gh:pegasust/dotfiles](https://github.com/pegasust/dotfiles) +onto this repo for quick env setup (especially devel) on new machines. + + diff --git a/devel/configuration.nix b/devel/configuration.nix new file mode 100755 index 0000000..06363b6 --- /dev/null +++ b/devel/configuration.nix @@ -0,0 +1,49 @@ +{ lib, pkgs, config, modulesPath, ... }: + +with lib; +let + nixos-wsl = import ./nixos-wsl; +in +{ + imports = [ + "${modulesPath}/profiles/minimal.nix" + + nixos-wsl.nixosModules.wsl + ]; + + wsl = { + enable = true; + automountPath = "/mnt"; + defaultUser = "nixos"; # if change defaultUser, make sure uid to be 1000 (first user) + startMenuLaunchers = true; + + # Enable native Docker support + # docker-native.enable = true; + + # Enable integration with Docker Desktop (needs to be installed) + docker-desktop.enable = true; + + }; + # users.users..uid = 1000; + + # Enable nix flakes + nix.package = pkgs.nixFlakes; + nix.extraOptions = '' + experimental-features = nix-command flakes + ''; + + programs.neovim = { + enable = true; + defaultEditor = true; + }; + programs.git = { + enable = true; + # more information should be configured under user level + }; + networking.hostName = "nixos"; + system.stateVersion = "22.05"; + + environment.systemPackages = [ + pkgs.gnumake + ]; +} diff --git a/devel/flake.lock b/devel/flake.lock new file mode 100644 index 0000000..9b5c68b --- /dev/null +++ b/devel/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1661328374, + "narHash": "sha256-GGMupfk/lGzPBQ/dRrcQEhiFZ0F5KPg0j5Q4Fb5coxc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f034b5693a26625f56068af983ed7727a60b5f8b", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/devel/flake.nix b/devel/flake.nix new file mode 100644 index 0000000..83907ed --- /dev/null +++ b/devel/flake.nix @@ -0,0 +1,14 @@ +{ + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs, ... }: { + nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + ]; + }; + }; +} diff --git a/devel/nixos-wsl/.envrc b/devel/nixos-wsl/.envrc new file mode 100644 index 0000000..c4f5ea4 --- /dev/null +++ b/devel/nixos-wsl/.envrc @@ -0,0 +1,7 @@ +use_flake() { + watch_file flake.nix + watch_file flake.lock + eval "$(nix print-dev-env)" +} + +use flake diff --git a/devel/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md b/devel/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..44e58a0 --- /dev/null +++ b/devel/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,26 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + + + +## Bug description + + +## To Reproduce +Steps to reproduce the behavior: + +**Expected behavior** + + +## Logs +``` +Include relevant console logs +``` + + diff --git a/devel/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md b/devel/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..a5173eb --- /dev/null +++ b/devel/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,16 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + + + +## Problem + + +## Solution + diff --git a/devel/nixos-wsl/.github/release-drafter.yml b/devel/nixos-wsl/.github/release-drafter.yml new file mode 100644 index 0000000..b798c14 --- /dev/null +++ b/devel/nixos-wsl/.github/release-drafter.yml @@ -0,0 +1,17 @@ +change-template: "* $TITLE (#$NUMBER) @$AUTHOR" +categories: + - title: 'πŸš€ Features' + labels: + - enhancement + - title: "πŸͺ² Bugfixes" + labels: + - bug + - title: "πŸ“– Documentation" + labels: + - documentation +template: | + # Changelog + + ## πŸ› οΈ General Changes + + $CHANGES diff --git a/devel/nixos-wsl/.github/workflows/main.yml b/devel/nixos-wsl/.github/workflows/main.yml new file mode 100644 index 0000000..c61332e --- /dev/null +++ b/devel/nixos-wsl/.github/workflows/main.yml @@ -0,0 +1,78 @@ +name: 'Build NixOS WSL tarball' + +on: [push, pull_request, release] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + # Nix Flakes doesn't work on shallow clones + fetch-depth: 0 + + - name: Install nix + uses: cachix/install-nix-action@v12 + with: + install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-2.4pre20201221_9fab14a/install + # Configure Nix to enable flakes + extra_nix_config: | + experimental-features = nix-command flakes + + - name: Run checks + run: | + nix flake check + + - name: Build tarball + run: | + nix build '.#nixosConfigurations.mysystem.config.system.build.tarball' + + - name: Upload tarball + uses: actions/upload-artifact@v2 + with: + name: rootfs + path: result/tarball/nixos-wsl-x86_64-linux.tar.gz + + - name: Build installer + run: | + nix build '.#nixosConfigurations.mysystem.config.system.build.installer' + + - name: Upload installer + uses: actions/upload-artifact@v2 + with: + name: installer + path: result/tarball/nixos-wsl-installer.tar.gz + + release: + if: startsWith(github.ref, 'refs/tags/') + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - uses: actions/download-artifact@v2 + with: + name: rootfs + + - uses: actions/download-artifact@v2 + with: + name: installer + + - name: Generate checksums + run: | + for x in *.tar.gz; do + sha256sum $x > ${x}.sha256 + done + + - name: Attach to release + uses: softprops/action-gh-release@v1 + with: + files: | + nixos-wsl-x86_64-linux.tar.gz + nixos-wsl-x86_64-linux.tar.gz.sha256 + nixos-wsl-installer.tar.gz + nixos-wsl-installer.tar.gz.sha256 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/devel/nixos-wsl/.github/workflows/release-drafter.yml b/devel/nixos-wsl/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..cade7c0 --- /dev/null +++ b/devel/nixos-wsl/.github/workflows/release-drafter.yml @@ -0,0 +1,19 @@ +name: Release Drafter + +on: + push: + branches: + - main + pull_request: + types: + - opened + - reopened + - synchronize + - +jobs: + update_release_draft: + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/devel/nixos-wsl/.github/workflows/update-flakes.yml b/devel/nixos-wsl/.github/workflows/update-flakes.yml new file mode 100644 index 0000000..6d1b68f --- /dev/null +++ b/devel/nixos-wsl/.github/workflows/update-flakes.yml @@ -0,0 +1,50 @@ +name: 'Update flakes' + +on: + workflow_dispatch: + schedule: + - cron: '0 2 * * 0' + +jobs: + update-flakes: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + # Nix Flakes doesn't work on shallow clones + fetch-depth: 0 + + - name: Install nix + uses: cachix/install-nix-action@v12 + with: + install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-2.4pre20201221_9fab14a/install + # Configure Nix to enable flakes + extra_nix_config: | + experimental-features = nix-command flakes + + - name: Update flakes + run: nix flake update --recreate-lock-file + + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v3 + with: + commit-message: Update flakes + committer: GitHub + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + signoff: false + branch: flake-updates + delete-branch: true + title: 'Update flakes' + body: | + Update report + - Updated with *today's* date + - Auto-generated by [create-pull-request][1] + + [1]: https://github.com/peter-evans/create-pull-request + + - name: Check outputs + run: | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" diff --git a/devel/nixos-wsl/.gitignore b/devel/nixos-wsl/.gitignore new file mode 100644 index 0000000..750baeb --- /dev/null +++ b/devel/nixos-wsl/.gitignore @@ -0,0 +1,2 @@ +result +result-* diff --git a/devel/nixos-wsl/LICENSE b/devel/nixos-wsl/LICENSE new file mode 100644 index 0000000..ef51da2 --- /dev/null +++ b/devel/nixos-wsl/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/devel/nixos-wsl/README.md b/devel/nixos-wsl/README.md new file mode 100644 index 0000000..b3a4ff9 --- /dev/null +++ b/devel/nixos-wsl/README.md @@ -0,0 +1,112 @@ +

+ NixOS on WSL
+ Matrix Chat + nixpkgs 22.05 + Downloads +

+ +A minimal root filesystem for running NixOS on WSL. It can be used with +[DistroLauncher](https://github.com/microsoft/WSL-DistroLauncher) as +`install.tar.gz` or as input to `wsl --import --version 2`. + +## Quick start + +First, [download the latest release\'s installer](https://github.com/nix-community/NixOS-WSL/releases/latest). + +Then open up a Terminal, PowerShell or Command Prompt and run: + +```sh +wsl --import NixOS .\NixOS\ nixos-wsl-installer.tar.gz --version 2 +``` + +This sets up a new WSL distribution `NixOS` that is installed under +`.\NixOS`. `nixos-wsl-installer.tar.gz` is the path to the file you +downloaded earlier. You might need to change this path or change to the download directory first. + +You can now run NixOS: + +```sh +wsl -d NixOS +``` + +The installer will unpack the file system and subsequently start NixOS. +A few warnings about file systems and locales will pop up. You can +safely ignore them. After systemd has started, you should be greeted +with a bash prompt inside your fresh NixOS installation. + +If you want to make NixOS your default distribution, you can do so with + +```sh +wsl -s NixOS +``` + +## Building your own system tarball + +This requires access to a system that already has Nix installed. Please refer to the [Nix installation guide](https://nixos.org/guides/install-nix.html) if that\'s not the case. + +If you have a flakes-enabled Nix, you can use the following command to +build your own tarball instead of relying on a prebuilt one: + +```cmd +nix build github:nix-community/NixOS-WSL#nixosConfigurations.mysystem.config.system.build.installer +``` + +Or, if you want to build with local changes, run inside your checkout: + +```cmd +nix build .#nixosConfigurations.mysystem.config.system.build.installer +``` + +Without a flakes-enabled Nix, you can build a tarball using: + +```cmd +nix-build -A nixosConfigurations.mysystem.config.system.build.installer +``` + +The resulting installer tarball can then be found under +`./result/tarball/nixos-wsl-installer.tar.gz`. + +You can also build a rootfs tarball without wrapping it in the installer +by replacing `installer` with `tarball` in the above commands. The +rootfs tarball can then be found under +`./result/tarball/nixos-wsl-x86_64-linux.tar.gz`. + +## Design + +Getting NixOS to run under WSL requires some workarounds: + +### systemd support + +WSL comes with its own (non-substitutable) init system while NixOS uses +systemd. Simply starting systemd later on does not work out of the box, +because systemd as system instance refuses to start if it is not PID 1. +This unfortunate combination is resolved in two ways: + +- the user\'s default shell is replaced by a wrapper script that acts + is init system and then drops to the actual shell +- systemd is started in its own PID namespace; therefore, it is PID 1. + The shell wrapper (see above) enters the systemd namespace before + dropping to the shell. + +### Installer + +Usually WSL distributions ship as a tarball of their root file system. +These tarballs however, can not contain any hard-links due to the way +they are unpacked by WSL, resulting in an \"Unspecified Error\". By +default some Nix-derivations will contain hard-links when they are +built. This results in system tarballs that can not be imported into +WSL. To circumvent this problem, the rootfs tarball is wrapped in that +of a minimal distribution (the installer), that is packaged without any +hard-links. When the installer system is started for the first time, it +overwrites itself with the contents of the rootfs tarball. + +## License + +Apache License, Version 2.0. See `LICENSE` or for details. + +## Further links + +- [DistroLauncher](https://github.com/microsoft/WSL-DistroLauncher) +- [A quick way into a systemd \"bottle\" for WSL](https://github.com/arkane-systems/genie) +- [NixOS in Windows Store for Windows Subsystem for Linux](https://github.com/NixOS/nixpkgs/issues/30391) +- [wsl2-hacks](https://github.com/shayne/wsl2-hacks) diff --git a/devel/nixos-wsl/default.nix b/devel/nixos-wsl/default.nix new file mode 100644 index 0000000..873ece4 --- /dev/null +++ b/devel/nixos-wsl/default.nix @@ -0,0 +1,13 @@ +(import + ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { + src = ./.; + }).defaultNix diff --git a/devel/nixos-wsl/flake.lock b/devel/nixos-wsl/flake.lock new file mode 100644 index 0000000..ba649f6 --- /dev/null +++ b/devel/nixos-wsl/flake.lock @@ -0,0 +1,59 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1660318005, + "narHash": "sha256-g9WCa9lVUmOV6dYRbEPjv/TLOR5hamjeCcKExVGS3OQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5c211b47aeadcc178c5320afd4e74c7eed5c389f", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-22.05", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/devel/nixos-wsl/flake.nix b/devel/nixos-wsl/flake.nix new file mode 100644 index 0000000..8a62b47 --- /dev/null +++ b/devel/nixos-wsl/flake.nix @@ -0,0 +1,56 @@ +{ + description = "NixOS WSL"; + + inputs = { + nixpkgs.url = "nixpkgs/nixos-22.05"; + flake-utils.url = "github:numtide/flake-utils"; + + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + { + + nixosModules.wsl = { + imports = [ + ./modules/build-tarball.nix + ./modules/docker-desktop.nix + ./modules/docker-native.nix + ./modules/installer.nix + ./modules/interop.nix + ./modules/wsl-distro.nix + ]; + }; + + nixosConfigurations.mysystem = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + ]; + }; + + } // + flake-utils.lib.eachSystem + (with flake-utils.lib.system; [ "x86_64-linux" "aarch64-linux" ]) + (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + checks.check-format = pkgs.runCommand "check-format" + { + buildInputs = with pkgs; [ nixpkgs-fmt ]; + } '' + nixpkgs-fmt --check ${./.} + mkdir $out # success + ''; + + devShell = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ nixpkgs-fmt ]; + }; + } + ); +} diff --git a/devel/nixos-wsl/modules/build-tarball.nix b/devel/nixos-wsl/modules/build-tarball.nix new file mode 100644 index 0000000..feba78d --- /dev/null +++ b/devel/nixos-wsl/modules/build-tarball.nix @@ -0,0 +1,97 @@ +{ config, pkgs, lib, ... }: +with builtins; with lib; +let + pkgs2storeContents = l: map (x: { object = x; symlink = "none"; }) l; + + nixpkgs = lib.cleanSource pkgs.path; + + channelSources = pkgs.runCommand "nixos-${config.system.nixos.version}" + { preferLocalBuild = true; } + '' + mkdir -p $out + cp -prd ${nixpkgs.outPath} $out/nixos + chmod -R u+w $out/nixos + if [ ! -e $out/nixos/nixpkgs ]; then + ln -s . $out/nixos/nixpkgs + fi + echo -n ${toString config.system.nixos.revision} > $out/nixos/.git-revision + echo -n ${toString config.system.nixos.versionSuffix} > $out/nixos/.version-suffix + echo ${toString config.system.nixos.versionSuffix} | sed -e s/pre// > $out/nixos/svn-revision + ''; + + preparer = pkgs.writeShellScriptBin "wsl-prepare" '' + set -e + + mkdir -m 0755 ./bin ./etc + mkdir -m 1777 ./tmp + + # WSL requires a /bin/sh - only temporary, NixOS's activate will overwrite + ln -s ${config.users.users.root.shell} ./bin/sh + + # WSL also requires a /bin/mount, otherwise the host fs isn't accessible + ln -s /nix/var/nix/profiles/system/sw/bin/mount ./bin/mount + + # Set system profile + system=${config.system.build.toplevel} + ./$system/sw/bin/nix-store --store `pwd` --load-db < ./nix-path-registration + rm ./nix-path-registration + ./$system/sw/bin/nix-env --store `pwd` -p ./nix/var/nix/profiles/system --set $system + + # Set channel + mkdir -p ./nix/var/nix/profiles/per-user/root + ./$system/sw/bin/nix-env --store `pwd` -p ./nix/var/nix/profiles/per-user/root/channels --set ${channelSources} + mkdir -m 0700 -p ./root/.nix-defexpr + ln -s /nix/var/nix/profiles/per-user/root/channels ./root/.nix-defexpr/channels + + # It's now a NixOS! + touch ./etc/NIXOS + + # Write wsl.conf so that it is present when NixOS is started for the first time + cp ${config.environment.etc."wsl.conf".source} ./etc/wsl.conf + + ${lib.optionalString config.wsl.tarball.includeConfig '' + # Copy the system configuration + mkdir -p ./etc/nixos/nixos-wsl + cp -R ${lib.cleanSource ../.}/. ./etc/nixos/nixos-wsl + mv ./etc/nixos/nixos-wsl/configuration.nix ./etc/nixos/configuration.nix + # Patch the import path to avoid having a flake.nix in /etc/nixos + sed -i 's|import \./default\.nix|import \./nixos-wsl|' ./etc/nixos/configuration.nix + ''} + ''; + +in +{ + + options.wsl.tarball = { + includeConfig = mkOption { + type = types.bool; + default = true; + description = "Whether or not to copy the system configuration into the tarball"; + }; + }; + + + config = mkIf config.wsl.enable { + # These options make no sense without the wsl-distro module anyway + + system.build.tarball = pkgs.callPackage "${nixpkgs}/nixos/lib/make-system-tarball.nix" { + # No contents, structure will be added by prepare script + contents = [ ]; + + fileName = "nixos-wsl-${pkgs.hostPlatform.system}"; + + storeContents = pkgs2storeContents [ + config.system.build.toplevel + channelSources + preparer + ]; + + extraCommands = "${preparer}/bin/wsl-prepare"; + + # Use gzip + compressCommand = "gzip"; + compressionExtension = ".gz"; + }; + + }; +} diff --git a/devel/nixos-wsl/modules/docker-desktop.nix b/devel/nixos-wsl/modules/docker-desktop.nix new file mode 100644 index 0000000..ade86e9 --- /dev/null +++ b/devel/nixos-wsl/modules/docker-desktop.nix @@ -0,0 +1,41 @@ +{ config, lib, pkgs, ... }: +with builtins; with lib; { + + imports = [ + (mkRenamedOptionModule [ "wsl" "docker" ] [ "wsl" "docker-desktop" ]) + ]; + + options.wsl.docker-desktop = with types; { + enable = mkEnableOption "Docker Desktop integration"; + }; + + config = + let + cfg = config.wsl.docker-desktop; + in + mkIf (config.wsl.enable && cfg.enable) { + + environment.systemPackages = with pkgs; [ + docker + docker-compose + ]; + + systemd.services.docker-desktop-proxy = { + description = "Docker Desktop proxy"; + script = '' + ${config.wsl.automountPath}/wsl/docker-desktop/docker-desktop-user-distro proxy --docker-desktop-root ${config.wsl.automountPath}/wsl/docker-desktop + ''; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Restart = "on-failure"; + RestartSec = "30s"; + }; + }; + + users.groups.docker.members = [ + config.wsl.defaultUser + ]; + + }; + +} diff --git a/devel/nixos-wsl/modules/docker-native.nix b/devel/nixos-wsl/modules/docker-native.nix new file mode 100644 index 0000000..35d10ef --- /dev/null +++ b/devel/nixos-wsl/modules/docker-native.nix @@ -0,0 +1,40 @@ +{ config, lib, pkgs, ... }: +with builtins; with lib; { + + options.wsl.docker-native = with types; { + enable = mkEnableOption "Native Docker integration in NixOS."; + + addToDockerGroup = mkOption { + type = bool; + default = config.security.sudo.wheelNeedsPassword; + description = '' + Wether to add the default user to the docker group. + + This is not recommended, if you have a password, because it essentially permits unauthenticated root access. + ''; + }; + }; + + config = + let + cfg = config.wsl.docker-native; + in + mkIf (config.wsl.enable && cfg.enable) { + nixpkgs.overlays = [ + (self: super: { + docker = super.docker.override { iptables = pkgs.iptables-legacy; }; + }) + ]; + + environment.systemPackages = with pkgs; [ + docker + docker-compose + ]; + + virtualisation.docker.enable = true; + + users.groups.docker.members = lib.mkIf cfg.addToDockerGroup [ + config.wsl.defaultUser + ]; + }; +} diff --git a/devel/nixos-wsl/modules/installer.nix b/devel/nixos-wsl/modules/installer.nix new file mode 100644 index 0000000..45d191a --- /dev/null +++ b/devel/nixos-wsl/modules/installer.nix @@ -0,0 +1,73 @@ +{ config, lib, pkgs, ... }: +with builtins; with lib; { + + config = mkIf config.wsl.enable ( + let + mkTarball = pkgs.callPackage "${lib.cleanSource pkgs.path}/nixos/lib/make-system-tarball.nix"; + + pkgs2storeContents = map (x: { object = x; symlink = "none"; }); + + rootfs = let tarball = config.system.build.tarball; in "${tarball}/tarball/${tarball.fileName}.tar${tarball.extension}"; + + installer = pkgs.writeScript "installer.sh" '' + #!${pkgs.busybox}/bin/sh + BASEPATH=$PATH + export PATH=$BASEPATH:${pkgs.busybox}/bin # Add busybox to path + + set -e + cd / + + echo "Unpacking root file system..." + ${pkgs.pv}/bin/pv ${rootfs} | tar xz + + echo "Activating nix configuration..." + /nix/var/nix/profiles/system/activate + PATH=$BASEPATH:/run/current-system/sw/bin # Use packages from target system + + echo "Cleaning up installer files..." + nix-collect-garbage + rm /nix-path-registration + + echo "Optimizing store..." + nix-store --optimize + + # Don't package the shell here, it's contained in the rootfs + exec ${builtins.unsafeDiscardStringContext config.users.users.root.shell} "$@" + ''; + + # Set installer.sh as the root shell + passwd = pkgs.writeText "passwd" '' + root:x:0:0:System administrator:/root:${installer} + ''; + in + { + + system.build.installer = mkTarball { + fileName = "nixos-wsl-installer"; + compressCommand = "gzip"; + compressionExtension = ".gz"; + extraArgs = "--hard-dereference"; + + storeContents = with pkgs; pkgs2storeContents [ + installer + ]; + + contents = [ + { source = config.environment.etc."wsl.conf".source; target = "/etc/wsl.conf"; } + { source = config.environment.etc."fstab".source; target = "/etc/fstab"; } + { source = passwd; target = "/etc/passwd"; } + { source = "${pkgs.busybox}/bin/busybox"; target = "/bin/sh"; } + { source = "${pkgs.busybox}/bin/busybox"; target = "/bin/mount"; } + ]; + + extraCommands = pkgs.writeShellScript "prepare" '' + export PATH=$PATH:${pkgs.coreutils}/bin + mkdir -p bin + ln -s /init bin/wslpath + ''; + }; + + } + ); + +} diff --git a/devel/nixos-wsl/modules/interop.nix b/devel/nixos-wsl/modules/interop.nix new file mode 100644 index 0000000..b7babfb --- /dev/null +++ b/devel/nixos-wsl/modules/interop.nix @@ -0,0 +1,88 @@ +{ lib, pkgs, config, ... }: + +with builtins; with lib; +{ + imports = [ + (mkRenamedOptionModule [ "wsl" "compatibility" "interopPreserveArgvZero" ] [ "wsl" "interop" "preserveArgvZero" ]) + ]; + + options.wsl.interop = with types; { + register = mkOption { + type = bool; + default = false; # Use the existing registration by default + description = "Explicitly register the binfmt_misc handler for Windows executables"; + }; + + includePath = mkOption { + type = bool; + default = true; + description = "Include Windows PATH in WSL PATH"; + }; + + preserveArgvZero = mkOption { + type = nullOr bool; + default = null; + description = '' + Register binfmt interpreter for Windows executables with 'preserves argv[0]' flag. + + Default (null): autodetect, at some performance cost. + To avoid the performance cost, set this to true for WSL Preview 0.58 and up, + or to false for any older versions, including pre-Microsoft Store and Windows 10. + ''; + }; + }; + + config = + let + cfg = config.wsl.interop; + in + mkIf config.wsl.enable { + + boot.binfmt.registrations = mkIf cfg.register { + WSLInterop = + let + compat = cfg.preserveArgvZero; + + # WSL Preview 0.58 and up registers the /init binfmt interp for Windows executable + # with the "preserve argv[0]" flag, so if you run `./foo.exe`, the interp gets invoked + # as `/init foo.exe ./foo.exe`. + # argv[0] --^ ^-- actual path + # + # Older versions expect to be called without the argv[0] bit, simply as `/init ./foo.exe`. + # + # We detect that by running `/init /known-not-existing-path.exe` and checking the exit code: + # the new style interp expects at least two arguments, so exits with exit code 1, + # presumably meaning "parsing error"; the old style interp attempts to actually run + # the executable, fails to find it, and exits with 255. + compatWrapper = pkgs.writeShellScript "nixos-wsl-binfmt-hack" '' + /init /nixos-wsl-does-not-exist.exe + [ $? -eq 255 ] && shift + exec /init "$@" + ''; + + # use the autodetect hack if unset, otherwise call /init directly + interpreter = if compat == null then compatWrapper else "/init"; + + # enable for the wrapper and autodetect hack + preserveArgvZero = if compat == false then false else true; + in + { + magicOrExtension = "MZ"; + fixBinary = true; + wrapInterpreterInShell = false; + inherit interpreter preserveArgvZero; + }; + }; + + # Include Windows %PATH% in Linux $PATH. + environment.extraInit = mkIf cfg.includePath ''PATH="$PATH:$WSLPATH"''; + + warnings = + let + registrations = config.boot.binfmt.registrations; + in + optional (!(registrations ? WSLInterop) && (length (attrNames config.boot.binfmt.registrations)) != 0) "Having any binfmt registrations without re-registering WSLInterop (wsl.interop.register) will break running .exe files from WSL2"; + }; + + +} diff --git a/devel/nixos-wsl/modules/wsl-distro.nix b/devel/nixos-wsl/modules/wsl-distro.nix new file mode 100644 index 0000000..4c6eda5 --- /dev/null +++ b/devel/nixos-wsl/modules/wsl-distro.nix @@ -0,0 +1,139 @@ +{ lib, pkgs, config, ... }: + +with builtins; with lib; +{ + options.wsl = with types; + let + coercedToStr = coercedTo (oneOf [ bool path int ]) (toString) str; + in + { + enable = mkEnableOption "support for running NixOS as a WSL distribution"; + automountPath = mkOption { + type = str; + default = "/mnt"; + description = "The path where windows drives are mounted (e.g. /mnt/c)"; + }; + automountOptions = mkOption { + type = str; + default = "metadata,uid=1000,gid=100"; + description = "Options to use when mounting windows drives"; + }; + defaultUser = mkOption { + type = str; + default = "nixos"; + description = "The name of the default user"; + }; + startMenuLaunchers = mkEnableOption "shortcuts for GUI applications in the windows start menu"; + wslConf = mkOption { + type = attrsOf (attrsOf (oneOf [ string int bool ])); + description = "Entries that are added to /etc/wsl.conf"; + }; + }; + + config = + let + cfg = config.wsl; + syschdemd = import ../syschdemd.nix { inherit lib pkgs config; inherit (cfg) automountPath defaultUser; defaultUserHome = config.users.users.${cfg.defaultUser}.home; }; + in + mkIf cfg.enable { + + wsl.wslConf = { + automount = { + enabled = true; + mountFsTab = true; + root = "${cfg.automountPath}/"; + options = cfg.automountOptions; + }; + network = { + generateResolvConf = mkDefault true; + generateHosts = mkDefault true; + }; + }; + + # WSL is closer to a container than anything else + boot.isContainer = true; + + environment.noXlibs = lib.mkForce false; # override xlibs not being installed (due to isContainer) to enable the use of GUI apps + hardware.opengl.enable = true; # Enable GPU acceleration + + environment = { + + etc = { + "wsl.conf".text = generators.toINI { } cfg.wslConf; + + # DNS settings are managed by WSL + hosts.enable = !config.wsl.wslConf.network.generateHosts; + "resolv.conf".enable = !config.wsl.wslConf.network.generateResolvConf; + }; + + systemPackages = [ + (pkgs.runCommand "wslpath" { } '' + mkdir -p $out/bin + ln -s /init $out/bin/wslpath + '') + ]; + }; + + networking.dhcpcd.enable = false; + + users.users.${cfg.defaultUser} = { + isNormalUser = true; + uid = 1000; + extraGroups = [ "wheel" ]; # Allow the default user to use sudo + }; + + users.users.root = { + shell = "${syschdemd}/bin/syschdemd"; + # Otherwise WSL fails to login as root with "initgroups failed 5" + extraGroups = [ "root" ]; + }; + + security.sudo = { + extraConfig = '' + Defaults env_keep+=INSIDE_NAMESPACE + ''; + wheelNeedsPassword = mkDefault false; # The default user will not have a password by default + }; + + system.activationScripts = { + copy-launchers = mkIf cfg.startMenuLaunchers ( + stringAfter [ ] '' + for x in applications icons; do + echo "Copying /usr/share/$x" + mkdir -p /usr/share/$x + ${pkgs.rsync}/bin/rsync -ar --delete $systemConfig/sw/share/$x/. /usr/share/$x + done + '' + ); + populateBin = stringAfter [ ] '' + echo "setting up /bin..." + ln -sf /init /bin/wslpath + ln -sf ${pkgs.bashInteractive}/bin/bash /bin/sh + ln -sf ${pkgs.util-linux}/bin/mount /bin/mount + ''; + }; + + systemd = { + # Disable systemd units that don't make sense on WSL + services = { + "serial-getty@ttyS0".enable = false; + "serial-getty@hvc0".enable = false; + "getty@tty1".enable = false; + "autovt@".enable = false; + firewall.enable = false; + systemd-resolved.enable = false; + systemd-udevd.enable = false; + }; + + tmpfiles.rules = [ + # Don't remove the X11 socket + "d /tmp/.X11-unix 1777 root root" + ]; + + # Don't allow emergency mode, because we don't have a console. + enableEmergencyMode = false; + }; + + warnings = (optional (config.systemd.services.systemd-resolved.enable && config.wsl.wslConf.network.generateResolvConf) "systemd-resolved is enabled, but resolv.conf is managed by WSL"); + }; +} diff --git a/devel/nixos-wsl/syschdemd.nix b/devel/nixos-wsl/syschdemd.nix new file mode 100644 index 0000000..406dd86 --- /dev/null +++ b/devel/nixos-wsl/syschdemd.nix @@ -0,0 +1,28 @@ +{ lib +, pkgs +, config +, automountPath +, defaultUser +, defaultUserHome ? "/home/${defaultUser}" +, ... +}: + +pkgs.substituteAll { + name = "syschdemd"; + src = ./syschdemd.sh; + dir = "bin"; + isExecutable = true; + + buildInputs = with pkgs; [ daemonize ]; + + inherit defaultUser defaultUserHome; + inherit (pkgs) daemonize; + inherit (config.security) wrapperDir; + fsPackagesPath = lib.makeBinPath config.system.fsPackages; + + systemdWrapper = pkgs.writeShellScript "systemd-wrapper.sh" '' + mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc || true + mount --make-rshared ${automountPath} + exec systemd + ''; +} diff --git a/devel/nixos-wsl/syschdemd.sh b/devel/nixos-wsl/syschdemd.sh new file mode 100644 index 0000000..6223cda --- /dev/null +++ b/devel/nixos-wsl/syschdemd.sh @@ -0,0 +1,78 @@ +#! @shell@ + +set -e + +sw="/nix/var/nix/profiles/system/sw/bin" +systemPath=$(${sw}/readlink -f /nix/var/nix/profiles/system) + +function start_systemd { + echo "Starting systemd..." >&2 + + PATH=/run/current-system/systemd/lib/systemd:@fsPackagesPath@ \ + LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive \ + @daemonize@/bin/daemonize /run/current-system/sw/bin/unshare -fp --mount-proc @systemdWrapper@ + + # Wait until systemd has been started to prevent a race condition from occuring + while ! $sw/pgrep -xf systemd | $sw/tail -n1 >/run/systemd.pid; do + $sw/sleep 1s + done + + # Wait for systemd to start services + status=1 + while [[ $status -gt 0 ]]; do + $sw/sleep 1 + status=0 + $sw/nsenter -t $(/dev/null || + status=$? + done +} + +# Needs root to work +if [[ $EUID -ne 0 ]]; then + echo "[ERROR] Requires root! :( Make sure the WSL default user is set to root" >&2 + exit 1 +fi + +if [ ! -e "/run/current-system" ]; then + LANG="C.UTF-8" /nix/var/nix/profiles/system/activate +fi + +if [ ! -e "/run/systemd.pid" ]; then + start_systemd +fi + +userShell=$($sw/getent passwd @defaultUser@ | $sw/cut -d: -f7) +if [[ $# -gt 0 ]]; then + # wsl seems to prefix with "-c" + shift + cmd="$@" +else + cmd="$userShell" +fi + +# Pass external environment but filter variables specific to root user. +exportCmd="$(export -p | $sw/grep -vE ' (HOME|LOGNAME|SHELL|USER)='); export WSLPATH=\"$PATH\"; export INSIDE_NAMESPACE=true" + +if [[ -z "${INSIDE_NAMESPACE:-}" ]]; then + + # Test whether systemd is still alive if it was started previously + if ! [ -d "/proc/$( Date: Sun, 6 Nov 2022 10:45:45 +0000 Subject: [PATCH 2/7] add niv as a package version manager --- apply-system.sh | 22 ++ nix/sources.json | 14 ++ nix/sources.nix | 194 ++++++++++++++++++ {devel => system}/configuration.nix | 20 +- {devel => system}/flake.lock | 0 {devel => system}/flake.nix | 0 {devel => system}/nixos-wsl/.envrc | 0 .../.github/ISSUE_TEMPLATE/bug_report.md | 0 .../.github/ISSUE_TEMPLATE/feature_request.md | 0 .../nixos-wsl/.github/release-drafter.yml | 0 .../nixos-wsl/.github/workflows/main.yml | 0 .../.github/workflows/release-drafter.yml | 0 .../.github/workflows/update-flakes.yml | 0 {devel => system}/nixos-wsl/.gitignore | 0 {devel => system}/nixos-wsl/LICENSE | 0 {devel => system}/nixos-wsl/README.md | 0 {devel => system}/nixos-wsl/default.nix | 0 {devel => system}/nixos-wsl/flake.lock | 0 {devel => system}/nixos-wsl/flake.nix | 0 .../nixos-wsl/modules/build-tarball.nix | 0 .../nixos-wsl/modules/docker-desktop.nix | 0 .../nixos-wsl/modules/docker-native.nix | 0 .../nixos-wsl/modules/installer.nix | 0 .../nixos-wsl/modules/interop.nix | 0 .../nixos-wsl/modules/wsl-distro.nix | 0 {devel => system}/nixos-wsl/syschdemd.nix | 0 {devel => system}/nixos-wsl/syschdemd.sh | 0 27 files changed, 247 insertions(+), 3 deletions(-) create mode 100755 apply-system.sh create mode 100644 nix/sources.json create mode 100644 nix/sources.nix rename {devel => system}/configuration.nix (79%) rename {devel => system}/flake.lock (100%) rename {devel => system}/flake.nix (100%) rename {devel => system}/nixos-wsl/.envrc (100%) rename {devel => system}/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md (100%) rename {devel => system}/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md (100%) rename {devel => system}/nixos-wsl/.github/release-drafter.yml (100%) rename {devel => system}/nixos-wsl/.github/workflows/main.yml (100%) rename {devel => system}/nixos-wsl/.github/workflows/release-drafter.yml (100%) rename {devel => system}/nixos-wsl/.github/workflows/update-flakes.yml (100%) rename {devel => system}/nixos-wsl/.gitignore (100%) rename {devel => system}/nixos-wsl/LICENSE (100%) rename {devel => system}/nixos-wsl/README.md (100%) rename {devel => system}/nixos-wsl/default.nix (100%) rename {devel => system}/nixos-wsl/flake.lock (100%) rename {devel => system}/nixos-wsl/flake.nix (100%) rename {devel => system}/nixos-wsl/modules/build-tarball.nix (100%) rename {devel => system}/nixos-wsl/modules/docker-desktop.nix (100%) rename {devel => system}/nixos-wsl/modules/docker-native.nix (100%) rename {devel => system}/nixos-wsl/modules/installer.nix (100%) rename {devel => system}/nixos-wsl/modules/interop.nix (100%) rename {devel => system}/nixos-wsl/modules/wsl-distro.nix (100%) rename {devel => system}/nixos-wsl/syschdemd.nix (100%) rename {devel => system}/nixos-wsl/syschdemd.sh (100%) diff --git a/apply-system.sh b/apply-system.sh new file mode 100755 index 0000000..8f65bd3 --- /dev/null +++ b/apply-system.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env sh +set -xv + +# Where is this script located +SCRIPT_DIR=$(realpath $(dirname $0)) +echo "SCRIPT_DIR: ${SCRIPT_DIR}" +# Where should the symlink for this repo live in the system +CONFIG_DIR="~/.dotfiles" + +# Create a symlink for this directory to ~/.dotfiles +# if it already exists, error out +if [ -L ${CONFIG_DIR} ] && [ $(readlink -f ${CONFIG_DIR}) != ${SCRIPT_DIR} ]; then + echo "ERR: ${SCRIPT_DIR}/apply-system.sh: ${CONFIG_DIR} exists and not symlink to ${SCRIPT_DIR}" + exit 1 +fi +ln -s -T ${SCRIPT_DIR} ${CONFIG_DIR} + + +# $PWD to ~/.dotfiles +pushd ~/.dotfiles +sudo nixos-rebuild switch -I nixos-config=./system/configuration.nix +popd diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000..5c20860 --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,14 @@ +{ + "nixpkgs": { + "branch": "release-21.05", + "description": "Nix Packages collection", + "homepage": "", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5f244caea76105b63d826911b2a1563d33ff1cdc", + "sha256": "1xlgynfw9svy7nvh9nkxsxdzncv9hg99gbvbwv3gmrhmzc3sar75", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5f244caea76105b63d826911b2a1563d33ff1cdc.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 0000000..9a01c8a --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,194 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + if spec ? ref then spec.ref else + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + submodules = if spec ? submodules then spec.submodules else false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules == true + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + {} + else {}; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import {} + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else {}; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs ( + name: spec: + if builtins.hasAttr "outPath" spec + then abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/devel/configuration.nix b/system/configuration.nix similarity index 79% rename from devel/configuration.nix rename to system/configuration.nix index 06363b6..e298cb6 100755 --- a/devel/configuration.nix +++ b/system/configuration.nix @@ -7,10 +7,13 @@ in { imports = [ "${modulesPath}/profiles/minimal.nix" - + ./hardware-configuration.nix nixos-wsl.nixosModules.wsl ]; + networking.hostName = "nixos"; + system.stateVersion = "22.05"; + wsl = { enable = true; automountPath = "/mnt"; @@ -32,6 +35,7 @@ in experimental-features = nix-command flakes ''; + # Home manager programs.neovim = { enable = true; defaultEditor = true; @@ -40,8 +44,18 @@ in enable = true; # more information should be configured under user level }; - networking.hostName = "nixos"; - system.stateVersion = "22.05"; + programs.zsh = { + enable = true; + shellAliases = { + # list lists + ll = "ls -l"; + update = "sudo nixos-rebuild switch"; + }; + history = { + size = 10000; + path = "${config.xdg.dataHome}/zsh/history"; + }; + }; environment.systemPackages = [ pkgs.gnumake diff --git a/devel/flake.lock b/system/flake.lock similarity index 100% rename from devel/flake.lock rename to system/flake.lock diff --git a/devel/flake.nix b/system/flake.nix similarity index 100% rename from devel/flake.nix rename to system/flake.nix diff --git a/devel/nixos-wsl/.envrc b/system/nixos-wsl/.envrc similarity index 100% rename from devel/nixos-wsl/.envrc rename to system/nixos-wsl/.envrc diff --git a/devel/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md b/system/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md similarity index 100% rename from devel/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md rename to system/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md diff --git a/devel/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md b/system/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md similarity index 100% rename from devel/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md rename to system/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md diff --git a/devel/nixos-wsl/.github/release-drafter.yml b/system/nixos-wsl/.github/release-drafter.yml similarity index 100% rename from devel/nixos-wsl/.github/release-drafter.yml rename to system/nixos-wsl/.github/release-drafter.yml diff --git a/devel/nixos-wsl/.github/workflows/main.yml b/system/nixos-wsl/.github/workflows/main.yml similarity index 100% rename from devel/nixos-wsl/.github/workflows/main.yml rename to system/nixos-wsl/.github/workflows/main.yml diff --git a/devel/nixos-wsl/.github/workflows/release-drafter.yml b/system/nixos-wsl/.github/workflows/release-drafter.yml similarity index 100% rename from devel/nixos-wsl/.github/workflows/release-drafter.yml rename to system/nixos-wsl/.github/workflows/release-drafter.yml diff --git a/devel/nixos-wsl/.github/workflows/update-flakes.yml b/system/nixos-wsl/.github/workflows/update-flakes.yml similarity index 100% rename from devel/nixos-wsl/.github/workflows/update-flakes.yml rename to system/nixos-wsl/.github/workflows/update-flakes.yml diff --git a/devel/nixos-wsl/.gitignore b/system/nixos-wsl/.gitignore similarity index 100% rename from devel/nixos-wsl/.gitignore rename to system/nixos-wsl/.gitignore diff --git a/devel/nixos-wsl/LICENSE b/system/nixos-wsl/LICENSE similarity index 100% rename from devel/nixos-wsl/LICENSE rename to system/nixos-wsl/LICENSE diff --git a/devel/nixos-wsl/README.md b/system/nixos-wsl/README.md similarity index 100% rename from devel/nixos-wsl/README.md rename to system/nixos-wsl/README.md diff --git a/devel/nixos-wsl/default.nix b/system/nixos-wsl/default.nix similarity index 100% rename from devel/nixos-wsl/default.nix rename to system/nixos-wsl/default.nix diff --git a/devel/nixos-wsl/flake.lock b/system/nixos-wsl/flake.lock similarity index 100% rename from devel/nixos-wsl/flake.lock rename to system/nixos-wsl/flake.lock diff --git a/devel/nixos-wsl/flake.nix b/system/nixos-wsl/flake.nix similarity index 100% rename from devel/nixos-wsl/flake.nix rename to system/nixos-wsl/flake.nix diff --git a/devel/nixos-wsl/modules/build-tarball.nix b/system/nixos-wsl/modules/build-tarball.nix similarity index 100% rename from devel/nixos-wsl/modules/build-tarball.nix rename to system/nixos-wsl/modules/build-tarball.nix diff --git a/devel/nixos-wsl/modules/docker-desktop.nix b/system/nixos-wsl/modules/docker-desktop.nix similarity index 100% rename from devel/nixos-wsl/modules/docker-desktop.nix rename to system/nixos-wsl/modules/docker-desktop.nix diff --git a/devel/nixos-wsl/modules/docker-native.nix b/system/nixos-wsl/modules/docker-native.nix similarity index 100% rename from devel/nixos-wsl/modules/docker-native.nix rename to system/nixos-wsl/modules/docker-native.nix diff --git a/devel/nixos-wsl/modules/installer.nix b/system/nixos-wsl/modules/installer.nix similarity index 100% rename from devel/nixos-wsl/modules/installer.nix rename to system/nixos-wsl/modules/installer.nix diff --git a/devel/nixos-wsl/modules/interop.nix b/system/nixos-wsl/modules/interop.nix similarity index 100% rename from devel/nixos-wsl/modules/interop.nix rename to system/nixos-wsl/modules/interop.nix diff --git a/devel/nixos-wsl/modules/wsl-distro.nix b/system/nixos-wsl/modules/wsl-distro.nix similarity index 100% rename from devel/nixos-wsl/modules/wsl-distro.nix rename to system/nixos-wsl/modules/wsl-distro.nix diff --git a/devel/nixos-wsl/syschdemd.nix b/system/nixos-wsl/syschdemd.nix similarity index 100% rename from devel/nixos-wsl/syschdemd.nix rename to system/nixos-wsl/syschdemd.nix diff --git a/devel/nixos-wsl/syschdemd.sh b/system/nixos-wsl/syschdemd.sh similarity index 100% rename from devel/nixos-wsl/syschdemd.sh rename to system/nixos-wsl/syschdemd.sh From 56c6847439a7e54691fb49f8137590bc8ac1d7e4 Mon Sep 17 00:00:00 2001 From: pegasust Date: Sun, 6 Nov 2022 11:48:16 +0000 Subject: [PATCH 3/7] fix: apply-system.sh now uses flake --- apply-system.sh | 2 +- devel/flake.nix | 30 ++++++++++++++ system/configuration.nix | 15 +------ system/hardware-configuration.nix | 65 +++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 devel/flake.nix create mode 100644 system/hardware-configuration.nix diff --git a/apply-system.sh b/apply-system.sh index 8f65bd3..7175470 100755 --- a/apply-system.sh +++ b/apply-system.sh @@ -18,5 +18,5 @@ ln -s -T ${SCRIPT_DIR} ${CONFIG_DIR} # $PWD to ~/.dotfiles pushd ~/.dotfiles -sudo nixos-rebuild switch -I nixos-config=./system/configuration.nix +sudo nixos-rebuild switch --flake ./system#nixos popd diff --git a/devel/flake.nix b/devel/flake.nix new file mode 100644 index 0000000..c199a94 --- /dev/null +++ b/devel/flake.nix @@ -0,0 +1,30 @@ +{ + description = "My development flake"; + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + home-manager.url = "github:nix-community/home-manager"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: { + programs.neovim = { + enable = true; + defaultEditor = true; + }; + programs.git = { + enable = true; + }; + programs.zsh = { + enable = true; + shellAliases = { + # list lists + ll = "ls -l"; + update = "sudo nixos-rebuild switch"; + }; + history = { + size = 10000; + path = "${config.xdg.dataHome}/zsh/history"; + }; + }; + }; +} diff --git a/system/configuration.nix b/system/configuration.nix index e298cb6..891e552 100755 --- a/system/configuration.nix +++ b/system/configuration.nix @@ -11,7 +11,6 @@ in nixos-wsl.nixosModules.wsl ]; - networking.hostName = "nixos"; system.stateVersion = "22.05"; wsl = { @@ -28,6 +27,7 @@ in }; # users.users..uid = 1000; + networking.hostName = "nixos"; # Enable nix flakes nix.package = pkgs.nixFlakes; @@ -44,19 +44,6 @@ in enable = true; # more information should be configured under user level }; - programs.zsh = { - enable = true; - shellAliases = { - # list lists - ll = "ls -l"; - update = "sudo nixos-rebuild switch"; - }; - history = { - size = 10000; - path = "${config.xdg.dataHome}/zsh/history"; - }; - }; - environment.systemPackages = [ pkgs.gnumake ]; diff --git a/system/hardware-configuration.nix b/system/hardware-configuration.nix new file mode 100644 index 0000000..bd15e46 --- /dev/null +++ b/system/hardware-configuration.nix @@ -0,0 +1,65 @@ +# Do not modify this file! It was generated by β€˜nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = [ ]; + + boot.initrd.availableKernelModules = [ ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/sdd"; + fsType = "ext4"; + }; + + fileSystems."/usr/lib/wsl/drivers" = + { device = "drivers"; + fsType = "9p"; + }; + + fileSystems."/usr/lib/wsl/lib" = + { device = "lib"; + fsType = "9p"; + }; + + fileSystems."/mnt/wsl" = + { device = "tmpfs"; + fsType = "tmpfs"; + }; + + fileSystems."/mnt/c" = + { device = "C:\134"; + fsType = "9p"; + }; + + fileSystems."/mnt/d" = + { device = "D:\134"; + fsType = "9p"; + }; + + fileSystems."/mnt/f" = + { device = "F:\134"; + fsType = "9p"; + }; + + swapDevices = [ ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.bond0.useDHCP = lib.mkDefault true; + # networking.interfaces.bonding_masters.useDHCP = lib.mkDefault true; + # networking.interfaces.dummy0.useDHCP = lib.mkDefault true; + # networking.interfaces.eth0.useDHCP = lib.mkDefault true; + # networking.interfaces.sit0.useDHCP = lib.mkDefault true; + # networking.interfaces.tunl0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} From 334a74dbb84aa2fd2497e8afd585b8bf781e0458 Mon Sep 17 00:00:00 2001 From: pegasust Date: Sun, 6 Nov 2022 12:56:42 +0000 Subject: [PATCH 4/7] bad config, let's redo from star --- devel/flake.lock | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ devel/flake.nix | 35 ++++++++---------- devel/shell.nix | 23 ++++++++++++ 3 files changed, 130 insertions(+), 21 deletions(-) create mode 100644 devel/flake.lock create mode 100644 devel/shell.nix diff --git a/devel/flake.lock b/devel/flake.lock new file mode 100644 index 0000000..76447ec --- /dev/null +++ b/devel/flake.lock @@ -0,0 +1,93 @@ +{ + "nodes": { + "flake-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" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + }, + "locked": { + "lastModified": 1667708081, + "narHash": "sha256-FChEy05x4ed/pttjfTeKxjPCnHknMYrUtDyBiYbreT4=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "1ef0da321217c6c19b7a30509631c080a19321e5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1667629849, + "narHash": "sha256-P+v+nDOFWicM4wziFK9S/ajF2lc0N2Rg9p6Y35uMoZI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "3bacde6273b09a21a8ccfba15586fb165078fb62", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1667629849, + "narHash": "sha256-P+v+nDOFWicM4wziFK9S/ajF2lc0N2Rg9p6Y35uMoZI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3bacde6273b09a21a8ccfba15586fb165078fb62", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "home-manager": "home-manager", + "nixpkgs": "nixpkgs_2" + } + }, + "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", + "version": 7 +} diff --git a/devel/flake.nix b/devel/flake.nix index c199a94..0c517a4 100644 --- a/devel/flake.nix +++ b/devel/flake.nix @@ -6,25 +6,18 @@ flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, flake-utils, ... }: { - programs.neovim = { - enable = true; - defaultEditor = true; - }; - programs.git = { - enable = true; - }; - programs.zsh = { - enable = true; - shellAliases = { - # list lists - ll = "ls -l"; - update = "sudo nixos-rebuild switch"; - }; - history = { - size = 10000; - path = "${config.xdg.dataHome}/zsh/history"; - }; - }; - }; + outputs = { + self, # instance of self + nixpkgs, # nixpkgs flake + flake-utils, + home-manager, + ... + }: flake-utils.lib.eachDefaultSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; in { + devShells.default = import ./shell.nix { + inherit pkgs; + inherit home-manager; + }; + } + ); } diff --git a/devel/shell.nix b/devel/shell.nix new file mode 100644 index 0000000..0990c0b --- /dev/null +++ b/devel/shell.nix @@ -0,0 +1,23 @@ +{ pkgs? import {}, home-manager, ...}: +with pkgs; +mkShell { + programs.neovim = { + enable = true; + defaultEditor = true; + }; + programs.git = { + enable = true; + }; + programs.zsh = { + enable = true; + shellAliases = { + # list lists + ll = "ls -l"; + update = "sudo nixos-rebuild switch"; + }; + history = { + size = 10000; + path = "${home-manager.cfg.dataHome}/zsh/history"; + }; + }; +} From 998c6624969523874b68e85abd862ee17f22910c Mon Sep 17 00:00:00 2001 From: pegasust Date: Sun, 6 Nov 2022 14:01:33 +0000 Subject: [PATCH 5/7] Remove devel sub-flake and prepare to merge with dotfiles config --- apply-system.sh | 22 ------ devel/flake.lock | 93 ----------------------- devel/flake.nix | 23 ------ devel/shell.nix | 23 ------ nix/sources.json | 14 ---- nix/sources.nix | 194 ----------------------------------------------- 6 files changed, 369 deletions(-) delete mode 100755 apply-system.sh delete mode 100644 devel/flake.lock delete mode 100644 devel/flake.nix delete mode 100644 devel/shell.nix delete mode 100644 nix/sources.json delete mode 100644 nix/sources.nix diff --git a/apply-system.sh b/apply-system.sh deleted file mode 100755 index 7175470..0000000 --- a/apply-system.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env sh -set -xv - -# Where is this script located -SCRIPT_DIR=$(realpath $(dirname $0)) -echo "SCRIPT_DIR: ${SCRIPT_DIR}" -# Where should the symlink for this repo live in the system -CONFIG_DIR="~/.dotfiles" - -# Create a symlink for this directory to ~/.dotfiles -# if it already exists, error out -if [ -L ${CONFIG_DIR} ] && [ $(readlink -f ${CONFIG_DIR}) != ${SCRIPT_DIR} ]; then - echo "ERR: ${SCRIPT_DIR}/apply-system.sh: ${CONFIG_DIR} exists and not symlink to ${SCRIPT_DIR}" - exit 1 -fi -ln -s -T ${SCRIPT_DIR} ${CONFIG_DIR} - - -# $PWD to ~/.dotfiles -pushd ~/.dotfiles -sudo nixos-rebuild switch --flake ./system#nixos -popd diff --git a/devel/flake.lock b/devel/flake.lock deleted file mode 100644 index 76447ec..0000000 --- a/devel/flake.lock +++ /dev/null @@ -1,93 +0,0 @@ -{ - "nodes": { - "flake-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" - } - }, - "home-manager": { - "inputs": { - "nixpkgs": "nixpkgs", - "utils": "utils" - }, - "locked": { - "lastModified": 1667708081, - "narHash": "sha256-FChEy05x4ed/pttjfTeKxjPCnHknMYrUtDyBiYbreT4=", - "owner": "nix-community", - "repo": "home-manager", - "rev": "1ef0da321217c6c19b7a30509631c080a19321e5", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "home-manager", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1667629849, - "narHash": "sha256-P+v+nDOFWicM4wziFK9S/ajF2lc0N2Rg9p6Y35uMoZI=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "3bacde6273b09a21a8ccfba15586fb165078fb62", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1667629849, - "narHash": "sha256-P+v+nDOFWicM4wziFK9S/ajF2lc0N2Rg9p6Y35uMoZI=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "3bacde6273b09a21a8ccfba15586fb165078fb62", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-unstable", - "type": "indirect" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "home-manager": "home-manager", - "nixpkgs": "nixpkgs_2" - } - }, - "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", - "version": 7 -} diff --git a/devel/flake.nix b/devel/flake.nix deleted file mode 100644 index 0c517a4..0000000 --- a/devel/flake.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ - description = "My development flake"; - inputs = { - nixpkgs.url = "nixpkgs/nixos-unstable"; - home-manager.url = "github:nix-community/home-manager"; - flake-utils.url = "github:numtide/flake-utils"; - }; - - outputs = { - self, # instance of self - nixpkgs, # nixpkgs flake - flake-utils, - home-manager, - ... - }: flake-utils.lib.eachDefaultSystem (system: - let pkgs = nixpkgs.legacyPackages.${system}; in { - devShells.default = import ./shell.nix { - inherit pkgs; - inherit home-manager; - }; - } - ); -} diff --git a/devel/shell.nix b/devel/shell.nix deleted file mode 100644 index 0990c0b..0000000 --- a/devel/shell.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ pkgs? import {}, home-manager, ...}: -with pkgs; -mkShell { - programs.neovim = { - enable = true; - defaultEditor = true; - }; - programs.git = { - enable = true; - }; - programs.zsh = { - enable = true; - shellAliases = { - # list lists - ll = "ls -l"; - update = "sudo nixos-rebuild switch"; - }; - history = { - size = 10000; - path = "${home-manager.cfg.dataHome}/zsh/history"; - }; - }; -} diff --git a/nix/sources.json b/nix/sources.json deleted file mode 100644 index 5c20860..0000000 --- a/nix/sources.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "nixpkgs": { - "branch": "release-21.05", - "description": "Nix Packages collection", - "homepage": "", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "5f244caea76105b63d826911b2a1563d33ff1cdc", - "sha256": "1xlgynfw9svy7nvh9nkxsxdzncv9hg99gbvbwv3gmrhmzc3sar75", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/5f244caea76105b63d826911b2a1563d33ff1cdc.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/nix/sources.nix b/nix/sources.nix deleted file mode 100644 index 9a01c8a..0000000 --- a/nix/sources.nix +++ /dev/null @@ -1,194 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - if spec ? ref then spec.ref else - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; - submodules = if spec ? submodules then spec.submodules else false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules == true - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - {} - else {}; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } From e57154bde3a45448937494ce348fa9a3fbaed2d8 Mon Sep 17 00:00:00 2001 From: pegasust Date: Sun, 6 Nov 2022 20:23:10 +0000 Subject: [PATCH 6/7] config home-manager --- devel-nix/flake.lock | 80 +++++++++++++++++++ devel-nix/flake.nix | 25 ++++++ devel-nix/home.nix | 49 ++++++++++++ hm-base/flake.lock | 80 +++++++++++++++++++ hm-base/flake.nix | 21 +++++ hm-base/home.nix | 53 ++++++++++++ {system => system-nix}/configuration.nix | 4 +- system-nix/flake.lock | 63 +++++++++++++++ system-nix/flake.nix | 22 +++++ .../hardware-configuration.nix | 0 {system => system-nix}/nixos-wsl/.envrc | 0 .../.github/ISSUE_TEMPLATE/bug_report.md | 0 .../.github/ISSUE_TEMPLATE/feature_request.md | 0 .../nixos-wsl/.github/release-drafter.yml | 0 .../nixos-wsl/.github/workflows/main.yml | 0 .../.github/workflows/release-drafter.yml | 0 .../.github/workflows/update-flakes.yml | 0 {system => system-nix}/nixos-wsl/.gitignore | 0 {system => system-nix}/nixos-wsl/LICENSE | 0 {system => system-nix}/nixos-wsl/README.md | 0 {system => system-nix}/nixos-wsl/default.nix | 0 {system => system-nix}/nixos-wsl/flake.lock | 0 {system => system-nix}/nixos-wsl/flake.nix | 0 .../nixos-wsl/modules/build-tarball.nix | 0 .../nixos-wsl/modules/docker-desktop.nix | 0 .../nixos-wsl/modules/docker-native.nix | 0 .../nixos-wsl/modules/installer.nix | 0 .../nixos-wsl/modules/interop.nix | 0 .../nixos-wsl/modules/wsl-distro.nix | 0 .../nixos-wsl/syschdemd.nix | 0 {system => system-nix}/nixos-wsl/syschdemd.sh | 0 system/flake.lock | 26 ------ system/flake.nix | 14 ---- 33 files changed, 395 insertions(+), 42 deletions(-) create mode 100644 devel-nix/flake.lock create mode 100644 devel-nix/flake.nix create mode 100644 devel-nix/home.nix create mode 100644 hm-base/flake.lock create mode 100644 hm-base/flake.nix create mode 100644 hm-base/home.nix rename {system => system-nix}/configuration.nix (94%) create mode 100644 system-nix/flake.lock create mode 100644 system-nix/flake.nix rename {system => system-nix}/hardware-configuration.nix (100%) rename {system => system-nix}/nixos-wsl/.envrc (100%) rename {system => system-nix}/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md (100%) rename {system => system-nix}/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md (100%) rename {system => system-nix}/nixos-wsl/.github/release-drafter.yml (100%) rename {system => system-nix}/nixos-wsl/.github/workflows/main.yml (100%) rename {system => system-nix}/nixos-wsl/.github/workflows/release-drafter.yml (100%) rename {system => system-nix}/nixos-wsl/.github/workflows/update-flakes.yml (100%) rename {system => system-nix}/nixos-wsl/.gitignore (100%) rename {system => system-nix}/nixos-wsl/LICENSE (100%) rename {system => system-nix}/nixos-wsl/README.md (100%) rename {system => system-nix}/nixos-wsl/default.nix (100%) rename {system => system-nix}/nixos-wsl/flake.lock (100%) rename {system => system-nix}/nixos-wsl/flake.nix (100%) rename {system => system-nix}/nixos-wsl/modules/build-tarball.nix (100%) rename {system => system-nix}/nixos-wsl/modules/docker-desktop.nix (100%) rename {system => system-nix}/nixos-wsl/modules/docker-native.nix (100%) rename {system => system-nix}/nixos-wsl/modules/installer.nix (100%) rename {system => system-nix}/nixos-wsl/modules/interop.nix (100%) rename {system => system-nix}/nixos-wsl/modules/wsl-distro.nix (100%) rename {system => system-nix}/nixos-wsl/syschdemd.nix (100%) rename {system => system-nix}/nixos-wsl/syschdemd.sh (100%) delete mode 100644 system/flake.lock delete mode 100644 system/flake.nix diff --git a/devel-nix/flake.lock b/devel-nix/flake.lock new file mode 100644 index 0000000..bdcb8f8 --- /dev/null +++ b/devel-nix/flake.lock @@ -0,0 +1,80 @@ +{ + "nodes": { + "flake-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" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "utils": "utils" + }, + "locked": { + "lastModified": 1667708081, + "narHash": "sha256-FChEy05x4ed/pttjfTeKxjPCnHknMYrUtDyBiYbreT4=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "1ef0da321217c6c19b7a30509631c080a19321e5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1667629849, + "narHash": "sha256-P+v+nDOFWicM4wziFK9S/ajF2lc0N2Rg9p6Y35uMoZI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "3bacde6273b09a21a8ccfba15586fb165078fb62", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "home-manager": "home-manager", + "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", + "version": 7 +} diff --git a/devel-nix/flake.nix b/devel-nix/flake.nix new file mode 100644 index 0000000..f0a9848 --- /dev/null +++ b/devel-nix/flake.nix @@ -0,0 +1,25 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = inputs @ { self, flake-utils, nixpkgs, home-manager, ... }: + let + nixpkgsOfSys = system: import nixpkgs { inherit system; }; + in flake-utils.lib.eachDefaultSystem (sys: + { + homeConfigurations.nixos = home-manager.lib.homeManagerConfiguration { + system = sys; + # configuration = import ./home.nix; + modules = [./home.nix]; + pkgs = nixpkgs.legacyPackages.${sys}; + }; + + } + ); +} diff --git a/devel-nix/home.nix b/devel-nix/home.nix new file mode 100644 index 0000000..32a1e68 --- /dev/null +++ b/devel-nix/home.nix @@ -0,0 +1,49 @@ +# Helpful website to search for configurations: +# https://mipmip.github.io/home-manager-option-search/ +{ config, pkgs,... }: +{ + home.username = "nixos"; + home.homeDirectory = "/home/nixos"; + home.stateVersion = "22.05"; + home.packages = [pkgs.htop pkgs.wget pkgs.ripgrep]; + + # allow unfree stuffs to be installed + nixpkgs.config.allowUnfree = true; + + # define paths + xdg.enable = true; + programs.home-manager.enable = true; + programs.fzf.enable = true; + programs.neovim = { + enable = true; + viAlias = true; + vimAlias = true; + # I use vim-plug, so I probably don't require packaging + extraConfig = builtins.readFile ../neovim/init.lua; + }; + programs.zsh = { + enable = true; + shellAliases = { + ll = "ls -l"; + nix-rebuild = "sudo nixos-rebuild switch"; + }; + history = { + size = 10000; + path = "${config.xdg.dataHome}/zsh/history"; + }; + }; + programs.git = { + enable = true; + lfs.enable = true; + aliases = { + a="add"; c="commit"; ca="commit --ammend"; cm="commit-m"; + lol="log --graph --decorate --pretty=oneline --abbrev-commit"; + lola="log --grpah --decorate --pretty-oneline --abbrev-commit --all"; + }; + extraConfig = { + merge = {tool="vimdiff"; conflictstyle="diff3";}; + }; + # Why is this no longer valid? + # pull = { rebase=true; }; + }; +} diff --git a/hm-base/flake.lock b/hm-base/flake.lock new file mode 100644 index 0000000..bdcb8f8 --- /dev/null +++ b/hm-base/flake.lock @@ -0,0 +1,80 @@ +{ + "nodes": { + "flake-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" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "utils": "utils" + }, + "locked": { + "lastModified": 1667708081, + "narHash": "sha256-FChEy05x4ed/pttjfTeKxjPCnHknMYrUtDyBiYbreT4=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "1ef0da321217c6c19b7a30509631c080a19321e5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1667629849, + "narHash": "sha256-P+v+nDOFWicM4wziFK9S/ajF2lc0N2Rg9p6Y35uMoZI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "3bacde6273b09a21a8ccfba15586fb165078fb62", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "home-manager": "home-manager", + "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", + "version": 7 +} diff --git a/hm-base/flake.nix b/hm-base/flake.nix new file mode 100644 index 0000000..f2fea67 --- /dev/null +++ b/hm-base/flake.nix @@ -0,0 +1,21 @@ +{ + description = "simple home-manager config"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = {nixpkgs, home-manager, ...}: + let system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + homeConfigurations.nixos = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + modules = [./home.nix]; + }; + }; +} diff --git a/hm-base/home.nix b/hm-base/home.nix new file mode 100644 index 0000000..225b51a --- /dev/null +++ b/hm-base/home.nix @@ -0,0 +1,53 @@ +{ config, pkgs,... }: +{ + home.username = "nixos"; + home.homeDirectory = "/home/nixos"; + + home.packages = [pkgs.htop pkgs.ripgrep]; + home.stateVersion = "22.05"; + nixpkgs.config.allowUnfree = true; + + programs.home-manager.enable = true; + programs.fzf.enable = true; + programs.neovim = { + enable = true; + viAlias = true; + vimAlias = true; + # I use vim-plug, so I probably don't require packaging + # extraConfig actually writes to init-home-manager.vim (not lua) + # https://github.com/nix-community/home-manager/pull/3287 + # extraConfig = builtins.readFile ../neovim/init.lua; + }; + xdg.configFile."nvim/init.lua".text = builtins.readFile ../neovim/init.lua; + programs.zsh = { + enable = true; + enableCompletion = true; + enableAutosuggestions = true; + shellAliases = { + ll = "ls -l"; + nix-rebuild = "sudo nixos-rebuild switch"; + }; + history = { + size = 10000; + path = "${config.xdg.dataHome}/zsh/history"; + }; + oh-my-zsh = { + enable = true; + plugins = [ "git" "sudo" "command-not-found" "gitignore" "ripgrep" "rust" ]; + }; + }; + programs.git = { + enable = true; + lfs.enable = true; + aliases = { + a="add"; c="commit"; ca="commit --ammend"; cm="commit-m"; + lol="log --graph --decorate --pretty=oneline --abbrev-commit"; + lola="log --grpah --decorate --pretty-oneline --abbrev-commit --all"; + }; + extraConfig = { + merge = {tool="vimdiff"; conflictstyle="diff3";}; + }; + # why is this no longer valid? + # pull = { rebase=true; }; + }; +} diff --git a/system/configuration.nix b/system-nix/configuration.nix similarity index 94% rename from system/configuration.nix rename to system-nix/configuration.nix index 891e552..20bf068 100755 --- a/system/configuration.nix +++ b/system-nix/configuration.nix @@ -27,7 +27,7 @@ in }; # users.users..uid = 1000; - networking.hostName = "nixos"; + # networking.hostName = "nixos"; # Enable nix flakes nix.package = pkgs.nixFlakes; @@ -35,7 +35,7 @@ in experimental-features = nix-command flakes ''; - # Home manager + # Some basic programs programs.neovim = { enable = true; defaultEditor = true; diff --git a/system-nix/flake.lock b/system-nix/flake.lock new file mode 100644 index 0000000..c1dbbbb --- /dev/null +++ b/system-nix/flake.lock @@ -0,0 +1,63 @@ +{ + "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "utils": "utils" + }, + "locked": { + "lastModified": 1667708081, + "narHash": "sha256-FChEy05x4ed/pttjfTeKxjPCnHknMYrUtDyBiYbreT4=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "1ef0da321217c6c19b7a30509631c080a19321e5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1661328374, + "narHash": "sha256-GGMupfk/lGzPBQ/dRrcQEhiFZ0F5KPg0j5Q4Fb5coxc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f034b5693a26625f56068af983ed7727a60b5f8b", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "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", + "version": 7 +} diff --git a/system-nix/flake.nix b/system-nix/flake.nix new file mode 100644 index 0000000..c0303ec --- /dev/null +++ b/system-nix/flake.nix @@ -0,0 +1,22 @@ +{ + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, ... }: { + nixosConfigurations.Felia = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + ]; + }; + nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + ]; + }; + }; +} diff --git a/system/hardware-configuration.nix b/system-nix/hardware-configuration.nix similarity index 100% rename from system/hardware-configuration.nix rename to system-nix/hardware-configuration.nix diff --git a/system/nixos-wsl/.envrc b/system-nix/nixos-wsl/.envrc similarity index 100% rename from system/nixos-wsl/.envrc rename to system-nix/nixos-wsl/.envrc diff --git a/system/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md b/system-nix/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md similarity index 100% rename from system/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md rename to system-nix/nixos-wsl/.github/ISSUE_TEMPLATE/bug_report.md diff --git a/system/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md b/system-nix/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md similarity index 100% rename from system/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md rename to system-nix/nixos-wsl/.github/ISSUE_TEMPLATE/feature_request.md diff --git a/system/nixos-wsl/.github/release-drafter.yml b/system-nix/nixos-wsl/.github/release-drafter.yml similarity index 100% rename from system/nixos-wsl/.github/release-drafter.yml rename to system-nix/nixos-wsl/.github/release-drafter.yml diff --git a/system/nixos-wsl/.github/workflows/main.yml b/system-nix/nixos-wsl/.github/workflows/main.yml similarity index 100% rename from system/nixos-wsl/.github/workflows/main.yml rename to system-nix/nixos-wsl/.github/workflows/main.yml diff --git a/system/nixos-wsl/.github/workflows/release-drafter.yml b/system-nix/nixos-wsl/.github/workflows/release-drafter.yml similarity index 100% rename from system/nixos-wsl/.github/workflows/release-drafter.yml rename to system-nix/nixos-wsl/.github/workflows/release-drafter.yml diff --git a/system/nixos-wsl/.github/workflows/update-flakes.yml b/system-nix/nixos-wsl/.github/workflows/update-flakes.yml similarity index 100% rename from system/nixos-wsl/.github/workflows/update-flakes.yml rename to system-nix/nixos-wsl/.github/workflows/update-flakes.yml diff --git a/system/nixos-wsl/.gitignore b/system-nix/nixos-wsl/.gitignore similarity index 100% rename from system/nixos-wsl/.gitignore rename to system-nix/nixos-wsl/.gitignore diff --git a/system/nixos-wsl/LICENSE b/system-nix/nixos-wsl/LICENSE similarity index 100% rename from system/nixos-wsl/LICENSE rename to system-nix/nixos-wsl/LICENSE diff --git a/system/nixos-wsl/README.md b/system-nix/nixos-wsl/README.md similarity index 100% rename from system/nixos-wsl/README.md rename to system-nix/nixos-wsl/README.md diff --git a/system/nixos-wsl/default.nix b/system-nix/nixos-wsl/default.nix similarity index 100% rename from system/nixos-wsl/default.nix rename to system-nix/nixos-wsl/default.nix diff --git a/system/nixos-wsl/flake.lock b/system-nix/nixos-wsl/flake.lock similarity index 100% rename from system/nixos-wsl/flake.lock rename to system-nix/nixos-wsl/flake.lock diff --git a/system/nixos-wsl/flake.nix b/system-nix/nixos-wsl/flake.nix similarity index 100% rename from system/nixos-wsl/flake.nix rename to system-nix/nixos-wsl/flake.nix diff --git a/system/nixos-wsl/modules/build-tarball.nix b/system-nix/nixos-wsl/modules/build-tarball.nix similarity index 100% rename from system/nixos-wsl/modules/build-tarball.nix rename to system-nix/nixos-wsl/modules/build-tarball.nix diff --git a/system/nixos-wsl/modules/docker-desktop.nix b/system-nix/nixos-wsl/modules/docker-desktop.nix similarity index 100% rename from system/nixos-wsl/modules/docker-desktop.nix rename to system-nix/nixos-wsl/modules/docker-desktop.nix diff --git a/system/nixos-wsl/modules/docker-native.nix b/system-nix/nixos-wsl/modules/docker-native.nix similarity index 100% rename from system/nixos-wsl/modules/docker-native.nix rename to system-nix/nixos-wsl/modules/docker-native.nix diff --git a/system/nixos-wsl/modules/installer.nix b/system-nix/nixos-wsl/modules/installer.nix similarity index 100% rename from system/nixos-wsl/modules/installer.nix rename to system-nix/nixos-wsl/modules/installer.nix diff --git a/system/nixos-wsl/modules/interop.nix b/system-nix/nixos-wsl/modules/interop.nix similarity index 100% rename from system/nixos-wsl/modules/interop.nix rename to system-nix/nixos-wsl/modules/interop.nix diff --git a/system/nixos-wsl/modules/wsl-distro.nix b/system-nix/nixos-wsl/modules/wsl-distro.nix similarity index 100% rename from system/nixos-wsl/modules/wsl-distro.nix rename to system-nix/nixos-wsl/modules/wsl-distro.nix diff --git a/system/nixos-wsl/syschdemd.nix b/system-nix/nixos-wsl/syschdemd.nix similarity index 100% rename from system/nixos-wsl/syschdemd.nix rename to system-nix/nixos-wsl/syschdemd.nix diff --git a/system/nixos-wsl/syschdemd.sh b/system-nix/nixos-wsl/syschdemd.sh similarity index 100% rename from system/nixos-wsl/syschdemd.sh rename to system-nix/nixos-wsl/syschdemd.sh diff --git a/system/flake.lock b/system/flake.lock deleted file mode 100644 index 9b5c68b..0000000 --- a/system/flake.lock +++ /dev/null @@ -1,26 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1661328374, - "narHash": "sha256-GGMupfk/lGzPBQ/dRrcQEhiFZ0F5KPg0j5Q4Fb5coxc=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "f034b5693a26625f56068af983ed7727a60b5f8b", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-unstable", - "type": "indirect" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/system/flake.nix b/system/flake.nix deleted file mode 100644 index 83907ed..0000000 --- a/system/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - inputs = { - nixpkgs.url = "nixpkgs/nixos-unstable"; - }; - - outputs = { self, nixpkgs, ... }: { - nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ./configuration.nix - ]; - }; - }; -} From 55eb996c42582b2fbb5cdd8b857f931cb0423686 Mon Sep 17 00:00:00 2001 From: pegasust Date: Sun, 6 Nov 2022 22:22:09 +0000 Subject: [PATCH 7/7] feats: more programs to come with zsh --- devel-nix/flake.nix | 25 --------- devel-nix/home.nix | 49 ---------------- hm-base/flake.lock | 80 --------------------------- {devel-nix => home-nix}/flake.lock | 0 {hm-base => home-nix}/flake.nix | 2 +- {hm-base => home-nix}/home.nix | 33 +++++++++-- neovim/init.lua | 2 +- starship/starship.toml | 89 ++++++++++++++++++++++++++++++ 8 files changed, 119 insertions(+), 161 deletions(-) delete mode 100644 devel-nix/flake.nix delete mode 100644 devel-nix/home.nix delete mode 100644 hm-base/flake.lock rename {devel-nix => home-nix}/flake.lock (100%) rename {hm-base => home-nix}/flake.nix (94%) rename {hm-base => home-nix}/home.nix (65%) create mode 100644 starship/starship.toml diff --git a/devel-nix/flake.nix b/devel-nix/flake.nix deleted file mode 100644 index f0a9848..0000000 --- a/devel-nix/flake.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ - description = "A very basic flake"; - - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - home-manager.url = "github:nix-community/home-manager"; - home-manager.inputs.nixpkgs.follows = "nixpkgs"; - flake-utils.url = "github:numtide/flake-utils"; - }; - - outputs = inputs @ { self, flake-utils, nixpkgs, home-manager, ... }: - let - nixpkgsOfSys = system: import nixpkgs { inherit system; }; - in flake-utils.lib.eachDefaultSystem (sys: - { - homeConfigurations.nixos = home-manager.lib.homeManagerConfiguration { - system = sys; - # configuration = import ./home.nix; - modules = [./home.nix]; - pkgs = nixpkgs.legacyPackages.${sys}; - }; - - } - ); -} diff --git a/devel-nix/home.nix b/devel-nix/home.nix deleted file mode 100644 index 32a1e68..0000000 --- a/devel-nix/home.nix +++ /dev/null @@ -1,49 +0,0 @@ -# Helpful website to search for configurations: -# https://mipmip.github.io/home-manager-option-search/ -{ config, pkgs,... }: -{ - home.username = "nixos"; - home.homeDirectory = "/home/nixos"; - home.stateVersion = "22.05"; - home.packages = [pkgs.htop pkgs.wget pkgs.ripgrep]; - - # allow unfree stuffs to be installed - nixpkgs.config.allowUnfree = true; - - # define paths - xdg.enable = true; - programs.home-manager.enable = true; - programs.fzf.enable = true; - programs.neovim = { - enable = true; - viAlias = true; - vimAlias = true; - # I use vim-plug, so I probably don't require packaging - extraConfig = builtins.readFile ../neovim/init.lua; - }; - programs.zsh = { - enable = true; - shellAliases = { - ll = "ls -l"; - nix-rebuild = "sudo nixos-rebuild switch"; - }; - history = { - size = 10000; - path = "${config.xdg.dataHome}/zsh/history"; - }; - }; - programs.git = { - enable = true; - lfs.enable = true; - aliases = { - a="add"; c="commit"; ca="commit --ammend"; cm="commit-m"; - lol="log --graph --decorate --pretty=oneline --abbrev-commit"; - lola="log --grpah --decorate --pretty-oneline --abbrev-commit --all"; - }; - extraConfig = { - merge = {tool="vimdiff"; conflictstyle="diff3";}; - }; - # Why is this no longer valid? - # pull = { rebase=true; }; - }; -} diff --git a/hm-base/flake.lock b/hm-base/flake.lock deleted file mode 100644 index bdcb8f8..0000000 --- a/hm-base/flake.lock +++ /dev/null @@ -1,80 +0,0 @@ -{ - "nodes": { - "flake-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" - } - }, - "home-manager": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "utils": "utils" - }, - "locked": { - "lastModified": 1667708081, - "narHash": "sha256-FChEy05x4ed/pttjfTeKxjPCnHknMYrUtDyBiYbreT4=", - "owner": "nix-community", - "repo": "home-manager", - "rev": "1ef0da321217c6c19b7a30509631c080a19321e5", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "home-manager", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1667629849, - "narHash": "sha256-P+v+nDOFWicM4wziFK9S/ajF2lc0N2Rg9p6Y35uMoZI=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "3bacde6273b09a21a8ccfba15586fb165078fb62", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "home-manager": "home-manager", - "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", - "version": 7 -} diff --git a/devel-nix/flake.lock b/home-nix/flake.lock similarity index 100% rename from devel-nix/flake.lock rename to home-nix/flake.lock diff --git a/hm-base/flake.nix b/home-nix/flake.nix similarity index 94% rename from hm-base/flake.nix rename to home-nix/flake.nix index f2fea67..463d035 100644 --- a/hm-base/flake.nix +++ b/home-nix/flake.nix @@ -15,7 +15,7 @@ in { homeConfigurations.nixos = home-manager.lib.homeManagerConfiguration { inherit pkgs; - modules = [./home.nix]; + modules = [./home.nix]; }; }; } diff --git a/hm-base/home.nix b/home-nix/home.nix similarity index 65% rename from hm-base/home.nix rename to home-nix/home.nix index 225b51a..b9e74ce 100644 --- a/hm-base/home.nix +++ b/home-nix/home.nix @@ -3,10 +3,34 @@ home.username = "nixos"; home.homeDirectory = "/home/nixos"; - home.packages = [pkgs.htop pkgs.ripgrep]; + home.packages = [ + pkgs.htop pkgs.ripgrep pkgs.gcc pkgs.fd pkgs.zk + ]; home.stateVersion = "22.05"; nixpkgs.config.allowUnfree = true; + ## Configs ## + xdg.configFile."nvim/init.lua".text = builtins.readFile ../neovim/init.lua; + xdg.configFile."starship.toml".text = builtins.readFile ../starship/starship.toml; + + ## Programs ## + programs.zoxide = { + enable = true; + enableZshIntegration = true; + }; + programs.tmux = { + enable = true; + shell = "zsh"; + extraConfig = builtins.readFile ../tmux/.tmux.conf; + }; + programs.exa = { + enable = true; + enableAliases = true; + }; + programs.starship = { + enable = true; + enableZshIntegration = true; + }; programs.home-manager.enable = true; programs.fzf.enable = true; programs.neovim = { @@ -18,14 +42,13 @@ # https://github.com/nix-community/home-manager/pull/3287 # extraConfig = builtins.readFile ../neovim/init.lua; }; - xdg.configFile."nvim/init.lua".text = builtins.readFile ../neovim/init.lua; programs.zsh = { enable = true; enableCompletion = true; enableAutosuggestions = true; shellAliases = { - ll = "ls -l"; nix-rebuild = "sudo nixos-rebuild switch"; + hm-switch = "home-manager switch --flake"; }; history = { size = 10000; @@ -40,9 +63,9 @@ enable = true; lfs.enable = true; aliases = { - a="add"; c="commit"; ca="commit --ammend"; cm="commit-m"; + a="add"; c="commit"; ca="commit --ammend"; cm="commit -m"; lol="log --graph --decorate --pretty=oneline --abbrev-commit"; - lola="log --grpah --decorate --pretty-oneline --abbrev-commit --all"; + lola="log --graph --decorate --pretty=oneline --abbrev-commit --all"; }; extraConfig = { merge = {tool="vimdiff"; conflictstyle="diff3";}; diff --git a/neovim/init.lua b/neovim/init.lua index e6aa1b9..baa2d7a 100644 --- a/neovim/init.lua +++ b/neovim/init.lua @@ -281,7 +281,7 @@ require('nvim-treesitter.configs').setup { ensure_installed = { 'tsx', 'toml', 'lua', 'typescript', 'rust', 'go', 'yaml', 'json', 'php', 'css', 'python', 'prisma', 'html', "dockerfile", "c", "cpp", "hcl", "svelte", "astro", - "clojure", "fennel", "bash" + "clojure", "fennel", "bash", "nix" }, sync_install = false, highlight = { enable = true }, diff --git a/starship/starship.toml b/starship/starship.toml new file mode 100644 index 0000000..15a352a --- /dev/null +++ b/starship/starship.toml @@ -0,0 +1,89 @@ +# ~/.config/starship.toml + +[aws] +symbol = " " + +[conda] +symbol = "ο„Œ " + +[dart] +symbol = " " +format = "via [$symbol]($style)" + +[directory] +read_only = " ο ½" +truncation_length = 1 + +[docker_context] +symbol = " " + +[elixir] +symbol = " " +format = 'via [$symbol]($style)' + +[elm] +symbol = " " + +[git_branch] +symbol = " " + +[golang] +symbol = " " +format = 'via [$symbol]($style)' + +[hg_branch] +symbol = " " + +[java] +symbol = "ξ‰– " +format = 'via [$symbol]($style)' + +[julia] +symbol = " " + +[memory_usage] +symbol = " " + +[nim] +symbol = " " + +[nix_shell] +symbol = "ο‹œ " + +[nodejs] +symbol = " " +format = 'via [$symbol]($style)' + +[package] +symbol = "ο£– " + +[perl] +symbol = " " + +[php] +symbol = " " + +[python] +symbol = "ξ˜† " +format = 'via [$symbol]($style)' + +[ruby] +symbol = " " + +[rust] +format = 'via [$symbol]($style)' + +[scala] +symbol = " " + +[shlvl] +symbol = "ο„  " + +[swift] +symbol = "ο―£ " +format = 'via [$symbol]($style)' + +[git_status] +disabled = true + +